Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple sub assemblies in a Parts List

11 REPLIES 11
Reply
Message 1 of 12
Myles1
4443 Views, 11 Replies

Multiple sub assemblies in a Parts List

Does anyone know of a way to create a parametric Parts List containing subassemblies, where the subs are listed, by name/item number, in colum format, and qty's are tabulated accross rows. (see attached as an example).  If the same part number occurs in multiple subs, the part is only listed once, but the quantity for each sub would be noted.  The pdf attached had to be done manually, which somewhat defeats the purpose of haveing software like Inventor.

 

 

Inv 2011

11 REPLIES 11
Message 2 of 12
mcgyvr
in reply to: Myles1

Not exactly like that.. But if you use iassemblies then place a parts list then edit the parts list and press the member selection button you can select each one of the iassembly members and it will do something like that..

 

I do wish Inventor had more "styles" of that type of tabulated parts list to choose from.



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 12
rhasell
in reply to: Myles1

I use iLogic code which creates a project number in each part/ assembly. This is associated with a particular project that the part is used in. If this part is used in multiple assemblies, it will get multiple project numbers.

 

The iLogic code populates the "Project number feild" with the QTY.

The part will now multiple QTY's attached to it, which can then be used anywhich way you desire.

You must just remember to run the code just before detailing to ensure up to date values.

 

NOTE: Unless so desired Always run this from the GA and not the sub assemblies.

 

The thing I love about it, is that I have taken the human element out of it, no more counting/guessing.

I takes a minute or so to run for the first time on large Assemblies.

 

It took me a long time to get this working, I hope it works for you.

 

Sub Main ()
	If iProperties.Value("Project", "Project")=""
		oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
		iProperties.Value("Project", "Project")=oProj
	End If

