Checking the parts lists weighted in drawings

Checking the parts lists weighted in drawings

max.baumann07
Enthusiast Enthusiast
463 Views
7 Replies
Message 1 of 8

Checking the parts lists weighted in drawings

max.baumann07
Enthusiast
Enthusiast

Hello,

I am currently working on checking the parts lists on drawings, from time to time it happens that weights are not added, for example if I place a glue as an empty component in an assembly to have it visible on the parts list. The adhesive then has a weight of 0.000. It can happen that this is overlooked.
Does anyone of you have an ilogic or another idea how this is best checked. So that a message may appear: Weight 0 detected, please check.

 

0 Likes
Accepted solutions (1)
464 Views
7 Replies
Replies (7)
Message 2 of 8

earl_cody
Contributor
Contributor

Here is some VBA that will detect if a part contained within an assembly has a mass of 0 (demo files attached). Should work with subassemblies as well. 

 

Screenshot 2024-04-12 175743.png

 

Screenshot 2024-04-12 175730.png

Sub Main()
    'get currently opened/active assembly document
    Dim asmDoc As Inventor.AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    'get assembly definition
    Dim asmDef As Inventor.AssemblyComponentDefinition
    Set asmDef = asmDoc.ComponentDefinition
    
    'collection to store parts that have 0 mass
    Dim collPartsZero As New Collection
    
    'call sub that detects 0 mass of subparts
    Call TraverseOccurrences(occs:=asmDef.Occurrences, coll:=collPartsZero)
    
    'message logic
    Dim message As String
    If collPartsZero.Count > 0 Then
        If collPartsZero.Count = 1 Then
            message = collPartsZero(1) & " has a mass of 0!"
        Else
            message = "The following parts have a mass of 0:" & vbCrLf
            
            For Each p In collPartsZero
                message = message & p & vbCrLf
            Next
        End If
    Else
        message = "All parts have mass!"
    End If
    
    'show message box
    MsgBox (message)

End Sub

Sub TraverseOccurrences(ByRef occs As Inventor.ComponentOccurrences, ByRef coll As Collection)
    Dim partDoc As Inventor.PartDocument
    Dim partDef As Inventor.PartComponentDefinition
    
    Dim co As Inventor.ComponentOccurrence
    For Each co In occs
        Select Case co.DefinitionDocumentType
            'if occurrence is part
            Case Inventor.kPartDocumentObject:
                Set partDef = co.Definition
                Set partDoc = partDef.Document
                
                'if part mass = 0
                If partDef.MassProperties.Mass = 0 Then
                    'add part display name to collection
                    'or change to whatever name property you want to display
                    coll.Add (partDoc.DisplayName)
                End If
            
            'if assembly then recursively call this sub for the suboccurrences
            Case Inventor.kAssemblyDocumentObject:
                Call TraverseOccurrences(occs:=co.SubOccurrences, coll:=coll)
        End Select
    Next
End Sub

 

0 Likes
Message 3 of 8

max.baumann07
Enthusiast
Enthusiast

Thank you very much.

That seems to work well.

Unfortunately I need this in the drawings.
The glue model is used again and again as an example. If a weight is stored here, then it is not correct in the other assemblies. I therefore have to adjust it on the drawings and need a small checker for this.

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @max.baumann07.  What does it look like in that cell of your PartsList when the Mass is zero?  If it is just zeros, then how many zeros?  Is there a leading zero, before the decimal point?  Is there a units specifier, such as "g" or "lbs" included in the cell?  When we access the value of a PartsListCell in a PartsList, it is always a String (even if you are expecting a Boolean, or numerical value).  So, if I obtain a String type value, what to I compare it against?  Will this always be on a 'custom' row?  Or will the component of that row always be a 'virtual' one?  If a String comparison will not work, because the value is not stable enough, then much more code would be needed to dig all the way back into the model from the row, which is a real pain.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor

I am leaving for the day now, but below is a quick example iLogic rule to help you look into this a bit further.  I will try to remember to check back here tomorrow.  It posts feedback to the iLogic Log window in a few places, but uses a MsgBox for the main alert message.  As mentioned in my previous response, if a 'static' String value can not be used for checking this zero mass cell value, then a bunch more code may be needed that will actually dig all the way back to the model being referenced by that row.  I have done that several times before, but it is more of a pain than it seems like it should be, so I do not like to go there if I do not have to.

