iAssembly iLogic to overwrite weight

iAssembly iLogic to overwrite weight

fwerth
Contributor Contributor
123 Views
2 Replies
Message 1 of 3

iAssembly iLogic to overwrite weight

fwerth
Contributor
Contributor

Hello everyone,
I am having a problem applying an ilogic rule in an assembly. The assembly contains several iAssembly variants. The tables of the inserted iAssemblies also contain a “Mass” column, which specifies the weight of the respective variant. The ilogic rule is supposed to search for the weight of each variant in the assembly from its table, add them up, and insert them into the physical iProperties.
This should work, but unfortunately it does not recognize the “ActiveTableRow” command to find the column of the inserted variant in its table.
Does anyone have any ideas for improvement?

 

Best Regards 

Fabio

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim totalWeight As Double = 0

For Each oOcc As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
    Try
        Dim occDoc As Document = oOcc.Definition.Document

        If occDoc.DocumentType = kPartDocumentObject Or occDoc.DocumentType = kAssemblyDocumentObject Then
            If occDoc.ComponentDefinition.IsiAssemblyMember Then
                Dim member As iAssemblyMember = occDoc.ComponentDefinition.iAssemblyMember

                ' Die aktuell in der Baugruppe verwendete Variante holen
                Dim row As iAssemblyTableRow = member.ActiveTableRow

                If Not row Is Nothing Then
                  
                    Dim variantWeight As Double = CDbl(row("Masse").Value)
                    totalWeight += variantWeight
                End If
            End If
        End If
    Catch ex As Exception
    End Try
Next


' Physikalische Masse überschreiben
oAsmDoc.ComponentDefinition.MassProperties.Mass = totalWeight

 

 

0 Likes
Accepted solutions (2)
124 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @fwerth.  You can use the ComponentOccurrence.IsiAssemblyMember property directly from the ComponentOccurrence object first.  Then, if that is true, you can dig down into the ComponentOccurrence.Definition , which will be the AssemblyComponentDefinition object, then use its AssemblyComponentDefinition.iAssemblyMember property to get the actual iAssemblyMember object.  Then, use its iAssemblyMember.Row property, instead of the "ActiveTableRow" that you are trying to use in your example.  From the iAssemblyTableRow object that you get from the 'Row' property, you can use its iAssemblyTableRow.Item property to access the iAssemblyTableCell holding the 'Mass' value.  Be aware though, if any of your components are suppressed, then your line of code that attempts to access the ComponentOccurrence.Definition property will throw an error, because it can not access the definition of a suppressed component.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

fwerth
Contributor
Contributor
Accepted solution

Hey @WCrihfield 

Thank you very much! You have solved my problem!
I have now expanded the code so that it also adds up the weights of components that are not iAssemblies.

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim totalWeight As Double = 0

For Each oOcc As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
    Try
        ' Prüfen, ob Occurrence ein iAssembly-Mitglied ist
        If oOcc.IsiAssemblyMember Then
            ' iAssemblyMember holen
            Dim member As iAssemblyMember = oOcc.Definition.iAssemblyMember

            ' Aktuelle Zeile
            Dim row As iAssemblyTableRow = member.Row

            If Not row Is Nothing Then
                ' Zelle "Masse" auslesen
                Dim cell As iAssemblyTableCell = row.Item("Masse")
                Dim variantWeight As Double = CDbl(cell.Value)

                totalWeight += variantWeight
            End If
			 Else
            ' Normales Teil / Baugruppe → Inventor-Masse
            Dim occMass As Double = oOcc.MassProperties.Mass
            totalWeight += occMass
        End If
    Catch ex As Exception
        ' suppressed Occurrences oder fehlende Spalten überspringen
    End Try
Next

' Physikalische Masse überschreiben
Dim massProps As MassProperties
massProps = oAsmDoc.ComponentDefinition.MassProperties

oAsmDoc.ComponentDefinition.MassProperties.Mass = totalWeight

' In iProperties schreiben
iProperties.Value("Custom", "Masse") = totalWeight

MessageBox.Show("Masse = " & totalWeight & " kg", "iLogic Info")
0 Likes