VBA assembly part count and other properties

VBA assembly part count and other properties

Anonymous
Not applicable
2,023 Views
5 Replies
Message 1 of 6

VBA assembly part count and other properties

Anonymous
Not applicable

Greetings

 

I'm trying to make an excel spreadsheet that gets some information from inventor assembly using VBA

Some of those information were part name-QTY-Range Box

Well i was getting part name and range box from AllReferenceDocument.Item(counter).etc etc

The only location were i could find the Quantity of the parts is from ComponentDefinition.BOM.BOMViews.Item(1).BOMRows.Item(counter).ItemQuantity

 

While i was trying my piece of code to various assemblies i noticed that i was getting wrong QTY for the parts. I guess its because Item(Counter) in AllReferenceDocument. is different  than Item(Counter) in ComponentDefinition.BOM.BOMViews.Item(1).BOMRows.

 

Is there any other way to export assemblies' part QTY rather than BOM? if not how can i fix that?

 

Sorry for the description of the problem but I'm not used to any programming language

0 Likes
Accepted solutions (2)
2,024 Views
5 Replies
Replies (5)
Message 2 of 6

YuhanZhang
Autodesk
Autodesk
Accepted solution

The AllReferencedDocuments returns all the referenced documents collection, which includes the directly and in-directly referenced part and sub-assembly documents by this assembly document. For example, if your top assembly has below structure:

TopAssy
  |------Part1.ipt:1
  |------Part1.ipt:2
  |------SubAssy:1
            |------Part1.ipt:1

Then the TopAssy.AllReferencedDocuments will return 2 Items. Even the Part1.ipt has 2 instances in the TopAssy and 1 instance in SubAssy, it is only 1 referenced document. 

 

While if you use the ComponentDefinition.BOM.BOMViews.Item(1).BOMRows.Item(counter).ItemQuantity to get the value of the QTY it returns the number of the instances. If you use the BOMViews(1) or BOMViews("Structured") the QTY for the Part1.ipt returns 2, and BOMViews("PartsOnly") returns 3.  So if you want to get the QTY of the leaf part in both top-assembly and sub-assembly you can use the BOMViews("PartsOnly"). Hope this clears.

 

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 6

MechMachineMan
Advisor
Advisor

It becomes a quickly convoluted process when you consider the usage of Reference Components in the BOM.

 

I would suggest simply iterating through the PartsOnly BOM so you can get total quantities and loop through each document only once. However, this will miss the assembly files as they do not show in the PartsOnly.

 

Another option would be to recursively iterate through your structured BOM as this will have reference components properly accounted for (i.e.; removed). The only issue with this is that it does not roll up quantities of similar parts, nor does it account for top level quantities > 1.

 

Really, it would be nice if Autodesk added a 4th type of BOM that did just what you are asking for as it makes it easier to edit iProperties en masse as well Smiley Happy


--------------------------------------
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 4 of 6

jake_egley
Advocate
Advocate

I cant get the "PartsOnly" version of this to work. If I don't index the BOMviews it works but its top level only. See my code what am I missing? I am using this in VBA

 

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim PQty As Integer
PQty = oAsmDoc.ComponentDefinition.BOM.BOMViews.Item("PartsOnly").BOMRows.Item(1).ItemQuantity
MsgBox (PQty)

 

Jake Egley
Inventor 2022
Message 5 of 6

Curtis_Waguespack
Consultant
Consultant

@jake_egley , 2 things to note. I think it is Parts Only with a space, and you might need to enable it first.

 

' Make sure that the Parts Only view is enabled.
oAsemDoc.ComponentDefintion.BOM.PartsOnlyViewEnabled = True

 

EESignature

Message 6 of 6

jake_egley
Advocate
Advocate
Accepted solution

That was it. Had to enable. Code is now this:

        Dim PQty As Integer
        Dim oBOM As BOM
        Set oBOM = oAsmDoc.ComponentDefinition.BOM
        ' Make sure that the parts only view is enabled.
        oBOM.PartsOnlyViewEnabled = True
        ' Set a reference to the "Parts Only" BOMView
        Dim oPartsOnlyBOMView As BOMView
        Set oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")
        PQty = oPartsOnlyBOMView.BOMRows.Item(counter - 4).ItemQuantity + 1
Jake Egley
Inventor 2022