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

Hei BrandonBG, 

 

Thanks for the tip but when I use that first code I get an error:

 

Error in rule: Rule1, in document: 7951 P02 Rømningstrapp.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

I ran the rule while standing in the main assembly. Right?

 

 

Dim oAssemblyDocument As AssemblyDocument 
oAssemblyDocument= ThisDoc.Document

Dim oAssemblyComponentDefinition As AssemblyComponentDefinition 
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition

Dim oBOM As BOM 
oBOM = oAssemblyComponentDefinition.BOM

oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView 
oBOMView = oBOM.BOMViews.Item("Parts Only") 'or structured

For Each oBOMRow As BOMRow In oBOMView.BOMRows
  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 oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
'creates the custom property and inputs the value Next