'get the project number of this assembly and use it to build the name of a custom property, i.e. "4100_QTY"
customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"

	oQ=MessageBox.Show(customPropertyName, "Project Number",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
		If oQ=vbYes
		oDone()
		ElseIf oQ=vbNo
		Call oProject
		ElseIf oQ=vbCancel
		MessageBox.Show("Cancelled", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
		Return
	End If
End Sub

Sub oDone
oCompDef = ThisDoc.Document.ComponentDefinition
openDoc = ThisDoc.Document
customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"
'Let's open the document that inventor has in focus right now
 

'Let's check to make sure that it's an assembly document.
'We don't want to run this on just a part document as it -
'will have none of the required information! 
If openDoc.DocumentType = kAssemblyDocumentObject Then  
    
    'If it is an assembly document, then we need to get a collection
    'of all the documents that are associated to it. 
    'the following line actually does that, while at the time time
    'starts the loop to look at each one of those documents. 
    
    'imagine that it's written out in this way : 
    'For each Document file in the collection of ALL the document
    'files that are in this open document, do the stuff below... 
    For Each docFile In openDoc.AllReferencedDocuments
        
        'First thing first, we need to make a string that can represent the 
        'document that we're working on. This way it will be easier to 
        'call on that document when we want to make changes to the iproperties. 
        'this is no different than if you just typed out : 
        '
        'iProperties.Value("Part_Name_Here.ipt", "Project", "Authority") 
        '
        'But because we are doing this dynamically, we don't have to type that 
        'about line out for every single part that is in the document. 
        '
        'FNamePos is getting the number of spaces that it takes to get to the 
        'very last back slash in the full file name of our document.         
        FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        
        'We can then take that number (position) and use it to cut off all of the 
        'file path that we don't need. In this case, it's the front of the path
        'that we're getting rid of, leaving us with just the file name.
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        'Let's make sure that we can even change this part. If we can, then we'll continue. 
        If docFile.IsModifiable = True Then
            
            'Because you can only grab the occurrences from an assembly document
            'we need to fill up that empty AssemblyDocument container with an object
            'that we know is definitely an assembly document. Because that was one
            'of the first checks we made up there on this open document, we can safely
            'declare that assemblyDoc (Which is an AssemblyDocument) is equal to 
            ' openDoc (Which is just a regular old Document)             
            assemblyDoc = openDoc        
            
            'While we're at it, let's go on and define the empty ComponentDefinition container
            '(we named ours assemblyDef) with some sort of content. 
            assemblyDef = assemblyDoc.ComponentDefinition
            
            'Now we need to collect every instance of the document against
            'our open assembly and put them all inside of partQty. 
            partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
            
                'Now that we have our collection of instances, we need to populate
                'our target iproperty with the total amount. 
                
                'Instead of just throwing that amount in there, let's make sure that
                'the value inside of the target iProperty isn't already equal to our count. 
                'If it is equal, then we don't have to change anything (which saves us time!),
                'but if it isn't equal then we will need to change it. 
                
                'The Try statement is here because of the next if statement ---
                '
                'If partQty.Count <>  iProperties.Value(docFName, "Project", "Authority") Then'
                '
                'If we just compare the two values, there is a small chance that our target
                'iProperty is already set to something that is NOT a number, which would create
                'an error (as you can't compare numbers against things that aren't numbers). 
                'So, we TRY to complete that if statement, and if there is an error (The CATCH)
                'we just force that target to equal our part qty total. 
                Try
						If partQty.Count <>  iProperties.Value(docFName, "Custom", customPropertyName) Then                
						iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                    End If                      
                    Catch
					iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                End Try
        End If
    Next
Else

'This is here to warn the user that they are attempting to run this in a document that is invalid!
'we don't want them running things that aren't correct! Force them to obey! 
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 
iLogicVb.UpdateWhenDone = True 
MessageBox.Show("Completed", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub

Sub oProject
	oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
	iProperties.Value("Project", "Project")=oProj
	Main ()
End Sub

 

 

Reg
2024.2
Please Accept as a solution / Kudos
Message 4 of 12
Anonymous
in reply to: rhasell

Wow, this is amazing. I was looking for this for ages.
I try this and it works perfect, but except library parts.


I’m using Vault. I run pack and go for main assebly of some project  to single-user project.
In this single-user project I would like to use this rule.

 

Pack and go copied files to a hierarchy same as in Vault. In this case this rule doesn’t work for library parts.

 

With setting pack and go to copy all files to one folder it works great.

 

Please can you help me what I’m doing wrong or if it is possible to do it also for library parts?

 

Thanks a lot.

Message 5 of 12
MechMachineMan
in reply to: Anonymous

If you are wanting to add information about library parts to a BOM, you will likely just have to add it to the parts list in a custom column - the exception is for if this information is consistent across every single project you use the library file in, and will be fore the future.

 

Also, I rewrote @rhasell code without the comments and with nesting for anyone else who comes across it has something to add/modify to make it work for you.

 

Sub Main ()
	If iProperties.Value("Project", "Project")=""
		oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
		iProperties.Value("Project", "Project")=oProj
	End If

	customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"

	oQ=MessageBox.Show(customPropertyName, "Project Number",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
		
	If oQ=vbYes
		oDone()
	ElseIf oQ=vbNo
		Call oProject
	ElseIf oQ=vbCancel
		MessageBox.Show("Cancelled", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
		Return
	End If
End Sub

Sub oDone
	oCompDef = ThisDoc.Document.ComponentDefinition
	openDoc = ThisDoc.Document
	customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"
 
	If openDoc.DocumentType = kAssemblyDocumentObject Then  
    
    		For Each docFile In openDoc.AllReferencedDocuments       
        		FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        		If docFile.IsModifiable = True Then  
            			assemblyDef = assemblyDoc.ComponentDefinition
            			partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
                		
				Try
					If partQty.Count <>  iProperties.Value(docFName, "Custom", customPropertyName) Then                
						iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                    			End If                      
                    		Catch
					iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                		End Try
        		End If
    		Next
	Else
		MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
	End If 

	iLogicVb.UpdateWhenDone = True 
	MessageBox.Show("Completed", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub

Sub oProject
	oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
	iProperties.Value("Project", "Project")=oProj
	Main ()
End Sub
 
 

 


--------------------------------------
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 6 of 12
rhasell
in reply to: Anonymous

Hi

 

When the library is configured in the project definition, it is setup as Read only.

 

This was also by design, all my library parts are fasteners, and I did not want to carry around hundreds of project numbers attached to a M20 nut. So I relied on the fact that the library is read only.

 

Therefore, your workaround is correct, you have to move/copy the library parts into another folder that is not set up as a library folder in your project definition.

 

By design, you cannot edit a library part in the normal manner once it has been created.

 

 

 

Reg
2024.2
Please Accept as a solution / Kudos
Message 7 of 12
rhasell
in reply to: rhasell

Hi

 

Another small update:

Here is a snippet, that can be added at the bottom, I left some of the existing code, so that you can find the insertion point.

 

-------

                    iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                End Try
        End If
    Next
'29/01/2016
'I Added the following line to add the value to the GA
' As the lack thereoff was causing issues in the detailing environment.
            Try
                oASSYParam= iProperties.Value("Custom",customPropertyName)
              Catch
                iProperties.Value("Custom",customPropertyName) = "1"
                    End Try
'This is here to warn the user that they are attempting to run this in a document that is invalid!
'we don't want them running things that aren't correct! Force them to obey!
'testing MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
'testing End If
iLogicVb.UpdateWhenDone = True
MessageBox.Show("Completed" , "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub

Sub oProject

--------------------------------------

Reg
2024.2
Please Accept as a solution / Kudos
Message 8 of 12
Anonymous
in reply to: MechMachineMan

There is some error in line 33

 

                   assemblyDef = assemblyDoc.ComponentDefinition

 "Type assemblyDoc not declared"

 

Thanks a lot

Petr

Message 9 of 12
Anonymous
in reply to: rhasell

One "End If" is missing.

 

There is in your snippet 'testing End If.

 

I know that library parts are read only. There isn’t way how to force it in Inventor?

We have many standard part as library.

I want to use it only temporary - as I wrote "pack and go" from Vault to temporary project, run rule, print drawing (with iproperty _QTY in stamp). Than delete data.

I changed the library path in temporary project. So now files from "pack and go" are outside the library.

It is working.

 

Thanks Petr

Message 10 of 12
Anonymous
in reply to: rhasell

Hi rhasell,

 

Can you maybe tell me exactly which steps i should follow. I never worked with ilogic, and your solution sounds like heaven for me ...

 

kind regards 

 

Dries

Message 11 of 12
rhasell
in reply to: Anonymous

Hi

 

I can help to a certain degree.

Getting started with iLogic it pretty straight forward, starting small is the best option.

 

Not sure if you know the following, ignore, if you do.

To get started, its easiest to have the 'iLogic browser' visible. This can be found in the 'manage tab' 'ilogic'

One other setting is the External rules setup.

 - Tools' tab

- Click on the down arrow in 'Options'

 

Once that is done, make a simple rule for yourself using preset snippets.

 

----------------------

The Rule....

I use this rule all the time, it's gold. I will re-post the entire rule so that there is no confusion.

 

The best option is to create this as an external rule, it then available at any stage.

 

It is best to be run at the end of a build just before going to paper, but it can also be run at any time you wish.

 

Screen dumps of an example:

The rule was run from the GA, and the screen capture is of a sub assembly.

 

 

bom-qty1.JPGbom-qty2.JPG

 

 

'01/03/2017
'Reg Hasell.
'This iLogic rule will run though all the items in an assembly and add a QTY field to it.
'The QTY field is based on a programmable project number. (project_QTY)
'Any Content Center items are ignored. (Read Only)
'There is an option to set the project number.
'
'Some of this code has originated from the forum, but I cannot
'remember where I got it from, so I am unable To give credit To the original author.

Sub Main ()
	'Check to see if this document is an assembly.
	oDoc = ThisApplication.ActiveDocument
		If oDoc.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("This rule can only be run in an Assembly file - exiting rule...", "GDI iLogic")
		Return
		End If
	If iProperties.Value("Project", "Project")=""
		oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
		iProperties.Value("Project", "Project")=oProj
	End If

'get the project number of this assembly and use it to build the name of a custom property, i.e. "4100_QTY"
customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"

	oQ=MessageBox.Show(customPropertyName, "Project Number",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
		If oQ=vbYes
		oDone()
		ElseIf oQ=vbNo
		Call oProject
		ElseIf oQ=vbCancel
		MessageBox.Show("Cancelled", "GDI iLogic", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
		Return
	End If
End Sub

Sub oDone
oCompDef = ThisDoc.Document.ComponentDefinition
openDoc = ThisDoc.Document
customPropertyName = CStr(iProperties.Value("Project", "Project")) & "_QTY"
'Open the document that inventor has in focus right now
    For Each docFile In openDoc.AllReferencedDocuments

	'FNamePos is getting the number of spaces that it takes to get to the 
    'very last back slash in the full file name of our document.         
        FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
     
	'We can then take that number (position) and use it to cut off all of the 
    'file path that we don't need. In this case, it's the front of the path
    'that we're getting rid of, leaving us with just the file name.
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        'Let's make sure that we can even change this part. If we can, then we'll continue. 
        If docFile.IsModifiable = True Then
            
            'Because you can only grab the occurrences from an assembly document
            'we need to fill up that empty AssemblyDocument container with an object
            'that we know is definitely an assembly document. Because that was one
            'of the first checks we made up there on this open document, we can safely
            'declare that assemblyDoc (Which is an AssemblyDocument) is equal to 
            ' openDoc (Which is just a regular old Document)             
            assemblyDoc = openDoc        
            
            'While we're at it, let's go on and define the empty ComponentDefinition container
            '(we named ours assemblyDef) with some sort of content. 
            assemblyDef = assemblyDoc.ComponentDefinition
            
            'Now we need to collect every instance of the document against
            'our open assembly and put them all inside of partQty. 
            partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
            
                'Now that we have our collection of instances, we need to populate
                'our target iproperty with the total amount. 
                
                'Instead of just throwing that amount in there, let's make sure that
                'the value inside of the target iProperty isn't already equal to our count. 
                'If it is equal, then we don't have to change anything (which saves us time!),
                'but if it isn't equal then we will need to change it. 
                
                'The Try statement is here because of the next if statement ---
               
                'If we just compare the two values, there is a small chance that our target
                'iProperty is already set to something that is NOT a number, which would create
                'an error (as you can't compare numbers against things that aren't numbers). 
                'So, we TRY to complete that if statement, and if there is an error (The CATCH)
                'we just force that target to equal our part qty total. 
                Try
						If partQty.Count <>  iProperties.Value(docFName, "Custom", customPropertyName) Then                
						iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                    End If                      
                    Catch
					iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                End Try
        End If
    Next
'29/01/2016
'I added the following to create the value for the GA
'Some code automation in the Detailing environment was
'failing because it could not find a valid entry.
'This is a dummy field, and does not contribute to the rest of the inteligence of the rule.
			Try
				oASSYParam= iProperties.Value("Custom",customPropertyName)
              Catch
				iProperties.Value("Custom",customPropertyName) = "1"
					End Try
iLogicVb.UpdateWhenDone = True 
MessageBox.Show("Completed" & vbNewLine & ":-)", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub

Sub oProject
	oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
	iProperties.Value("Project", "Project")=oProj
	Main ()
End Sub

I will upload the file as well, just in case there is a copy and paste problem. (I had to change the file extension of the attachment. change it from a ".txt" to a ".iLogicVB"

 

Let me know how it goes.

 

 

Reg
2024.2
Please Accept as a solution / Kudos
Message 12 of 12
Anonymous
in reply to: rhasell

Dear Rhasell, 

 

Thank you very much, I only tested it with parts for manufacturing and not for pushased items but this code works perfectly.

 

Again this helps us a lot.

 

Kind regards

 

Dries

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report