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