VBA for accessing and modifying user define iproperties with oBOM.BOMViews

VBA for accessing and modifying user define iproperties with oBOM.BOMViews

ChristianHolme5777
Participant Participant
383 Views
2 Replies
Message 1 of 3

VBA for accessing and modifying user define iproperties with oBOM.BOMViews

ChristianHolme5777
Participant
Participant

HI, 


I am trying to write a VBA as a test to access the 1st row of an assembly BOM. I wish to access iproperties through oBOM.BOMViews and then modify the value. I took reference from some examples on this forum and come up with a small piece of code. However, it is not working and I have no clue how read the User Define properties "Type" which is already defined in the part file. Thanks in advance 

 

Public Sub BOM_dunc_test()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
Set oBOM = oDoc.ComponentDefinition.BOM

oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView

Set oBOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRows As BOMRowsEnumerator
Set oBOMRows = oBOMView.BOMRows

Dim oRow As BOMRow

Set oRow = oBOMRows.Item(1)

Dim oBOMRowDoc As ComponentDefinition

Set oBOMRowDoc = oRow.ComponentDefinitions(1)

Dim oType As String

Set oType = oROMRowDoc.PropertySets.Item("Inventor User Defined Properties").Item("Type").Value


End Sub

0 Likes
384 Views
2 Replies
Replies (2)
Message 2 of 3

k14348
Advocate
Advocate

Hi,

    We can able to access only Assembly custom iproperties using Bill of materials.  and also we can able create new custom iproperties for parts level using Assembly bom. We cannot access existing iproperties of parts. Based on this now you tell me what i have to do using vba codes.

0 Likes
Message 3 of 3

Anonymous
Not applicable
On Error Resume Next
    ' Get the custom property set.
    Dim invCustomPropertySet As PropertySet
    Set invCustomPropertySet = oDoc.PropertySets.item("Inventor User Defined Properties")
            
    Dim a_Property As Property
    Dim customPropertyCount As Integer
    
    customPropertyCount = invCustomPropertySet.Count
    Dim i As Integer
    
    If customPropertyCount > 0 Then
    
        For i = 1 To customPropertyCount
            Set a_Property = invCustomPropertySet.item(i)
            
            With Me.ListBoxCustomData
                .AddItem
                '.list(rCount, 0) = i
                .list(rCount, 0) = a_Property.displayName
                .list(rCount, 1) = a_Property.Expression
            
                rCount = rCount + 1
            End With
            
        Next i
     End If

002.jpg

 

Hi, I hope that it helps.

0 Likes