ILogic Code to put Drawing BOM Item number into a part custom iproperty

ILogic Code to put Drawing BOM Item number into a part custom iproperty

BrandonLee_Innovex
Contributor Contributor
379 Views
1 Reply
Message 1 of 2

ILogic Code to put Drawing BOM Item number into a part custom iproperty

BrandonLee_Innovex
Contributor
Contributor

Hello, 

 

I am trying to determine a way to grab an item number from a drawing BOM and have it populate in a custom iproperty. 

A little background why.... We have a custom view label that needs to reference the BOM as well as the single part file.

brandonlee97_0-1653086062457.png

If anyone has any Ilogic code that may work to achieve this, please let me know 

Thank you for your time 

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

JelteDeJong
Mentor
Mentor

try the following rule in a drawing of an assembly.

 

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)

Dim assemblyDoc As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument
Dim propertyName As String = "BomItemNumber"

Dim bom As BOMView = assemblyDoc.ComponentDefinition.BOM.BOMViews.Item("Structured")
For Each row As BOMRow In bom.BOMRows
    Dim itemNumber As String = Row.ItemNumber

    ' 1 bom row can be associated with multiple parts
    ' we need to find all.
    For Each occ As ComponentOccurrence In Row.ComponentOccurrences
        Try
            Dim occDoc As Document = occ.ReferencedDocumentDescriptor.ReferencedDocument
            Dim propSet As PropertySet = occDoc.PropertySets.Item("Inventor User Defined Properties")

            Try
                propSet.Item(propertyName).Value = itemNumber
            Catch ex As Exception
                propSet.Add(itemNumber, propertyName)
            End Try

        Catch ex As Exception
            MsgBox("Could not set Item number to occurrence: " & occ.Name)
        End Try
    Next
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes