Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copying Item QTY from Assembly BOM to a Part custom iproperties

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
spanky
349 Views, 7 Replies

Copying Item QTY from Assembly BOM to a Part custom iproperties

spanky
Participant
Participant

Is there a way to use iLogic to copy a value from the assembly BOM 'Item QTY', and paste it to each part in the assembly as a custom iproperty?

 

 

0 Likes

Copying Item QTY from Assembly BOM to a Part custom iproperties

Is there a way to use iLogic to copy a value from the assembly BOM 'Item QTY', and paste it to each part in the assembly as a custom iproperty?

 

 

7 REPLIES 7
Message 2 of 8
A.Acheson
in reply to: spanky

A.Acheson
Mentor
Mentor
Accepted solution

By looping through the BomView object ad each Bom Row you can achieve this. 

Dim assyDoc As AssemblyDocument = ThisDoc.Document
Dim bom As BOM = assyDoc.ComponentDefinition.BOM

bom.PartsOnlyViewEnabled = True

Dim bView As BOMView = bom.BOMViews.Item("Parts Only")

For Each bRow As BOMRow In bView.BOMRows

	If bRow.ComponentDefinitions.Count > 1
		'MessageBox.Show("duplicate part #'s")
		Continue For
	End If

	Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
	
	If Not partDoc.IsModifiable Then Continue For

	' ilogic iProperty Method.
	Try
		Dim componentName As String = IO.Path.GetFileName(partDoc.FullFileName)
		iProperties.Value(componentName,"Custom", "TOTAL QTY") = bRow.ItemQuantity
	Catch
	End Try
	
'	' API PropertySets Method.
'	Dim totalQty As Inventor.Property
'	Try
'		totalQty = partDoc.PropertySets.Item(4).Item("TOTAL QTY") 
'		totalQty.Value = bRow.ItemQuantity
'	Catch
'		totalQty = partDoc.PropertySets.Item(4).Add(bRow.ItemQuantity,"TOTAL QTY")
'	End Try

Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

By looping through the BomView object ad each Bom Row you can achieve this. 

Dim assyDoc As AssemblyDocument = ThisDoc.Document
Dim bom As BOM = assyDoc.ComponentDefinition.BOM

bom.PartsOnlyViewEnabled = True

Dim bView As BOMView = bom.BOMViews.Item("Parts Only")

For Each bRow As BOMRow In bView.BOMRows

	If bRow.ComponentDefinitions.Count > 1
		'MessageBox.Show("duplicate part #'s")
		Continue For
	End If

	Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
	
	If Not partDoc.IsModifiable Then Continue For

	' ilogic iProperty Method.
	Try
		Dim componentName As String = IO.Path.GetFileName(partDoc.FullFileName)
		iProperties.Value(componentName,"Custom", "TOTAL QTY") = bRow.ItemQuantity
	Catch
	End Try
	
'	' API PropertySets Method.
'	Dim totalQty As Inventor.Property
'	Try
'		totalQty = partDoc.PropertySets.Item(4).Item("TOTAL QTY") 
'		totalQty.Value = bRow.ItemQuantity
'	Catch
'		totalQty = partDoc.PropertySets.Item(4).Add(bRow.ItemQuantity,"TOTAL QTY")
'	End Try

Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8
spanky
in reply to: A.Acheson

spanky
Participant
Participant

Any ideas? @A.Acheson 

 

It gives me an error in Line 15.

 

spanky_0-1691674853227.png

spanky_1-1691674896933.png

 

 

 

0 Likes

Any ideas? @A.Acheson 

 

It gives me an error in Line 15.

 

spanky_0-1691674853227.png

spanky_1-1691674896933.png

 

 

 

Message 4 of 8
Curtis_Waguespack
in reply to: spanky

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @spanky 

 

It likely just tripped over a subassembly in your BOM

 

I think you can just change line 15 

 

from this:

 

Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document

 

to this:

 

Dim partDoc As Document = bRow.ComponentDefinitions(1).Document

 

 

Hi @spanky 

 

It likely just tripped over a subassembly in your BOM

 

I think you can just change line 15 

 

from this:

 

Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document

 

to this:

 

Dim partDoc As Document = bRow.ComponentDefinitions(1).Document

 

 

Message 5 of 8
GosponZ
in reply to: spanky

GosponZ
Collaborator
Collaborator

Try this one run in assembly.

doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM

oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow As BOMRow

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow.ComponentDefinitions.Item(1)
    
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index+1)
    
    'MessageBox.Show(CompFileNameOnly)
    
    Dim Qty As String
    Qty = oBOMRow.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "PartQty") = Qty
Next

 

Try this one run in assembly.

doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM

oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow As BOMRow

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow.ComponentDefinitions.Item(1)
    
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index+1)
    
    'MessageBox.Show(CompFileNameOnly)
    
    Dim Qty As String
    Qty = oBOMRow.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "PartQty") = Qty
Next

 

Message 6 of 8

A.Acheson
Mentor
Mentor

Cheers Curtis,

 

I hadn't allowed for assemblies being inseparable and being in there which is why it tripped up on the part document declaration. The generic document declaration will allow both part documents and assembly document processing. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Cheers Curtis,

 

I hadn't allowed for assemblies being inseparable and being in there which is why it tripped up on the part document declaration. The generic document declaration will allow both part documents and assembly document processing. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 8
spanky
in reply to: A.Acheson

spanky
Participant
Participant

Thank you!

0 Likes

Thank you!

Message 8 of 8
spanky
in reply to: GosponZ

spanky
Participant
Participant

This one worked also, but seems to have pulled the standard QTY data, versus the Item QTY. But thank you for the help also!

0 Likes

This one worked also, but seems to have pulled the standard QTY data, versus the Item QTY. But thank you for the help also!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report