I am looking to incorporate accurate weights for a large CAD Library without having completely accurate designs/models. I have multiple variations of parts in singular iParts. The issue with adding a "user defined mass" to the iPart is that it is applied to all subparts within the iPart, which are not all the same weight in reality. I was thinking I could add a custom iProperty to each part variation within each iPart. The issue is that when it comes to the final drawing/assembly, I would have to manually add up all the weight values. Is there a way (using iLogic or another method) to automatically add up the custom property weights for every part in the assembly? Is there a way to print this value to text within a drawing of this assembly? Please provide any information you can and let me know if this is possible, or if there would be a better alternative to this method. Thank you.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @ober2558. How are you determining the Mass/Weight for those iPart member models? Are you using the MassProperties.Mass property's value, or are you using a different/custom value for their Mass? If you are using a different/custom value for their Mass, then you may have to store that value up into the iPartFactory's table, in the row for that member, instead of in the iPart member model file. Then, for every iPart member component you encounter in the assembly, access its parent iPartFactory, and get the Mass value from that member's column/cell in its table. If you are using the value from MassProperties.Mass, then you should be able to pull that directly from each of the member model's ComponentOccurrence.Definition.MassProperties.Mass, and put that value in a List(Of Double) or something like that, as you loop through the components. Then, once you have added all the Mass values to that List object, you can use its Sum method to get the total Mass.
Wesley Crihfield
(Not an Autodesk Employee)
Each part has been physically weighed and the value for each put into their own cell within the iPartFactory table under a custom iProperty column. I'm looking for a way to determine the total mass of the assembly based on the specific custom weights of each part, without having to add them up manually.
Hi @ober2558. I haven't messed with iParts or iAssemblies in a while, but I think that if the column in your iPartFactory's table for the member's Mass is labeled "Mass", then this code example below may get you closer to what you are after. This example is only looking at top level components, not looking down into sub-assemblies, and is only looking at components that are identified as iPartMembers. I hope this is close to what you were trying to do.
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oMassList As New List(Of Double)
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
If Not oOcc.IsiPartMember Then Continue For
Dim oMember As iPartMember = oOcc.Definition.iPartMember
Dim oMass As Double = CDbl(oMember.Row.Item("Mass").Value)
oMassList.Add(oMass)
Next
Dim oTotaliPartsMass As Double = oMassList.Sum
MsgBox("Total iParts Mass = " & oTotaliPartsMass, vbInformation, "Total iParts Mass")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @ober2558. If that works to get the custom Mass of each iPartMember, but you need it to add up the mass of all components, not just the iPartMembers, and you need it to process all possible levels of the assembly, including down into sub-assemblies, then this expanded code should do that for you.
Class ThisRule
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
oMassList = New List(Of Double)
RecursivelyProcessComponents(oOccs)
Dim oTotaliPartsMass As Double = oMassList.Sum
MsgBox("Total iParts Mass = " & oTotaliPartsMass, vbInformation, "Total iParts Mass")
End Sub
Dim oMassList As List(Of Double) 'shared by both routines
Sub RecursivelyProcessComponents(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
If oComp.Suppressed Then Continue For
If TypeOf oComp.Definition Is VirtualComponentDefinition Then Continue For
If oComp.IsiPartMember Then
Dim oMember As iPartMember = oComp.Definition.iPartMember
oMassList.Add(CDbl(oMember.Row.Item("Mass").Value))
Else
oMassList.Add(oComp.MassProperties.Mass)
End If
If oComp.SubOccurrences.Count > 0 Then
RecursivelyProcessComponents(oComp.SubOccurrences)
End If
Next
End Sub
End Class
Wesley Crihfield
(Not an Autodesk Employee)
When trying to implement this iLogic code I ran into an issue. When the assembly is first created and the code ran, it works as expected, notifying with a text box that "total iPart mass = 0". However, when I actually place an iPart or multiple iParts that have the custom mass property in the iTable, the code returns the error "Error on line 14 in rule: Rule0, in document: BS Assembly.iam Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))". Attempts to troubleshoot the code have not yielded any meaningful results. Do you have any guidance on this issue?
Hi @ober2558. When I look at 'line 14' of the last code I posted above, that is a blank line, so I will need you to tell me what is on line 14 of your rule's code, so that I can understand specifically what code is throwing the error. Since it says 'unspecified error', it may be a bit more difficult to diagnose, but maybe something will come to mind about that specific bit of code, or maybe I know of a different way of doing it.
In next code above the last code I posted, the code on line 14 of that was the following:
Dim oMass As Double = CDbl(oMember.Row.Item("Mass").Value)
If that is the line causing problems, there are a few possibilities of what might be the problem. Where I am specifying "Mass", I am assuming that there is a iPartTableColumn labeled "Mass", and I am also assuming that specifying that column's name there would return the iPartTableCell object at the intersection of that row, and that column, but I could be wrong. The online help page for iPartTableRow.Item property says that the 'Index' variable it is expecting as input is a Variant (same as a generic Object), instead of an Integer, so I am assuming that a String could be used there, which usually indicates that a name can be used as input. But if the 'Mass' column represents a 'custom' iProperty, then the column header would probably contain "Mass [Custom]", instead of just "Mass". Try replacing "Mass" with "Mass [Custom]", and see if that fixes it.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.