How to Get and Change "Default BOM Structure" by iLogic?

How to Get and Change "Default BOM Structure" by iLogic?

ngdnam88
Advocate Advocate
2,608 Views
9 Replies
Message 1 of 10

How to Get and Change "Default BOM Structure" by iLogic?

ngdnam88
Advocate
Advocate

Hello Everyone,

Is there any iLogic Rule can Get and Change "Default BOM Structure" of Active Part/Assembly - They're not in an Assembly!

I tried: BOMStructureEnum.kNormalBOMStructure but its gives the error. Please help me. Thanks!

0 Likes
Accepted solutions (1)
2,609 Views
9 Replies
Replies (9)
Message 2 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @ngdnam88 

Are you saying this doesn't work?

Dim oDoc As Document = ThisApplication.ActiveDocument
oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure

It works fine for me🤔

Message 3 of 10

ngdnam88
Advocate
Advocate

Hi  @JhoelForshav

I don't know why. At now it's working correct!

Thanks you very much!

0 Likes
Message 4 of 10

ngdnam88
Advocate
Advocate

Hi @JhoelForshav 

Thanks for the previous solution. I still have a problem: the first run Inventor, the rule run correctly with this rule (Assembly1 = picture 001),

001.PNG

but when I create a new part the rule can't run and give an error (part1 = picture 002).

002.PNG

Can you help me? Thanks for your time to support!

0 Likes
Message 5 of 10

JhoelForshav
Mentor
Mentor

Hi @ngdnam88 

Can you share the rule that you're trying to run?

0 Likes
Message 6 of 10

ngdnam88
Advocate
Advocate

Hi @JhoelForshav 

It's a simple Code for checking Document before run another Rules,

 

Dim nDOC As Document = ThisApplication.ActiveDocument
MessageBox.Show(nDOC.ComponentDefinition.BOMStructure, "Checking?", MessageBoxButtons.OK, MessageBoxIcon.Information)

0 Likes
Message 7 of 10

JhoelForshav
Mentor
Mentor

@ngdnam88 

That rule really shouldn't fail🤔...

I cannot get it to fail on my machine, but if you have the rule locally in the document maybe try ThisDoc.Document instead?

Also I changed it to return the enum name instead of number if you're more intereseted in the name 🙂

 

'Dim nDOC As Document = ThisApplication.ActiveDocument
Dim nDOC As Document = ThisDoc.Document
MessageBox.Show([Enum].GetName(GetType(Inventor.BOMStructureEnum), nDOC.ComponentDefinition.BOMStructure), "Checking?", MessageBoxButtons.OK, MessageBoxIcon.Information)
0 Likes
Message 8 of 10

ngdnam88
Advocate
Advocate

Hi @JhoelForshav 

My problem with Inventor version 2018 and previous versions. with 2020 it runs correct! Both yours rules code are very good.

Any idea for me? I'm using Inventor 2018.3.8 Updated. Thanks,

 

002-001.PNG

 

The Detail Error:

System.Runtime.InteropServices.COMException (0x80020003): Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 9 of 10

JhoelForshav
Mentor
Mentor

@ngdnam88 

It's difficult for me to figure out the problem as I don't have inventor 2018. But I'm thinking it might have something to do with the document not being saved, if it only fails on new documents?

Maybe try to save document before running the code? 🙂

0 Likes
Message 10 of 10

ngdnam88
Advocate
Advocate

Thanks @JhoelForshav 

It's happened with saved and not saved documents. I'll try to find another way to check the document. Thanks one more time!

0 Likes