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: 

Sort BOM while avoiding locked parts

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
VGonsalves
1187 Views, 7 Replies

Sort BOM while avoiding locked parts

Hi

 

I need to sort the BOM (structured) while avoiding three parts. So I attempted manually locking the three parts in the BOM through the user interface and then running the following code

 

 

' Set a reference to the assembly document. ' This assumes an assembly document is active. Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument

' Set a reference to the BOM Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM

' Make sure that the structured view is enabled. 'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView oBOMView = oBOM.BOMViews.Item("Structured")

'The following line works correctly Call oBOMView.Sort("Part Number",True) 'Re-Number the BOM Call oBOMView.Renumber(3, 1) 'Re-Sort Items 'Call oBOMView.Sort("Item",True)

 

The above code is bits and pieces that I have combined from the internet. The only problem with it is that sort works fine on some files while on others it skips a few e.g. 1,2,5,6,7......

 

Is there any way we can sort the BOM while avoiding all the locked parts.

 

Can anyone please help me

 

Thanks

7 REPLIES 7
Message 2 of 8
adam.nagy
in reply to: VGonsalves

Hi,

 

It may be useful to provide some very minimal, non-confidential sample documents that can be used to reproduce the behaviour.

Also point out what exact order you'd want to get in the end in case of that sample assembly BOM.

 

I'm also wondering if all this is just an intermediate step - i.e. e.g. you are trying to export the list somewhere in the end?

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 8
VGonsalves
in reply to: adam.nagy

Hi Adam

 

I have created a dummy file to explain the condition.

 

Since we need the Grid part and the two verticals to have specific BOM item number the only way I thought I could do it is by going to the BOM and setting these values and then locking them. Now I need to sort the parts based on their "Part Numbers". Renumber only those parts which are not locked. Then re-sort the whole BOM based on Item.

 

So now that I have explained the problem. I wanted to resolve this by being able to select the three parts that need fixed Item numbers before running the rule. With end result being the Base item being item "0", the left most vertical being item "1" and the next one being item "2". And then all the other items get sorted as mentioned above.

 

Hope this gives you an idea of the situation.

 

Thanks

Message 4 of 8
adam.nagy
in reply to: VGonsalves

Hi,

 

I think I understand what the problem is. 

The locked items won't be skipped during renumbering, but simply no value will be assigned to them.

I.e. if you say Renumber(3,1) and the first item in the sorted list is locked, then 3 will not be assigned to it and then the second item (if it's not locked) will get the next value in row, i.e. 4  ... etc

So in the end 3 will not be used at all.

 

If you want to skip the locked items, then pass a BOMRow list to Renumber() that does not include those

Dim app As Inventor.Application = 
  Marshal.GetActiveObject("Inventor.Application")
Dim doc As Inventor.AssemblyDocument = 
  app.ActiveDocument 
Dim bom As Inventor.BOM = 
  doc.ComponentDefinition.BOM

bom.StructuredViewEnabled = True 
Dim bomView As Inventor.BOMView = bom.BOMViews("Structured")
  
' Find rows which are not locked.
' You could also search for them based on e.g. "Part Number"
Dim rows As Inventor.ObjectCollection = 
  app.TransientObjects.CreateObjectCollection()
 
For Each row As Inventor.BOMRow In bomView.BOMRows 
  If Not row.ItemNumberLocked Then
    rows.Add(row) 
  End If
Next

bomView.Sort("Part Number")
bomView.Renumber(3, 1, rows)  

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 8
VGonsalves
in reply to: adam.nagy

Thanks Adam

 

This looks promising. Just to bring to your notice I am using iLogic and not VBA. I tried the code and I got the following error

 

"Error on Line 1 : Expression expected.

Error on Line 2 : Name 'Marshal' is not declared.

Error on Line 3 : Expression expected.

Error on Line 4 : Name 'app' is not declared.

Error on Line 5 : Expression expected.

Error on Line 6 : Name 'doc' is not declared.

Error on Line 8 : Reference to a non-shared member requires an object reference.

Error on Line 9 : Reference to a non-shared member requires an object reference.

Error on Line 13 : Expression expected.

Error on Line 14 : Name 'app' is not declared.

Error on Line 18 : Reference to a non-shared member requires an object reference.

Error on Line 23 : 'rows' is a type and cannot be used as an expression."

 

Could you please assist me with this.

 

Thank you

Message 6 of 8
VGonsalves
in reply to: adam.nagy

Hi Adam

 

Thank you for the code. Sorry about the earlier reply. Your code does work. I made the following change and it works just great now

 

Dim app As Inventor.Application = ThisApplication Dim doc As Inventor.AssemblyDocument = app.ActiveDocument Dim bom As Inventor.BOM = doc.ComponentDefinition.BOM

bom.StructuredViewEnabled = True Dim bomView As Inventor.BOMView = bom.BOMViews("Structured")   ' Find rows which are not locked. ' You could also search for them based on e.g. "Part Number" Dim rows As Inventor.ObjectCollection = app.TransientObjects.CreateObjectCollection()   For Each row As Inventor.BOMRow In bomView.BOMRows   If Not row.ItemNumberLocked Then     rows.Add(row)   End If Next

bomView.Sort("Part Number") bomView.Renumber(3, 1, rows)

 

Now onto the next stage where I can select the parts prior to starting the iLogic command and hence auto set the lock and item numbers.

 

Any suggestions.

 

Thank you

Message 7 of 8
Anonymous
in reply to: VGonsalves

Hi vishgon

 

I know I am a bit behind, but how do you lock a part number on the BOM?

Message 8 of 8
VGonsalves
in reply to: VGonsalves

Andrew
Since we have a specific need to lock certain items in the BOM, we do it manually in BOM in the assembly. I have not tried locking items using iLogic. Hope this helps
Vishal

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report