Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Assembly item QTY to model property in parts

Anonymous

Assembly item QTY to model property in parts

Anonymous
Not applicable

Hello,

 

i have this ilogic code provided by @Anonymous that allows me to copy the item number from a part list and past this for each corresponding parts in a model property.

for the item number i have chosen it to fill it in the "stock number field"

 

i have been trying to adapt this code to run it so it would to the same for the item qty in the bom list, and past it in the status field of each corresponding part, regardless of the level of detail.

 

if anyone with experience with the i-logic parameter/names that can help me out with a code, or update the current one i am using, would be appreciated.

 

this is the idea: fill in the stocknumber with item nr data and fill in status with the qty data.

Saltlife212_0-1591806675477.png

 

and this is the current code i am using in the assembly:

Sub Main
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document

Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition

'Get Name of Active LOD
NameActiveLOD = oAssemblyComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name
'Active Master LOD
oAssemblyComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations(1).Activate

Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM

oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews(2) 'Structured view

Call RecursiveCheckAndSetProps(oBOMView.BOMRows,0)

'Reactive original LOD
oAssemblyComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations(NameActiveLOD).Activate
End Sub

Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator, indent As Integer)
	On Error Resume Next
        For Each oBOMRow As BOMRow In oRowsElements
            Dim oComponentDefinition As ComponentDefinition
            oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)

            Dim oBOMItemNumber As String
            oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
			
				Dim rDoc As Document = oComponentDefinition.Document
				Call Check_Prop(rDoc,oBOMItemNumber)

            If Not oBOMRow.ChildRows Is Nothing Then
				Call RecursiveCheckAndSetProps(oBOMRow.ChildRows,indent+1)
            End If
        Next
End Sub

Sub Check_Prop(rDoc As Document,oBOMItemNumber As String)

    Dim oComponentDefinitionPropertySet As PropertySet
    oComponentDefinitionPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
    'project property tab
      'set the Stock Number to the oBOMItemNumber variable
        oComponentDefinitionPropertySet.Item("Stock Number").Value = oBOMItemNumber

End Sub

 

0 Likes
Reply
Accepted solutions (1)
645 Views
2 Replies
Replies (2)

mcgyvr
Consultant
Consultant
Accepted solution

@Anonymous  Did you message me about this and I didn't see it?  Sorry if I left you hanging... 

Anyways... This should do what you want..

 

Sub Main
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document

Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition

'Get Name of Active LOD
NameActiveLOD = oAssemblyComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name
'Active Master LOD
oAssemblyComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations(1).Activate

Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM

oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews(2) 'Structured view

Call RecursiveCheckAndSetProps(oBOMView.BOMRows,0)

'Reactive original LOD
oAssemblyComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations(NameActiveLOD).Activate
End Sub

Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator, indent As Integer)
	On Error Resume Next
        For Each oBOMRow As BOMRow In oRowsElements
            Dim oComponentDefinition As ComponentDefinition
            oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)

            Dim oBOMItemNumber As String
            oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
			Dim oBomQty As String
			oBomQty = oBOMRow.TotalQuantity 'get the total quantity in the bom
			'MessageBox.Show (oBomQty, "Qty")
			
				Dim rDoc As Document = oComponentDefinition.Document
				Call Check_Prop(rDoc,oBOMItemNumber, oBomQty)

            If Not oBOMRow.ChildRows Is Nothing Then
				Call RecursiveCheckAndSetProps(oBOMRow.ChildRows,indent+1)
            End If
        Next
End Sub

Sub Check_Prop(rDoc As Document,oBOMItemNumber As String, oBomQty As String)

    Dim oComponentDefinitionPropertySet As PropertySet
    oComponentDefinitionPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
    'project property tab
      'set the Stock Number to the oBOMItemNumber variable
        oComponentDefinitionPropertySet.Item("Stock Number").Value = oBOMItemNumber
		'set the Status Field to the oBomQty variable
		oComponentDefinitionPropertySet.Item("User Status").Value = oBomQty

End Sub

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes

Anonymous
Not applicable

Thanks for the help @mcgyvr

working like planned!

 

regards