Error with oBOM.BOMViews.Item("Structured")

Error with oBOM.BOMViews.Item("Structured")

Alivibro
Explorer Explorer
1,320 Views
1 Reply
Message 1 of 2

Error with oBOM.BOMViews.Item("Structured")

Alivibro
Explorer
Explorer

I'm using Inventor 2019 with ILogic.  This code has one error in the last line

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
    
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False

' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True

' Set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")

 

and the error is:

 

System.ArgumentException: Parametro non corretto. (Eccezione da HRESULT: 0x80070057 (E_INVALIDARG))
   in System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   in Inventor.BOMViews.get_Item(Object Index)
   in ThisRule.Main()
   in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

How can I solve the problem?

 

Thanks, Luca

Accepted solutions (1)
1,321 Views
1 Reply
Reply (1)
Message 2 of 2

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, in what language are you using Inventor?
This access error is generally displayed when you have an inventor installed in another language, here I leave you a code that captures the name regardless of the language. I have placed a dialog box with the name for each BomView so you can check it.

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
    
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False

' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True

Dim oBVList As New ArrayList
For Each item As BOMView In oBOM.BOMViews
	oBVList.Add(item.Name)
	MessageBox.Show(item.Name)
Next

Dim BomStructName As String= oBVList(1)

' Set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item(BomStructName)

 The New ArrayList starts counting from number 0, that's why zero will be unnarmed and 1 will represent structured. Once you have found the correct name you can put your name and delete the part of the code that I have passed you. In updated inventor versions you can put an integer for the bomview, such as
oStructuredBOMView = oBOM.BOMViews.Item (2)
But in this case keep in mind that it starts counting from 1 and not from zero as in the new arraylist
In old inventor versions this could not be done

Hope this helps with your problem. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn