Extract part qty with ilogic

Extract part qty with ilogic

jletcher
Advisor Advisor
6,244 Views
24 Replies
Message 1 of 25

Extract part qty with ilogic

jletcher
Advisor
Advisor

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.

 

Part list.JPG

 

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?

0 Likes
Accepted solutions (1)
6,245 Views
24 Replies
Replies (24)
Message 2 of 25

MegaJerk
Collaborator
Collaborator

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. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 3 of 25

jletcher
Advisor
Advisor

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..

0 Likes
Message 4 of 25

MegaJerk
Collaborator
Collaborator

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!) 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 5 of 25

jletcher
Advisor
Advisor

I tried to run your code and received this error.

 

Error.JPG

0 Likes
Message 6 of 25

MegaJerk
Collaborator
Collaborator

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. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 7 of 25

jletcher
Advisor
Advisor

OK put new code in this is what I get.

 

ER1.JPG

 

ER2.JPG

 

Do I need to do anything to the part file 1st?

0 Likes
Message 8 of 25

jletcher
Advisor
Advisor

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.

0 Likes
Message 9 of 25

MegaJerk
Collaborator
Collaborator

I don't think that you should. I believe that I was just being sloppy. This should work. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 10 of 25

jletcher
Advisor
Advisor

Yep thats it. Ok let me see if everyone like it this way I will let you know.

 

Many thanks to you

 

 

0 Likes
Message 11 of 25

jletcher
Advisor
Advisor

How easy is it to add assembly count also?

0 Likes
Message 12 of 25

MegaJerk
Collaborator
Collaborator

This should do it. 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 13 of 25

jletcher
Advisor
Advisor

Ran got this

 

No2.JPG

NO1.JPG

0 Likes
Message 14 of 25

MegaJerk
Collaborator
Collaborator
Accepted solution

I didn't check it well enough 😞 

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 15 of 25

jletcher
Advisor
Advisor

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...

0 Likes
Message 16 of 25

MegaJerk
Collaborator
Collaborator

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! 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 17 of 25

jletcher
Advisor
Advisor

Sweet nice thanks..

0 Likes
Message 18 of 25

LSA-skan
Advocate
Advocate

Hi Mr. MegaJerk

 

This code is just what i was looking for..!!

 

Thank alot, 1 Kudo coming your way..!

 

/LSA-Skan

0 Likes
Message 19 of 25

LSA-skan
Advocate
Advocate

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.. 🙂

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Also-counting-reference-parts-which-it...

 

/LSA 

0 Likes
Message 20 of 25

Anonymous
Not applicable

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,

0 Likes