Sub Main
	'make sure we have a Drawing
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then
		Logger.Debug("The rule named '" & iLogicVb.RuleName & "' exited (no DrawingDocument obtained)!")
		Return
	End If
	'get first PartsList on the active sheet
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.PartsLists.Count = 0 Then
		Logger.Debug("No PartsLists on active sheet.  Exiting routine.")
		Return
	End If
	Dim oPList As PartsList = oSheet.PartsLists.Item(1)
	'find the column for Mass
	Dim oMassCol As PartsListColumn = Nothing
	Dim oCols As PartsListColumns = oPList.PartsListColumns
	For Each oCol As PartsListColumn In oCols
		If oCol.PropertyType = PropertyTypeEnum.kMassPartsListProperty Then
			oMassCol = oCol
			Exit For
		End If
	Next 'oCol
	'it it was not found, report it, then exit routine
	If oMassCol Is Nothing Then
		Logger.Debug("No 'Mass' column found in PartsList!")
		Return
	End If
	Dim oRows As PartsListRows = oPList.PartsListRows
	For Each oRow As PartsListRow In oRows
		If oRow.Visible = False Then Continue For 'skip to next row
		'If oRow.Custom = True Then Continue For 'skip to next row
		'cell Value Data Type is always a String (not Numeric, Boolean, or other)
		'get value from cell in Mass column of this row, as a String value
		Dim sMass As String = oRow.Item(oMassCol).Value
		'Could just try to check its value against a static String, like "0.000" or somethingl
		If sMass = "0.00" OrElse "0" OrElse "0.00 lbs" Then
			Logger.Info("Mass = " & sMass)
			MsgBox("PartsList Row has zero value for Mass.", vbExclamation, "iLogic")
		End If
	Next 'oRow
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 8

max.baumann07
Enthusiast
Enthusiast

Hello,

Thank you very much.

The line would then look like this

maxbaumann07_0-1713244085117.png

The mass will always come from the iProperties and will not be a custom iProp.

 

maxbaumann07_1-1713244206004.png

 

They will also never be virtual components.

 

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

OK @max.baumann07.  I have updated the code to match that information.  It will check the String type value it gets from the cell in the PartsList against "0,000 g", and will also attempt to convert the numerical portion of it to a Double data type, then compare that value against zero.  If any cell is matches those tests, it should show a message on your screen to let you know about it.  However, you will need to run the rule for it to check those things.  You can either run it manually, or maybe use the 'Event Triggers' dialog and put it under an event in the 'This Document' tab (only effect this one drawing), or put this rule under an event in the 'Drawings' tab (to have it effect all drawings).

Sub Main
	'<<< make sure we have a Drawing >>>
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then
		Logger.Debug("The rule named '" & iLogicVb.RuleName & "' exited (no DrawingDocument obtained)!")
		'MsgBox("The rule named '" & iLogicVb.RuleName & "' exited (no DrawingDocument obtained)!", vbCritical, "iLogic")
		Return
	End If
	'<<< get first PartsList on the active sheet >>>
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.PartsLists.Count = 0 Then
		Logger.Debug("No PartsLists on active sheet.  Exiting routine.")
		'MsgBox("No PartsLists on active sheet.  Exiting routine.", vbExclamation, "iLogic")
		Return
	End If
	Dim oPList As PartsList = oSheet.PartsLists.Item(1)
	'<<< find the column for Mass >>>
	Dim oMassCol As PartsListColumn = Nothing
	Dim oCols As PartsListColumns = oPList.PartsListColumns
	For Each oCol As PartsListColumn In oCols
		If oCol.PropertyType = PropertyTypeEnum.kMassPartsListProperty Then
			oMassCol = oCol
			Exit For
		End If
	Next 'oCol
	'<<< it it was not found, report it, then exit routine >>>
	If oMassCol Is Nothing Then
		Logger.Debug("No 'Mass' column found in PartsList!")
		'MsgBox("No 'Mass' column found in PartsList!", vbExclamation, "iLogic")
		Return
	End If
	'<<< iterate through rows and check for zero Mass value >>>
	Dim oRows As PartsListRows = oPList.PartsListRows
	For Each oRow As PartsListRow In oRows
		If oRow.Visible = False Then Continue For 'skip to next row
		If oRow.Custom = True Then Continue For 'skip to next row
		'cell Value Data Type is always a String (not Numeric, Boolean, or other)
		'get value from cell in Mass column of this row, as a String value
		Dim sMass As String = oRow.Item(oMassCol).Value
		If sMass = "0,000 g" OrElse _
			Conversion.Val(sMass) = 0 Then
			MsgBox("A PartsList Row has zero Mass!", vbExclamation, "iLogic")
		End If
	Next 'oRow
End Sub

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

EESignature

(Not an Autodesk Employee)

Message 8 of 8

max.baumann07
Enthusiast
Enthusiast
Many thanks for your help and the code. Exactly what I was looking for.
0 Likes