I want to use iLogic to:
1.Sort an assembly BOM by Part Number.
2. Renumber Items in the BOM as sorted.
3. Sort a drawing Parts list by item number.
The background to my problem is that i have an assembly which is working beautifully turning components on and off (suppressing/activating in LOD reps) as defined by iLogic rules (iLogic is awesome). The problem is whenever a part is turned on/activated again, it shows up at the bottom of the BOM and Parts list out of order (would be nice if parts went back in the list where they came from). I can do all this manually but I have to do it often and would love to improve efficiency and I sometimes forget when in a hurry.
Any help/code for this would be greatly appreciated.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi ifsi,
You can find an example of how to do this at this link:
http://inventortrenches.blogspot.com/2011/02/ilogic-code-for-parts-lists-title.html
Note that in the example there are three lines as such:
The Renumber and SaveItemOveridesToBOM lines are commented so, you'll want to remove the apostrophe to uncomment them and let those line become active.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com/
That code is working great, but I was curious to see if anyone had any idea as to how to get the parts list to sort by multiple fields instead of just the Part Number. I can't seem to find what the proper API would be for the 2nd level of sorting. Ideally I would like to have the parts list sort by...
1st) "Allocation" - (Allocation will be listed as "loose" or "installed" hardware)
2nd) "Bench" - (Bench will be listed as either "B" or "-")
Hi SpencerPrice33,
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("DESCRIPTION", 1, "QTY", 1)
This results in the parts list sorting first by the DESCRIPTION column and then the QTY column in ascending order. You can use 0 for the sort Boolean to sort by descending order. For example:
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("DESCRIPTION", 0, "QTY", 0)
Great! Thank you so much! I thought I had tried that earlier and it didn't work - must have missed something tiny...
Curtis
Is it possible to sort the BOM while ignoring rows that have their item numbers locked. As an extension to that is it possible to lock the rows for selected item, e.g. select items before running ilogic rule and hence ilogic ignores those items in the BOM
Hello, Curtis,
I need some help. I tried to run your script, but I must not know how to set it up correctly because I can't get it to run. I am new to using scripts/iLogic. Are you availabe as a consultant? We have a need for some scripts and how to access them.
Hi Curtis, thanks for this code. We've been using it for a while now and it works great. we're using the below variation of it. Now we have the need to sort a parts list in little more complicated way: We have "project specific" part numbers that look like 10-1234-xxxxxx and also library parts that look like 00-0000-xxxxxx. We want to sort all the 10-1234 parts by part number and then have all the 00-0000 parts below, sort these by part number and then renumber the whole BoM so it would look something like this:
Item 1: 10-1234-000001
Item 2: 10-1234-000002
Item 3: 10-1234-000003
Item 4: 00-0000-000100
Item 5: 00-0000-000101
I have looked into some custom sorting for Excel but wasn't able to translate this to iLogic. Is there an easy way to do this?
Our code we use right now (that puts the 00-0000 parts on top):
Dim oAsmDoc As AssemblyDocument Dim oAsmCompDef As AssemblyComponentDefinition Dim oBOMView As BOMView oAsmDoc = ThisDoc.Document oAsmCompDef = oAsmDoc.ComponentDefinition oBOMView = oAsmCompDef.BOM.BOMViews.Item("Structured") oBOMView.Sort("Part Number", True) oBOMView.Renumber()
Thanks!
Hi Andreas
Thanks for the code.
I modified it a little bit for my use.
But the ascending / descending part do not work.
No matter if i use 0 / 1 or True / False.
It is always ascending.
Du you know how to make that part work?
SyntaxEditor Code Snippet
Dim oAsmDoc As AssemblyDocument Dim oAsmCompDef As AssemblyComponentDefinition Dim oBOMView As BOMView oAsmDoc = ThisDoc.Document oAsmCompDef = oAsmDoc.ComponentDefinition oBOMView = oAsmCompDef.BOM.BOMViews.Item("Structured") oBOMView.Sort("BOM Structure", 0, "Subject", 1, "Description", 1) oBOMView.Renumber(001) oBOMView = oAsmCompDef.BOM.BOMViews.Item("Parts Only") oBOMView.Sort("BOM Structure", 0, "Subject", 1, "Description", 1) oBOMView.Renumber(001)
King regards
Henrik Graversen
Hi HenrikGraversen,
What version of Inventor are you using?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hello,
Is it also possible to save the sorted and renumbered BOM into the assembly?
As far as I can see, when I manually export the BOM sorting/renumbering is saved but when done by code(VBA/iLogic) it's not.
Same with dragging rows to a certain position, is kept when exporting the BOM and lost when not.
I'm using IV2022.
Something like this should work. Replace oPartsList with whatever variable you're using.
oPartsList.SaveItemOverridesToBOM
Thanks James for your quick reaction,
I mean the BOM in an assembly, not yet the PartsList on a drawing.
As far as I can see is 'SaveItemOverrides' not available for the a BOM, am I correct?
Hi
I'm a little bit late to the party. But this topic is still very relevant since it cannot be defaulted by Inventor itself.
I've been trying to make this code to work for hours, but to no avail. I'm also getting the generic error :
(Exception from HRESULT: 0x80004005 (E_FAIL))
Even ChatGPT isn't helping right now. Does anyone have any idea what i'm doing wrong?
What version of Inventor?
Can you post the code you are running? Maybe with an example drawing? Or screen shot of it?
What line is the error occurring on?
I'm using Inventor 2022.
The error isn't on any specific line. It's giving me this generic error. See attached.
I've tried your original code, as wel as a small modification as this:
Sub Main Dim oDoc As Document oDoc = ThisDoc.Document 'check if Document type is drawing If oDoc.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub Dim oPartsList1 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) 'If oPartsList1 Is Nothing Then Resume Next oPartsList1.Sort("PART NUMBER") 'oPartsList1.Renumber 'oPartsList1.SaveItemOverridesToBOM End Sub
I comment out the " On Error Resume Next" , because nothing happens if i leave that in.
Any idea what goed wrong?
Perhaps you can point me in the right direction.
Thanks in advance for any tips.
Best regards
Charles
Can't find what you're looking for? Ask the community or share your knowledge.