Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic to Sort BOM, Renumber and sort Parts list

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
ifsi
11211 Views, 20 Replies

iLogic to Sort BOM, Renumber and sort Parts list

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.

20 REPLIES 20
Message 2 of 21
Curtis_Waguespack
in reply to: ifsi

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:

 

oPartsList1.Sort("PART NUMBER")
'oPartsList1.Renumber
'oPartsList1.SaveItemOverridesToBOM

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/

 

 

Tags (2)
Message 3 of 21
ifsi
in reply to: Curtis_Waguespack

Pure gold! Thank you Curtis

Message 4 of 21
SPrice33
in reply to: ifsi

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

 

 

Message 5 of 21

Hi SpencerPrice33,

 

If you need to sort a parts list by multiple columns you can use something like this:

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)
 


I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Message 6 of 21

Great!  Thank you so much!  I thought I had tried that earlier and it didn't work - must have missed something tiny...

Message 7 of 21

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

Message 8 of 21

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.

Tags (1)
Message 9 of 21
iogurt1
in reply to: Curtis_Waguespack

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!

Message 10 of 21
HenrikGraversen
in reply to: iogurt1

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

Message 11 of 21

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

Message 12 of 21

I have only tried in version 2016 so far.

 

Message 13 of 21

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.

Message 14 of 21
SharkDesign
in reply to: ifsi

Something like this should work. Replace oPartsList with whatever variable you're using. 

 

oPartsList.SaveItemOverridesToBOM

 

  Expert Elite
  Inventor Certified Professional
Message 15 of 21

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?

Message 16 of 21

Not sure, I'm not an iLogic master, but that works for me.
  Expert Elite
  Inventor Certified Professional
Message 17 of 21
Charles_LouwagieBE
in reply to: ifsi

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?

Message 18 of 21

Hi @Charles_LouwagieBE 

 

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?

Message 19 of 21

Hi @Curtis_Waguespack 

 

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.

 

Message 20 of 21

Hi @Curtis_Waguespack 

 

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.

Post to forums  

Autodesk Design & Make Report