I need to keep the gross weight.
Despise weight of all suppress parts and references.
Routine should disregard weights of suppressed parts and referencesI
Could someone help?
Iva.btblan
Solved! Go to Solution.
Solved by ivanildo.b. Go to Solution.
Hi @ivanildo.b. Here is something very basic you can try. It gets the 'active' document, makes sure it is an assembly, then loops through all of its 'top level' components. If the component is Suppressed or its BOMStructure is set to Reference, it will skip that component. Those that pass that test, it gets their Mass, then adds that to a total Mass variable. At the end it shows you the result. Keep in mind that the units are in 'database units' (kilogram in this case), not necessarily the mass units you have specified of your document. So you may need to include some math or other units conversion if you need the result in other units.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
oOccs = oADef.Occurrences
Dim oOverallMass As Double = 0.0
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Or
oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
Continue For 'skip to next oOcc in loop
End If
'get its Mass
oOccMass = oOcc.MassProperties.Mass 'is in database units, not document units
oOverallMass = oOverallMass + oOccMass
Next
'get String for database mass units for report
oDbUnits = ThisApplication.UnitsOfMeasure.GetStringFromType(UnitsTypeEnum.kDatabaseMassUnits)
MsgBox("oOverallMass= " & oOverallMass & " " & oDbUnits,,"")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
Actually, after an extra test or 3, I see that a much simpler code will return the same results.
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
Dim oOverallMass As Double = oADef.MassProperties.Mass
MsgBox("oOverallMass= " & oOverallMass,,"")
or even this:
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
Dim oOverallMass As Double = iProperties.Mass
MsgBox("oOverallMass= " & oOverallMass,,"")
But this last one, which gets the value from iProperties, returns the value in document units, instead of database units.
In all three ways of getting the total assembly mass, they always reduced the overall mass anytime I suppressed any component or set any component's BOMStructure to Reference. (I'm using Inventor 2022.1.1, just for reference.)
Wesley Crihfield
(Not an Autodesk Employee)
I thank you attention!
I need the somatoria of the Bruto of each part.
I don't want the value of mass.
Iva.btblan
OK. After reviewing your files, I saw that you had that one component set to 'Enabled = False', instead of Suppressed or BOMStructure set to Reference. That's why my earlier code was still including the weight for that component. Now when I additionally include checking each component for Enabled...if Enabled = False, then skip that component. That fixed the outcome, so it would show the final weight you were looking for.
Sub Main
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
iProperties.Value("Custom", "BRUTO") = 0
Call Recursivo(oDoc.ComponentDefinition.Occurrences)
oDoc.Update
oVal = iProperties.Value("Custom", "BRUTO")
MsgBox("oVal = " & oVal,,"")
End Sub
Sub Recursivo(ByVal Occurrences As ComponentOccurrences)
Dim oTotal As Double = 0.0
For Each occ As ComponentOccurrence In Occurrences
If occ.Suppressed Or _
occ.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Or _
occ.Enabled = False Then
Continue For
End If
If occ.DefinitionDocumentType = kPartDocumentObject Then
Dim oOccPDoc As PartDocument = occ.Definition.Document
Dim oOccBruto As Double = oOccPDoc.PropertySets.Item("Inventor User Defined Properties").Item("BRUTO").Value
oTotal = oTotal + oOccBruto
End If
If occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Recursivo(occ.SubOccurrences)
End If
Next
iProperties.Value("Custom", "BRUTO") += oTotal
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Excellent! It's wonderful!
Thanks for the attention!
Congratulations on your work!
Iva.btblan
Can't find what you're looking for? Ask the community or share your knowledge.