- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
HI!
I'm trying to find a way to catch the Item number (structured BOM) and create an iProperty in every assembly's parts.
I'm using the code below and it works really good for assemblies in a "master LOD", and without Content center and/or library parts.
These are my two problems:
1- First issue is, i need a custom LOD, because i run other rules to make active(or not) some parts.
If i use a custom LOD, the rule doesn't work at all.
A) Any idea to put this code running in a custom LOD?
2- Also, i have some parts from the library, and besides the rule works in the normal parts, it stops when finding a non-modifiable part and an error box appear eventually.
The questions are:
A) how can i avoid the error message?
(I tried the " on error resume", but it's incompatible with the "try" statement).
(Also tried the "if the part is modificable= true then", but i think this will not work for this case).
Sub Main Dim oAssemblyDocument As AssemblyDocument oAssemblyDocument = ThisDoc.Document Dim oAssemblyComponentDefinition As AssemblyComponentDefinition oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition Dim oBOM As BOM oBOM = oAssemblyComponentDefinition.BOM oBom.StructuredViewEnabled = True Dim oBOMView As BOMView oBOMView = oBom.BOMViews(2) 'Structured view oBom.StructuredViewFirstLevelOnly = False oBom.StructuredViewDelimiter = "." Call RecursiveCheckAndSetProps(oBOMView.BOMRows) End Sub Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator) 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 ' MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on Dim oComponentDefinitionPropertySet As PropertySet oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties") 'custom property tab Try 'if already exists then set it oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber Catch ex As Exception 'else add it oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number") End Try 'creates the custom property and inputs the value If Not oBOMRow.ChildRows Is Nothing Then Call RecursiveCheckAndSetProps(oBOMRow.ChildRows) End If Next End Sub
Solved! Go to Solution.