Write BOM number and Quantity to parts

Write BOM number and Quantity to parts

sgorveattXRPG3
Contributor Contributor
1,152 Views
2 Replies
Message 1 of 3

Write BOM number and Quantity to parts

sgorveattXRPG3
Contributor
Contributor

 

The code below is run from the main assembly and allows us to write the BOM # and BOM quantity to each part in the main assembly. This used to work for all parts in the assembly (custom parts, standard content center parts & part library parts).

 

As of Inventor 2018 this no longer works. I believe the code was exploiting a bug that allowed us to write custom variables to read-only parts. This has been fixed so our iLogic code no longer works. 

 

How can I modify this code so that it checks if a part is read-only(ie. standard content center parts, part library parts) and if it is, it's skips those parts? 

 

 

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.ItemQuantity
    
    iProperties.Value(CompFileNameOnly, "Custom", "BOMQTY") = Qty
Next

 

 

0 Likes
Accepted solutions (1)
1,153 Views
2 Replies
Replies (2)
Message 2 of 3

MechMachineMan
Advisor
Advisor
Accepted solution
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

Dim oSkippedDocs As String
oSkippedDocs = "Non-Modifiable Docs that were SKIPPED: " & vblf &
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)

If oCompDef.Document.IsModifiable = True Then Dim Qty As String Qty = oBOMRow.ItemQuantity iProperties.Value(CompFileNameOnly, "Custom", "BOMQTY") = Qty
Else
oSkippedDocs = oSkippedDocs & " - " & CompFileNameOnly & vblf
End if
Next 

MsgBox(oSkippedDocs) 

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 3

sgorveattXRPG3
Contributor
Contributor

Thanks so much!

 

I got "Error on Line 12 : Expression expected.", but I just deleted the & from the end of that line and it worked!