Write BOM QTY to part files, but skipping Library files

Write BOM QTY to part files, but skipping Library files

nick_desmet3CLTQ
Observer Observer
84 Views
1 Reply
Message 1 of 2

Write BOM QTY to part files, but skipping Library files

nick_desmet3CLTQ
Observer
Observer

So, my lack of iLogic knowledge is fully apparent with this one.

We are currently using this code to write all the quantities to part level in a Custom iProperty, including how many pieces are not in a subassembly.

However, know I would like to edit this so it skips all the non-editable parts, thinking about Library parts and later parts that are set to Released in Vault.

 

Can anyone help me?

 

Thanks in advance!

 

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("Structured")
Dim oBOMRow As BOMRow

question = MessageBox.Show("Write Assemblyname and Quantities to Parts", "Actum-Services",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If question = vbYes Then
	
Dim oBOMView3 As BOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow3 As BOMRow

For Each oBOMRow3 In oBOMView3.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow3.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)
    
    Dim Qty As String
    Qty = oBOMRow3.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "LoosePieces") = 0
Next

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)

    Dim Qty As String
    Qty = oBOMRow.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "LoosePieces") = Qty
	iProperties.Value(CompFileNameOnly, "Custom", "PCS") = Qty
	iProperties.Value(CompFileNameOnly, "Custom", "Assemblyname") = ThisDoc.FileName(False)
Next

Dim oBOMView2 As BOMView = oBOM.BOMViews.Item("Parts Only")
Dim oBOMRow2 As BOMRow

For Each oBOMRow2 In oBOMView2.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow2.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)
    
Dim AllPieces As String
    AllPieces = oBOMRow2.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "PCS") = AllPieces 
	iProperties.Value(CompFileNameOnly, "Custom", "Assemblyname") = ThisDoc.FileName(False)
Next

End If

 

0 Likes
85 Views
1 Reply
Reply (1)
Message 2 of 2

bradeneuropeArthur
Mentor
Mentor

Try this out please.

I have added this:

 '##########
	Dim p As Document = oCompDef.Document
	If p.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim prt As PartDocument = p
		If prt.ComponentDefinition.IsContentMember Then
	Exit For
	End If
	End If	
    '#########

With this as result

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("Structured")
Dim oBOMRow As BOMRow

question = MessageBox.Show("Write Assemblyname and Quantities to Parts", "Actum-Services",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If question = vbYes Then
	
Dim oBOMView3 As BOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow3 As BOMRow

For Each oBOMRow3 In oBOMView3.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow3.ComponentDefinitions.Item(1)
	'##########
	Dim p As Document = oCompDef.Document
	If p.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim prt As PartDocument = p
		If prt.ComponentDefinition.IsContentMember Then
	Exit For
	End If
	End If	
    '#########
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index+1)
    
    Dim Qty As String
    Qty = oBOMRow3.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "LoosePieces") = 0
Next

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 p As Document = oCompDef.Document
	If p.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim prt As PartDocument = p
		If prt.ComponentDefinition.IsContentMember Then
	Exit For
	End If
	End If	
    '#########
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index+1)

    Dim Qty As String
    Qty = oBOMRow.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "LoosePieces") = Qty
	iProperties.Value(CompFileNameOnly, "Custom", "PCS") = Qty
	iProperties.Value(CompFileNameOnly, "Custom", "Assemblyname") = ThisDoc.FileName(False)
Next

Dim oBOMView2 As BOMView = oBOM.BOMViews.Item("Parts Only")
Dim oBOMRow2 As BOMRow

For Each oBOMRow2 In oBOMView2.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow2.ComponentDefinitions.Item(1)
    '##########
	Dim p As Document = oCompDef.Document
	If p.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim prt As PartDocument = p
		If prt.ComponentDefinition.IsContentMember Then
	Exit For
	End If
	End If	
    '#########
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index+1)
    
Dim AllPieces As String
    AllPieces = oBOMRow2.TotalQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "PCS") = AllPieces 
	iProperties.Value(CompFileNameOnly, "Custom", "Assemblyname") = ThisDoc.FileName(False)
Next

End If

 Knowing/using this the code could be much simpler, but that was not the question isn't it?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes