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

Make a Custom iProperty equal to the Item in the Parts Only Bom

Anonymous

Make a Custom iProperty equal to the Item in the Parts Only Bom

Anonymous
Not applicable

I would like to be able to run an ilogic program from within an assembly that would update a custom iproperty named BomNo within all the parts to its corresponding Item listed in the assembly BOM. 

 

Does anyone know the code that would do this?

 

Thanks,

Morgan

0 Likes
Reply
1,802 Views
12 Replies
Replies (12)

BrandonBG
Collaborator
Collaborator
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

 

I think this accomplishes what you want, however, if the custom iProperty already exists, you'll get an error.

 

BrandonBG

Inventor2015

Anonymous
Not applicable

Thank you.  This gets me part of the way.  This rule will be run more than once for a specific part and like you have pointed out you receive an error if you run it multiple times.

0 Likes

Anonymous
Not applicable

Hi Brandon,

 

Any idea how to manipulate this code to get what I want?  This code copies the BOM Qty to a custom iProperty named AssemQty

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef= ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
iProperties.Value(oOccurrence.Name,"Custom", "AssemQty")= ThisBOM.CalculateQuantity("Model Data", iProperties.Value(oOccurrence.Name, "Project", "Part Number"))
Next

 

Thanks,

Morgan

0 Likes

Anonymous
Not applicable

Could this code be adapted so the BOM item number be carried over to the view label?

0 Likes

BrandonBG
Collaborator
Collaborator
Your code is working for me. I'm getting a new custom iProperty in each component.

What are you trying to get it to do?

BrandonBG
0 Likes

BrandonBG
Collaborator
Collaborator

Yes, but I believe that the iLogic rule would have to be run in the drawing, not the assembly.

 

http://inventortrenches.blogspot.com/2012/01/set-your-drawing-view-labels-to-use.html

 

Scroll down to the UPDATE portion of his post.

 

BrandonBG

 

0 Likes

Anonymous
Not applicable

Yes this code works to get the qty into a custom property.  I would like it to do the same but copy the BOM number to a custom property. 

 

Thanks,

Morgan

0 Likes

BrandonBG
Collaborator
Collaborator

I don't believe you can access the BOM Item Number through ThisBom.

 

See: http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-10A98DEE-0617-4D36-8FE5-B145929833E1

 

In the BOM window in the Assembly, there are three BOM tabs: Model, Structured, and Parts Only. It is my understanding that ThisBOM looks at the Model tab only. If you right-click on the column headers, then Runtime Column Customization, you'll see what data is available.

 

BrandonBG

0 Likes

Anonymous
Not applicable

Hi Brandon,

 

Can the code be adjusted to use the 'Parts Only' bom?

 

Thanks,

Morgan

0 Likes

BrandonBG
Collaborator
Collaborator

Yes . . .  but, the Item Number still isn't accessible.

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef= ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences iProperties.Value(oOccurrence.Name,"Custom", "AssemQty")= ThisBOM.CalculateQuantity("Parts Only", iProperties.Value(oOccurrence.Name, "Project", "Part Number")) Next

 

I can't really explain why it's not there. ThisBOM doesn't have the same functionality that the BOM object has. See my earlier post.

 

BrandonBG

0 Likes

eric.smyth
Participant
Participant

This is working for me. I do get an error when it gets to a part that cannot be changed. then stops the rule. I get around this by putting all those parts to the end of the list. is there a bit of code that will skip this or on error go to next?

0 Likes

eric.smyth
Participant
Participant

for future users... this seems to work.

 

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("Structured") 'or structured Parts Only

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


  If oComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then GoTo start

  	Try
				oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
				Catch ex As Exception					
				customProp = oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
			End Try
  
  'oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number") 
     'creates the custom property and inputs the value
start:	
Next

 

0 Likes