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: 

How to get the properties of the opening asm file?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
2208571753
363 Views, 3 Replies

How to get the properties of the opening asm file?

I have a question, i opened the drawing file Clutch_Bell_Simplified.iam. And i can get the bom by the API like this below.

Public Sub BOMQuery()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set 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
    Set 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
    Set oBOMView = oBOM.BOMViews.Item("Structured")
        
    Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description"
    Debug.Print "----------------------------------------------------------------------------------"

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

20220328084000.png

BOM informations include "Part Number,Thumbnail,Bom Structure,Unit QYT,QYT,Stock Number,Description". Then how can get the same informations like BOM from the top parent node:"Clutch_Bell_Simplified.iam"?

Labels (3)
3 REPLIES 3
Message 2 of 4
A.Acheson
in reply to: 2208571753

You would access the iproperties through the document property sets. Api sample here

Some more info here on the property sets. 

Public Sub GetPropertySample()
    ' Get the active document.
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As Property
    Set invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox "Part Number: " & invPartNumberProperty.value
End Sub
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 4
WCrihfield
in reply to: 2208571753

Hi @2208571753.  I'm not 100% sure what you are asking for here, but since your code and image are both focused on the assembly's BOM, I assume you are looking for where all those individual pieces of information you are seeing in the BOM are coming from within the document.  So, I have written out a fairly simple bit of iLogic code to help you get a better understanding about where each of those pieces of information are being found within the document.

AddReference "stdole"
Imports stdole
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oPartNumber = oADoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
oThumbnail = oADoc.Thumbnail 'an image (can't view it directly in a simple message)
Dim oBOMStructure As BOMStructureEnum = oADoc.ComponentDefinition.BOMStructure
Dim oQuantityType As BOMQuantityTypeEnum
oBaseQuantity = oADoc.ComponentDefinition.BOMQuantity.GetEvaluatedBaseQuantity(oQuantityType)
Dim oBaseUnits As String = oADoc.ComponentDefinition.BOMQuantity.BaseUnits
Dim oUnitQuantity As String = oADoc.ComponentDefinition.BOMQuantity.UnitQuantity
Dim oStockNumber As String = oADoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
Dim oDescription As String = oADoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value

MsgBox("oPartNumber = " & oPartNumber & vbCrLf & _
"oBOMStructure = " & oBOMStructure.ToString & vbCrLf & _
"oBaseQuantity = " & oBaseQuantity & vbCrLf & _
"oQuantityType = " & oQuantityType.ToString & vbCrLf & _
"oBaseUnits = " & oBaseUnits & vbCrLf & _
"oUnitQuantity = " & oUnitQuantity & vbCrLf & _
"oStockNumber = " & oStockNumber & vbCrLf & _
"oDescription = " & oDescription, vbInformation, "BOM Related Data")

And I just thought I would include one more image to help clarify some of the details.  This shows you where to access some of the BOM related information about a document manually, just in case you weren't already aware.

Tools tab > Options panel > Document Settings button > Bill of Materials tab (within that dialog).

WCrihfield_0-1648487640918.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4
2208571753
in reply to: A.Acheson

Thanks a lot! You solve my questions.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report