Part Quantities Per Assembly

Part Quantities Per Assembly

andrewdroth
Advisor Advisor
6,865 Views
27 Replies
Message 1 of 28

Part Quantities Per Assembly

andrewdroth
Advisor
Advisor

Hey all,

 

We have a client that has requested that our shop drawings follow a standard that is slightly different from the one we're familiar with.

 

Each part file for the project will get it's own drawing and special qty field.

 

The QTY field will list the number of instances per assembly, and the total number per project. I think this will look something like this.

 

A1001(6), A1007(2), A1015(3)

TOTAL QTY: 11

 

My intention it to run an iLogic code from the top level assembly that dives down and adds the QTY's for each part as a custom iProperty that can then be linked in the drawing.

 

I found this bit of code here that is close to what I would need, but doesn't differentiate sub assembly quantities.

http://forums.autodesk.com/t5/inventor-forum/multiple-sub-assemblies-in-a-parts-list/td-p/4342872

 

 

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

 

Any tips on how to concatenate the per assembly quantities into one field?

 

Thanks in advance!


Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes
Accepted solutions (1)
6,866 Views
27 Replies
Replies (27)
Message 21 of 28

andrewdroth
Advisor
Advisor

Wow Man!

 

This worked perfectly.

 

Thank you so much!

 

 


Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
Message 22 of 28

Anonymous
Not applicable

I don't know everything about illogic and visual basic. I know that the set command is a Visual Basic command. So I removed those and I am left with the following errors

Rule Compile Errors in Total Parts -Assy to Assy, in 178150 TOP ASSEMBLY.iam

Error on Line 1 : Statement is not valid in a namespace.

Error on Line 95 : Type of 'j' is ambiguous because the loop bounds and the step clause do not convert to the same

 

Very close I can tell

 

Thanks

 

0 Likes
Message 23 of 28

Anonymous
Not applicable

Removed the first line

and added

Dim j as integer

 

it worked. 

Thanks.

0 Likes
Message 24 of 28

Anonymous
Not applicable

Hi

 

I used these rule and its great. One question is there a way for these rule to add information to part and subassemblys like number and quantity.Exsample below.

 

Assembly Name - Number in Assembly - Quantity in Assembly.

 

exsample

 

Landing 1, Number-3, Quantity-114

 

0 Likes
Message 25 of 28

Anonymous
Not applicable

Also how to make it identify parts and assemblys by part number?

0 Likes
Message 26 of 28

info
Contributor
Contributor

Hey

 

Great tool.

But I still have a challenge. Is it possible to mention the total numbers on the ipt:

Now count the numbers per subassembly are not added in the highest subassembly

 

See example:

Now:

501298CC (mainassembly)

                518111CC(subassembly)

                                518327CC(10), 518340CC(10), 518356CC(3 X 8), (subassembly`s)

                518112CC

                               518329CC(8), 518341CC(8), 518401CC(3 X 8) (subassembly`s)

I would like:

 

501298CC (mainassembly)

                518111CC(44) (subassembly)

                518112CC(40) (subassembly)

 

_AncestryStr

518111CC(44*) 518112CC(40*)

 

Or:

_AncestryStr

518111CC(44*) >518327CC(10*), 518340CC(10*), 518356CC(3 X 8*)<, 518112CC(40*)   >518329CC(8*), 518341CC(8*), 518401CC(3 X 8*)<

0 Likes
Message 27 of 28

andrewdroth
Advisor
Advisor

@MechMachineMan, I realize it's been a long time since you looked at this, but we still use it regularly and it is awesome.

 

I have a question for you though. Do you know why it might get hung up on purchased components? It's not a big deal because I can witch them to normal and then run the rule, but if I could figure it out it would be a real timesaver!

 

see the attached screencast.

 

Let me know, and thanks again!

 

 


Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes
Message 28 of 28

tecnico
Contributor
Contributor

Hi, is it possible to have a code that inserts the quantity obtained from the super-assembly into the Authority field? updated as the one written in 2017 is no longer supported by the software, I need it to be able to write the total quantity of the same piece in the 2D table, I don't know if it is possible to include the fact that this has a mirror, it seems to me still science fiction but maybe some of you can help me.

0 Likes