Ilogic bendcount all sheetmetal part in assembly

Ilogic bendcount all sheetmetal part in assembly

omEVKG8
Observer Observer
731 Views
1 Reply
Message 1 of 2

Ilogic bendcount all sheetmetal part in assembly

omEVKG8
Observer
Observer

is there anyone who can help make a rule that counts all bends on my sheetmetal parts in an assembly writes it into iproperties on every part

0 Likes
732 Views
1 Reply
Reply (1)
Message 2 of 2

ckeveryga
Advocate
Advocate

This will create flat pattern/iProperty for all sheet metal parts in assembly/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("Bends iProperty added to all sheet metal parts.", "iLogic")
End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences) 
	
    Dim oOcc As ComponentOccurrence
	For Each oOcc In Occurrences
		oDocType = oOcc.DefinitionDocumentType
		Select Case oDocType
		Case kAssemblyDocumentObject
			Call TraverseAssembly(oOcc.SubOccurrences)
		Case kPartDocumentObject						
			If oOcc.Definition.Type = 83886592 Then 'standard
				'						
			Else If oOcc.Definition.Type = 150995200 Then 'sheet metal part
				Dim oDoc As PartDocument
				oDoc = oOcc.Definition.Document
				
				Dim bFlat As Boolean
				
				Dim oSMDef As SheetMetalComponentDefinition
				oSMDef = oDoc.ComponentDefinition
				
				'Check for Flat Pattern
				If oSMDef.FlatPattern Is Nothing Then					
					'Create Flat Pattern
					Try
						oSMDef.Unfold()
						oSMDef.FlatPattern.ExitEdit()
						oDoc.Close()
						bFlat = True
					Catch ' Failed to unfold part
						MessageBox.Show("Failed to create Flat Pattern")
						bFlat = False
						Return
					End Try
				Else										
					bFlat = True			
				End If
				If bFlat = True
					Dim bends As FlatBendResults
					bends = oSMDef.FlatPattern.FlatBendResults
					
					'Count bends
					Dim count As Integer = 0					
					For Each Bend In oSMDef.Bends
						count += 1
					Next
					
					Dim oCustomPropSet As PropertySet
					oCustomPropSet = oOcc.Definition.Document.PropertySets("Inventor User Defined Properties")
					
					'Check for/create property
					Try
						intTest = oCustomPropSet.Item("Bends").Value
					Catch ex As Exception
						oCustomPropSet.Add(count, "Bends")
					End Try
				End If
			End If
		End Select
	Next
End Sub
End Class
0 Likes