To Update Mass by iLogic Rule Running from Within Drawing

To Update Mass by iLogic Rule Running from Within Drawing

RoyWickrama_RWEI
Advisor Advisor
2,094 Views
5 Replies
Message 1 of 6

To Update Mass by iLogic Rule Running from Within Drawing

RoyWickrama_RWEI
Advisor
Advisor

I am interested in updating mass of the assembly in the drawing document by running a rule from the drawing.

By running this in the drawing, nothing happens.

 

Could someone help me.

Thanks.

 

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
iLogicVb.UpdateWhenDone = True
0 Likes
Accepted solutions (1)
2,095 Views
5 Replies
Replies (5)
Message 2 of 6

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, To use the command you propose I think you should have an access like the following

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oViewModelDoc As Document
 
For Each oSheet As Sheet In oDoc.Sheets
	For Each oView As DrawingView In oSheet.DrawingViews
		oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oViewModelDoc = ThisApplication.Documents.Open(oViewModelDoc.fullfilename, True)
		oViewModelDoc.activate
		ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
		iLogicVb.UpdateWhenDone = True
		oViewModelDoc.Close
	Next
Next

 However, I think there should be another more direct access, if I find something I will tell you below. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 6

Sergio.D.Suárez
Mentor
Mentor

Here are some threads that maybe they can serve you.

 

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

 

https://forums.autodesk.com/t5/inventor-customization/vba-check-if-mass-update-is-required/td-p/7565...


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 4 of 6

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot.

It does well for my needs.

0 Likes
Message 5 of 6

yuriboutique10
Community Visitor
Community Visitor

Can you help me the ilogic related to update mass for many opened drawing in this document? Thanks.

 

0 Likes
Message 6 of 6

nick_panzarino
Enthusiast
Enthusiast

I had a similar problem and used the below rule to resolve it. Set to "Run Before Save" using event triggers.

 

Sub Main()
	' Check that the active document is a drawing  file
	If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
		MessageBox.Show("Please run this rule from a drawing file.", "iLogic")
		Exit Sub
	End If

	' Set a reference to the drawing document.
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.ActiveDocument

	Dim oRefDoc As Inventor.Document
	
	For Each oRefDoc In oDrawDoc.ReferencedDocuments
		'MsgBox(oRefDoc.DisplayName)
		updateMass(oRefDoc)
	Next
	
	oDrawDoc.Update2(True)
End Sub

Function updateMass(oDoc As Inventor.Document)
	If oDoc.DocumentType = kPartDocumentObject Or oDoc.DocumentType = kAssemblyDocumentObject Then
		Dim oMassProps As Inventor.MassProperties
		oMassProps = oDoc.ComponentDefinition.MassProperties
		
		If oMassProps.AvailableAccuracy <> 24579 And oMassProps.AvailableAccuracy <> 24580 Then
	      oMassProps.Accuracy = 24579 'Inventor.AccuracyEnum.kHigh
	      oMassProps.CacheResultsOnCompute = True
	    End If
		
		Dim readMass As Double
		readMass = oMassProps.Mass
	End If
End Function