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

Master Assy Qty for SubAssy and Parts at the Drawing Level

timothy_berg
Advocate

Master Assy Qty for SubAssy and Parts at the Drawing Level

timothy_berg
Advocate
Advocate

Is there anyway to get the Master Assembly qty of a part or subassembly at the drawing level? On the attached pdf there is a qty of 72 pieces of the part on dwg#1020-8000-00-039 (pg 43 of the pdf), is there any way, besides a manual input, to get the qty from the master assembly to that page?

0 Likes
Reply
Accepted solutions (1)
645 Views
12 Replies
Replies (12)

MechMachineMan
Advisor
Advisor

Take a look at a solution for this I made previously and let me know how/if your requirements differ.

 

https://forums.autodesk.com/t5/inventor-customization/part-quantities-per-assembly/td-p/6858321

 

 


--------------------------------------
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
0 Likes

timothy_berg
Advocate
Advocate

does that run in iLogic?

 

 

0 Likes

MechMachineMan
Advisor
Advisor
It is in VBA, so you can use the Macro environment.

Although + F11.
Right click and insert a new module under the Application Project.
Paste the code from the last post in that thread.

Save.

Hit the macro button under Tools Ribbon.

Run the macro.

--------------------------------------
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
0 Likes

MechMachineMan
Advisor
Advisor
It is in VBA, so you can use the Macro environment.

Although + F11.
Right click and insert a new module under the Application Project.
Paste the code from the last post in that thread.

Save.

Hit the macro button under Tools Ribbon.

Run the macro.

--------------------------------------
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
0 Likes

timothy_berg
Advocate
Advocate

tried that and got the attached error message, it also got stuck in a loop 

0 Likes

Owner2229
Advisor
Advisor

Hey, getting the qty from the top assembly is quite easy in fact (if you have the top assy and the part/sub assy references. e.g. from a view).

 

So, let's say the top assy document is the first view from the first sheet from the drawing and the searched document is in the first view from the second sheet. The code would then look like this:

 

Sub Main
'Get the active document

Dim oDoc As Document = ThisApplication.ActiveDocument
'Check if it's a drawing
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
'Get the drawing sheets
Dim oSheets As Sheets = oDoc.Sheets
'Get the top/sub doc from 1./2. sheet, 1. view
Dim oTopDoc As Document = GetViewDoc(oSheets, 1, 1)
Dim oSubDoc As Document = GetViewDoc(oSheets, 2, 1)
If oTopDoc Is Nothing Or oSubDoc Is Nothing Then Exit Sub
Dim oTopCD As AssemblyComponentDefinition = oTopDoc.ComponentDefinition Dim oPartEnum As ComponentOccurrencesEnumerator = oTopCD.Occurrences.AllReferencedOccurrences(oSubDoc) Dim QTY As Integer = oPartEnum.Count
MsgBox(QTY)
End Sub
Private Function GetViewDoc(oSheets As Sheets, iSheet As Integer, iView As Integer) As Document
Dim oDoc As Document = Nothing
Try
Dim oSheet As DrawingSheet = oSheets(iSheet)
Dim oView As DrawingView = oSheet.DrawingViews(iView)
oDoc = oView.ReferencedDocumentDescriptor
Catch
End Try
Return oDoc
End Function

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

timothy_berg
Advocate
Advocate

The part in question is not in the BOM listed on page 1? It is buried in multiple subassemblies of the master assembly. The parts BOM of the master has the total qty needed and that is what i would like to have in a custom iprop so it can be displayed on the drawing of the part.  Also i tried your code in iLogic and VBA neither one worked.

 

 

0 Likes

Owner2229
Advisor
Advisor

Alright, little correction in the code. As for the function, I've tested it and it will get the occurence count top-down from the top assembly, so it doesn't matter if the document is in the top assy or in the deepest one, it'll get them all.

Orange is what I've changed.

 

Sub Main
'Get the active document

Dim oDoc As Document = ThisApplication.ActiveDocument
'Check if it's a drawing
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
'Get the drawing sheets
Dim oSheets As Sheets = oDoc.Sheets
'Get the top/sub doc from 1./2. sheet, 1. view
Dim oTopDoc As Document = GetViewDoc(oSheets, 1, 1)
Dim oSubDoc As Document = GetViewDoc(oSheets, 2, 1)
If oTopDoc Is Nothing Or oSubDoc Is Nothing Then Exit Sub
Dim oTopCD As AssemblyComponentDefinition = oTopDoc.ComponentDefinition Dim oPartEnum As ComponentOccurrencesEnumerator = oTopCD.Occurrences.AllReferencedOccurrences(oSubDoc) Dim QTY As Integer = oPartEnum.Count
MsgBox(QTY)
End Sub
Private Function GetViewDoc(oSheets As Sheets, iSheet As Integer, iView As Integer) As Document
Dim oDoc As Document = Nothing
Try
Dim oSheet As DrawingSheet = oSheets(iSheet)
Dim oView As DrawingView = oSheet.DrawingViews(iView)
oDoc = oView.ReferencedFile.ReferencedDocument
Catch
End Try
Return oDoc
End Function

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

timothy_berg
Advocate
Advocate

Thanks Mike I appreciate your help is this for iLogic i get this error when attempting to run I also got an error in VBA

0 Likes

Owner2229
Advisor
Advisor

Yea, it's iLogic. Also there should be "Sheet" instead of "DrawingSheet".

 

Sub Main
'Get the active document

Dim oDoc As Document = ThisApplication.ActiveDocument
'Check if it's a drawing
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
'Get the drawing sheets
Dim oSheets As Sheets = oDoc.Sheets
'Get the top/sub doc from 1./2. sheet, 1. view
Dim oTopDoc As Document = GetViewDoc(oSheets, 1, 1)
Dim oSubDoc As Document = GetViewDoc(oSheets, 2, 1)
If oTopDoc Is Nothing Or oSubDoc Is Nothing Then Exit Sub
Dim oTopCD As AssemblyComponentDefinition = oTopDoc.ComponentDefinition Dim oPartEnum As ComponentOccurrencesEnumerator = oTopCD.Occurrences.AllReferencedOccurrences(oSubDoc) Dim QTY As Integer = oPartEnum.Count
MsgBox(QTY)
End Sub
Private Function GetViewDoc(oSheets As Sheets, iSheet As Integer, iView As Integer) As Document
Dim oDoc As Document = Nothing
Try
Dim oSheet As Sheet = oSheets(iSheet)
Dim oView As DrawingView = oSheet.DrawingViews(iView)
oDoc = oView.ReferencedFile.ReferencedDocument
Catch
End Try
Return oDoc
End Function

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

timothy_berg
Advocate
Advocate

Mike thanks for the response I think i'm not explaining this very well. What i would like to have is the rule ran at the master assy bom level (in the .iam file) and put a total qty into a custom i property field of the part. When I run the rule you have provided it gave me a message box of zero. Thanks for your help.

0 Likes

timothy_berg
Advocate
Advocate
Accepted solution

I found this on another thread and it does exactly what I want thanks for everybody's help.

 

https://forums.autodesk.com/t5/inventor-forum/quantity-om-drawing-based-on-total-number-of-parts-ilo...

 

 

0 Likes