Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error Bom.Componentdefinitions

1 REPLY 1
SOLVED
Reply
Message 1 of 2
bradeneuropeArthur
297 Views, 1 Reply

Error Bom.Componentdefinitions

bradeneuropeArthur
Mentor
Mentor

 

Public Sub Main()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    oBOMView = oBOM.BOMViews.Item("Structured")
        
   
    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As Inventor.ComponentDefinition
		Try
			
			oCompDef = oRow.ComponentDefinitions.Item(1)
			
			
			Catch
				MsgBox (oRow.ItemNumber)
			End Try
        

        Dim oPartNumProperty As Inventor.Property
        Dim oDescripProperty As Inventor.Property

        If TypeOf oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

           
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            oPartNumProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

           
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub

 

 

This code from the help gives an error on the line with:

Try
oCompDef = oRow.ComponentDefinitions.Item(1)
Catch
MsgBox (oRow.ItemNumber)

msgbox (oRow.ComponentDefinitions.Count)

gives somtimes "0" for an assembly
End Try

 

Why is that the case

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

Error Bom.Componentdefinitions

 

Public Sub Main()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    oBOMView = oBOM.BOMViews.Item("Structured")
        
   
    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As Inventor.ComponentDefinition
		Try
			
			oCompDef = oRow.ComponentDefinitions.Item(1)
			
			
			Catch
				MsgBox (oRow.ItemNumber)
			End Try
        

        Dim oPartNumProperty As Inventor.Property
        Dim oDescripProperty As Inventor.Property

        If TypeOf oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

           
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            oPartNumProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

           
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub

 

 

This code from the help gives an error on the line with:

Try
oCompDef = oRow.ComponentDefinitions.Item(1)
Catch
MsgBox (oRow.ItemNumber)

msgbox (oRow.ComponentDefinitions.Count)

gives somtimes "0" for an assembly
End Try

 

Why is that the case

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

1 REPLY 1
Message 2 of 2

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Found out why.

Since the implementation of Model States, suppressed components are no longer removed from the Bill Of Material.

They are only indicated with quantity "0".

These return a "oRow.ComponentDefinitions.Count" of "0" ofcourse.

This is very confusing because you don't see this directly during programming.

Still good to learn from this case and maybe it helps others.

 

Regards,

 

Arthur

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Found out why.

Since the implementation of Model States, suppressed components are no longer removed from the Bill Of Material.

They are only indicated with quantity "0".

These return a "oRow.ComponentDefinitions.Count" of "0" ofcourse.

This is very confusing because you don't see this directly during programming.

Still good to learn from this case and maybe it helps others.

 

Regards,

 

Arthur

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report