VBA - Check if Mass update is required.

VBA - Check if Mass update is required.

danmachen
Advocate Advocate
3,426 Views
11 Replies
Message 1 of 12

VBA - Check if Mass update is required.

danmachen
Advocate
Advocate

Hi guys,

 

I've written a small VBA script to check if an update or mass properties need to be updated in the model for a part or an assembly.

 

However, I can't seem to find anything in the API for checking if the mass update needs to be run. I have already tried returning the value of the mass, which does work but the mass remains as "N/A".

 

Any help appreciated. Existing code below.

 

 

Private Sub CheckUpdatesRequired()

'set the active document
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

'If an update is required send this message to the userform
If oDoc.RequiresUpdate = True Then
TextBox1.Value = TextBox1.Value & "An update is required" & vbNewLine
End If

'insert code here to inform if the "Update Mass" button needs to be pressed

End Sub
Dan Machen
Autodesk Inventor 2019 Certified Professional
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Ideas that need support:
Circular / Rectangular Point Matrix
Allow Axis & Plane Selection on Rectangular / Circular pattern
Graphical iLogic Programming
0 Likes
Accepted solutions (1)
3,427 Views
11 Replies
Replies (11)
Message 2 of 12

dgreatice
Collaborator
Collaborator

Hi,

 

Better you use Application Option setting for update the mass. It will update after save command.

This is related Topic, already solve that problem.

 

https://forums.autodesk.com/t5/inventor-customization/assemby-mass-update/m-p/5519134/highlight/true...

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 12

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

I suggest not to use the application option to update the mass of the files, regarding the dirty maker issue.

Inventor will always try to update the property mass but will not always successful with this option on. this means if files are released in Vault, this may lead into errors, because inventor wants to update/try to update the value the next time. because the file is read-only it will not succeed and inventor removes the readonly flag. Means dirty in your design. But the file is released and the design cannot be checked in anymore, when used in another assembly or drawing.

 

See the issue here from autodesk:

Re: Stop telling me I need to save something I haven't changed

 

To check the two values I use the following:

 

Public Sub mass()
Dim a As Document
Set a = ThisDocument

Dim StrMass1 As String
StrMass1 = a.ComponentDefinition.MassProperties.mass

Dim StrMass2 As String
StrMass2 = a.PropertySets.Item("Design Tracking Properties").Item("Mass").Value / 1000

If StrMass1 <> StrMass2 Then
MsgBox StrMass1 & " unequal " & StrMass2 & " And needs Update"
Else
MsgBox StrMass1 & " = " & StrMass2 & " and needs no Update"
End If

End Sub

Hope this will help.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 12

danmachen
Advocate
Advocate

 This is great! This is what I needed.

 

It looks like this script does in fact update the mass property.

 

Just so I understand better, what is the difference between the mass definition for ComponentDefinition and for Design Tracking Properties?

 

Thanks again!

Dan Machen
Autodesk Inventor 2019 Certified Professional
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Ideas that need support:
Circular / Rectangular Point Matrix
Allow Axis & Plane Selection on Rectangular / Circular pattern
Graphical iLogic Programming
0 Likes
Message 5 of 12

bradeneuropeArthur
Mentor
Mentor

The Componentdefinition "Mass" needs to be written to design tracking tracking properties "Mass", to be visible.

 

That is why.

 

And that is also why it s going wrong with the application options set to update, if you may understand?

 

If you need further support or explanation please let me know.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 12

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Maybe you are interested in this too.

 

Public Sub propMassUptoDate()

Dim a As Document
Set a = ThisDocument

Dim p As Property
Dim ps As PropertySet

Set ps = a.PropertySets.Item(3)
Set p = ps.Item("Mass")

MsgBox "Mass up to date : " & p.Dirty

End Sub

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 12

dgreatice
Collaborator
Collaborator

Hi all

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 8 of 12

dgreatice
Collaborator
Collaborator

Hi all,

 

I have that issue at my file vault (some file no update the mass), it because user forgot to update, if you already released, you must quick change or get revised.

 

For first setting at application Tools, user may be forgot to update but system help you to update.

 

With showing message about that mass no update, it maybe use for searching file with status for approval, approved or released only. Its job for administrator vault to find that file (necessary job :D), with setting "update after save" before add into vault, this issue maybe no come again.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 9 of 12

bradeneuropeArthur
Mentor
Mentor

Think this runs out of this question!

Dirty files and update them should be in another topic.

For example:

 

https://forums.autodesk.com/t5/inventor-ideas/stop-telling-me-i-need-to-save-something-i-haven-t-cha...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 12

R_Cygan
Participant
Participant

Trying to run that rule, got that message

 

 

RomanCygan_0-1681500015753.png

 

0 Likes
Message 11 of 12

R_Cygan
Participant
Participant

I got that rule, all works well

 

'iLogic rule to update mass of the model
'it runs everytime the document is saved
'no manual form or command require


Sub Main UpdateMass()

 If ActiveSheet.Sheet.DrawingViews.Count=0Then
 Exit Sub
 End If

 Dim oDoc As Document=ThisDrawing.ModelDocument
 Dim oMassStr As String=Round(oDoc.ComponentDefinition.MassProperties.Mass,0)
 InventorVb.DocumentUpdate()
End Sub

but when in the drawings is just 1 presentaion ( .ipn) file, got that massage:

 

RomanCygan_1-1681501034459.png

unless I place .ipt or am on that page first - than no error!

 

Please help

 

Message 12 of 12

WCrihfield
Mentor
Mentor

Hi @R_Cygan.  That iLogic shortcut snippet 'ThisDrawing.ModelDocument' will attempt to find the first view in the active drawing document that is referencing a model document.  Even if you may have multiple model documents being referenced within that drawing, this will just return the 'first' one.  If that referenced document is a presentation, and not a part or assembly, then the only 'Mass' you will be able to access is the iProperty one, and that iProperty may not contain accurate mass data.  All document types will have that iProperty named Mass, because it is a standard one, but usually only the part or assembly type documents might have its value filled in correctly.  The PresentationDocument object does not have a ComponentDefinition or MassProperties, so getting accurate mass data from that document may not be possible.

 

Instead of using that iLogic shortcut snippet, you could use other ways of checking for a model document being referenced by a drawing document using regular Inventor API code.  For instance, you could look within the DrawingDocument.ReferencedDocuments collection to check each referenced document.  Or you could loop through each DrawingView on each Sheet and get the DrawingView.ReferencedDocumentDescriptor.ReferencedDocument to a Document type variable, then if the document type is a part or assembly, try checking its Mass.  It all depends on if your drawing documents contain references to more than one model document or not, and if multiple, which one do you need to get the mass from, or do you need to get it from all of them.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes