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 Structured BOMview

10 REPLIES 10
Reply
Message 1 of 11
Madoid
2310 Views, 10 Replies

Sort Structured BOMview

Hi,

I'm trying to sort a structured BomView trough .Net Api in Inventor 2012.

I'm using Sort method of BOMView object.

I don't get any error but BOM isn't changed after this call.

Any ideas?

 

I've tried :

oBv.Sort("Item") or oBv.Sort("Item", False)

oBv.Sort("Part Number") or oBv.Sort("Part Number", False)

 

Thanks in advance

Tags (1)
10 REPLIES 10
Message 2 of 11
CadUser46
in reply to: Madoid

I just did this the Other day but I'm not at work to give you the code right now. You need to address the tab to be sorted. If no one else replies I will get it tomorrow.

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 3 of 11
CadUser46
in reply to: Madoid

Just thinking off top of head but I think it was something like this.

Dim oBomView as bomview: oBomView = thisapplication.activedocument.bomview("structured")

Call oBomView.sort("column name",false)




Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 4 of 11
Madoid
in reply to: CadUser46

Hi,

thanks for your reply, probably I wasn't so clear.

My problem regards "Sort" method.

I call it properly but seems that it doesn't work.

Have you tried your code with a concrete case?

Thanks in advance

Message 5 of 11
CadUser46
in reply to: Madoid

Hi.  Yea i have this code working fine in 2012.  It in VBA so remove the 'set'.

 

Dim oBOMView As BOMView: Set oBOMView = thisapplication.activedocument.ComponentDefinition.BOM.BOMViews.Item("Structured")
'Call the sort and renumber methods. Sort in ascending order.
Call oBOMView.Sort("column name", True)
Call oBOMView.Renumber(1, 1) 

 

My memory wasnt far off.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 6 of 11
Madoid
in reply to: CadUser46

Hi,

i've tried this code in VBA without getting result.

 

Sub SortBom()
    Dim oBOMView As BOMView
    Dim oBOM As BOM
    Set oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
    oBOM.StructuredViewEnabled = True
    Dim bv As BOMView
    For Each bv In oBOM.BOMViews
        If bv.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
            Set oBOMView = bv
            Exit For
        End If
    Next
    'Call the sort and renumber methods. Sort in ascending order.
    Call oBOMView.Sort("Part Number", False)
  End Sub

 

Probably it doesn't work because of my Italian version?

If I use italian translation of column name, Sort method generates one error.

Thanks in advance

Message 7 of 11
CadUser46
in reply to: Madoid

I think you are making it more difficult than it needs to be.  Did you try my code?  I tried the code as well and it doesnt like the oBOM declaration.

 

Whats the point in looping through the bomviews (of which there are only three, only two of which can be addressed in the api) if you are only sorting one view.  Just address it directly then sort it.

 

Maybe its a language thing.  I did read somewhere the other day about german characters being interpreted differantly.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 8 of 11
Madoid
in reply to: CadUser46

Sorry for this delay.

I tried you code but the result is the same.

I'm even more sure the problem is in Sort method.

In my sample BOM there aren't strange characters.

 

Message 9 of 11
maxstel
in reply to: CadUser46

Sort by BomStructure

My code not working I want sort by bom structure

 

oStructuredBOMView.Sort("BOM structure", True)

Message =  (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

comand  oStructuredBOMView.Sort("Part Number", True)  worked

Thank you

 

 

 

Message 10 of 11
NL-Laurens
in reply to: CadUser46

The code of CadUser46 works indeed.

 

But make sure you don't have the BOM opened on your screen, otherwise the code won't execute on the .sort function

Message 11 of 11
freesbee
in reply to: Madoid

I can confirm it: there is something awkward in the Sort method.

I am trying to sort on Item Number

call oBOMView.Sort("Item", True)

and I do not see any effect in the BOM view (renumbering is another story). I also tried to sort on Part Number

call oBOMView.Sort("Part Number", True)

without seeing any effect.

The method does not fail, but apparently no result is visible (and I'm using inventor in English).

Shall we try to escalate it or can anybody actually sort the BOMView via VBA successfully?

(or maybe the "case is closed" because it is too old??)

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH

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

Post to forums  

Autodesk Design & Make Report