Ok I will try to make it as clear as mud what I would like to do.
Ok lets say I have an assembly with 20 parts.
I will make a detail drawing of the parts in the assembly.
In the detail part IDW I would like to have the qty needed for the assembly 1,2,4 ect.
So how I think the ilogic should work.
In the detail drawing have a rule named QTY when ran auto or manually Will pompt to pick the Top Level Assembly the parts are in.
The user will look for the top level assembly select it.
The rule would filter out all parts but the detail part number and return the QTY of parts needed for the assembly.
I only need the Qty.
I know this is done by the number of Occurrences in the assembly this I can find but what I can't find is how the user would look up the assembly and set it to parts only.
Like the pic below when doing a parts list.
I don't need the select view because it is a part and it would return QTY of 1 but the assembly may have 5.
Is there a way to do this?
Solved! Go to Solution.
Solved by MegaJerk. Go to Solution.
So you just want a parts list that only shows the QTY of parts used, or perhaps you'd like to show QTY of the part under the detail view of each part. If it's the second case, I would suggest using iLogic in your assembly to get the part qty of each part and write that to an iProperty.
Before I get into code examples though, let's find out more about where you'll be using this part qty info.
Not sure if I want to do it from the assembly. I will have to think if that is the best way. I rather it happen at the Part detail IDW if can. If not then I would have no choice but to do it in the assembly as one of your suggestions.
I would llike to Select top level assembly and return QTY for that part place it as a note or have a box in the IDW title block and when part is placed it fills in the qty. But I will have to tell it what the top level assembly some how.
Reason for not doing it at the Top Level assembly is most parts would be in subs assembly and if we are in a rush we might have to get some units to the floor to be made. And if not in a rush would do the whole floor layout then send it all to the floor..
Does this clear it up for you? If not I will think of a better way to explain..
One of the reasons that I suggested doing it from the top level was because I already have a bit of code banged up that writes the parts QTY (across all assemblies, even subs) into a custom iProperty. If you were to use this code (below) in the top level assembly, it would place the part qty number in the iProperty Authority ( I used authority in this example so you didn’t have to worry about making a new custom iprop in all of your parts).
It is then pretty easy to reference that iProperty across to the drawing. In our case, we have our sheet metal flat pattern views set up to display the iProperty via the Style that we’re using. You could very well do the same for a title block, or the design view that you’re throwing onto the drawing sheet.
This way it keeps your users from having to do extra work that could result in errors or blood loss.
If you could give that a shot, in the meantime, I’ll see about coding out a top level assembly selector in case it doesn’t float your boat.
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.IsModifiable = True Then If docFile.DocumentType = 12290 Then Dim assemblyDoc As AssemblyDocument assemblyDoc = openDoc Dim assemblyDef As AssemblyComponentDefinition assemblyDef = assemblyDoc.ComponentDefinition Dim partDoc As PartDocument partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False) Dim partQty As ComponentOccurrencesEnumerator partQty = assemblyDef.Occurrences.AllReferencedOccurrences(partDoc) 'MessageBox.Show(partQty.Count, "") If IsNumeric(partQty.Count) = True Then If CDblAny(partQty.Count) <> CDblAny(iProperties.Value(docFile.DisplayName, "Project", "Authority")) Then iProperties.Value(docFile.DisplayName, "Project", "Authority") = partQty.Count partDoc.Close Else partDoc.Close End If End If Else Dim docDisplayName As String If docFile.LevelOfDetailName <> "Master" Then docDisplayName = (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3)) 'MessageBox.Show( (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3)) ,"") Else docDisplayName = docFile.DisplayName 'MessageBox.Show(docFile.DisplayName,"") End If If iProperties.Value(docDisplayname, "Project", "Authority") <> "Assembly" Then iProperties.Value( docDisplayName, "Project", "Authority") = "Assembly" End If End If 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 '''Created By: Mega Jerk. - Featuring Non-Commented Code By: Mega Jerk. (Thanks ya big jerk!)
I'm guessing that word wrapping might have messed a few things up. I have attached a text file that should allow you to copy / paste without any problems.
Also I found this, the part with the most QTY in the assembly make the error. I put 3 of 8058-0400-0003 in the assembly then ran your code and it was the name listed in the error if I add more Trans Sidebody opp dis 3.25 -3.25 then it will be listed in the error..
I been trying to understand the code by changing this and that but have not figured it all out yet.
I don't think that you should. I believe that I was just being sloppy. This should work.
This should do it.
I didn't check it well enough 😞
Oh don't worry your darn good at this better than me.
Works great
you in orlando florida look me up I owe you a drink or two...
Even though that counted as solving it, I wanted to post a (slightly) faster bit of code, that actually has comments on it.
Now if you (or others) take a look at the code, it may be helpful in showing you what's happening so that you can better learn from it / use it else where.
I hope that this works out for what you'd like to do.
Thanks for giving it a shot!
Hi Mr. MegaJerk
This code is just what i was looking for..!!
Thank alot, 1 Kudo coming your way..!
/LSA-Skan
Hi all
I found an issue which im discribing in this other thread. Posting here so people in the future hopefully can get this correction on top of this great code.. 🙂
/LSA
This rule works great, but I want to count only the sheet metal parts. Is this possible by adding some additional code?
Thanks in advance,
Can't find what you're looking for? Ask the community or share your knowledge.