- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
Solved! Go to Solution.