Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Override Mass in batch

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
hugo.trepanier
575 Views, 2 Replies

Override Mass in batch

We currently convert more than 10,000 .sldprt file to .ipt. This is an old library of part from SW. All is done by Autodesk Inventor Task scheduler. But Now we need to manually override the Mass with the custom iproperty. Any tool to do this? Inventor BOM could be an usefull tool but it can't override MASS, we absolutely need to open 10,000 part one by one to doing this :(.  Will the the only way to do this be a macro to run in batch? If a macro is available it could be useful.

 

Thanks

Hugo Trepanier
Autodesk MSD Application Specialist
Labels (3)
2 REPLIES 2
Message 2 of 3
ckeveryga
in reply to: hugo.trepanier

This rule will update the mass for every part in an assembly and subassemblies. 

Class ThisRule

Dim oAsmDoc As Document

Public Sub Main()	
	oAsmDoc = ThisApplication.ActiveDocument
	If oAsmDoc.DocumentType  <> DocumentTypeEnum.kAssemblyDocumentObject Then
		Return
	End If
	Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences)
	
	MessageBox.Show("All weights updated.", "iLogic")
End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences) 
	
    Dim oOcc As ComponentOccurrence
	Dim dblMass As Double
	Dim strMassProp As String
	For Each oOcc In Occurrences
		oDocType = oOcc.DefinitionDocumentType
		Select Case oDocType
		Case kAssemblyDocumentObject
			Call TraverseAssembly(oOcc.SubOccurrences)
		Case kPartDocumentObject
			
			Dim oCustomPropSet As PropertySet
			oCustomPropSet = oOcc.Definition.Document.PropertySets("Inventor User Defined Properties")
			
			'Check for/create property
			Try
				strMassProp = oCustomPropSet.Item("MASSE").Value

				oOcc.MassProperties.Mass = Convert.ToDouble(strMassProp) / 2.20462 'convert to lbs
			Catch ex As Exception
				MessageBox.Show("No MASSE property.", oOcc.Definition.Document.displayname)
			End Try
		End Select
	Next
End Sub
End Class

 Warning: if the MASSE property is not in the part, a message box will show up! (to remove, comment the message box in the catch)

 

Hope this works for you. 

Message 3 of 3
hugo.trepanier
in reply to: ckeveryga

Thanks you so much for your help!!

 

All works fine and simply create a dummy assembly with all my 10,000 files to proceed! 🙂

Hugo Trepanier
Autodesk MSD Application Specialist

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report