Error in rule when changing BOM Structure to Phantom

Error in rule when changing BOM Structure to Phantom

caspar.boetchiaerAYLML
Explorer Explorer
350 Views
5 Replies
Message 1 of 6

Error in rule when changing BOM Structure to Phantom

caspar.boetchiaerAYLML
Explorer
Explorer

Hi 

 

As title mentions, I get the following error when changing BOM structure to Phantom.

Referenced and Default(Normal) works just fine.

Can anybody help me?

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.set_BOMStructure(BOMStructureEnum )
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

oCompDef = ThisDoc.Document.ComponentDefinition
Dim CheckValue1 As String = "MC-"

For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
	If oOcc.Visible = True And Not oOcc.Name.Contains(CheckValue1) Then
			oOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
	ElseIf oOcc.Visible = True AndAlso oOcc.Name.Contains(CheckValue1) Then
			oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
			
	Else
		oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next


iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()
RuleParametersOutput()
ThisDoc.Document.Rebuild2

 

 

0 Likes
Accepted solutions (1)
351 Views
5 Replies
Replies (5)
Message 2 of 6

dutt.thakar
Collaborator
Collaborator
Accepted solution

@caspar.boetchiaerAYLML 

 

The Phantom enumerator of BOM is not accessible through the occurrence object. When you access the BOM Structure from Occurrence you can only change between reference and default. Default is the state you have set in your BOM (it could be phantom or purchased etc.). It is similar when you right click on an occurrence in your assembly and set BOM Strucutre, where you only see two options default and reference. If you set phantom to one of your parts and then check again by right clicking you will see, Default (Phantom).

 

You need to iterate through actual BOM of the assembly component definition and construct your logic if you want to access Phantom enumerator. Something like below.

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oBOM As BOM = oDef.BOM
Dim oBView As BOMView = oBOM.BOMViews.Item(1)

For Each oRow As BOMRow In oBView.BOMRows
	oRow.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
Next

I hope this will help you.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 3 of 6

marcin_otręba
Advisor
Advisor

it's because you cant change occurrence bom structure to phantom

 

marcin_otrba_0-1657721460941.png

 

and as far as i undertand you want to change part's bom structure not ocurrences? :

marcin_otrba_1-1657721724572.png

check this thread:

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/change-bom-structure-to-reference-at...

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 4 of 6

caspar.boetchiaerAYLML
Explorer
Explorer
Thanks for the Reply.
The suggestion list, showing on your second picture, how is that turned on?
0 Likes
Message 5 of 6

caspar.boetchiaerAYLML
Explorer
Explorer

Thanks Dutt.

It's actually your code Im adding to.

So its fitting you're the one who gives the solution.

Ended up using another snippet I had in my notes only because it required less changes.

 

Here is final versions which seem to work as intented.

 

oCompDef = ThisDoc.Document.ComponentDefinition


For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
	If oOcc.Visible = True 
			oOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
				
	Else
		oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next

Dim CheckValue1 As String = "MC-"

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	If oOccurrence.Name.Contains(CheckValue1) Then
		'set BOM Structure
		oOccurrence.Definition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure 'Phantom 
	End If
	
Next


iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()
RuleParametersOutput()
ThisDoc.Document.Rebuild2

 

0 Likes
Message 6 of 6

marcin_otręba
Advisor
Advisor

it was from vba not ilogic but you can get it in ilogic as well, but you must write word BOMStructureEnum first:

 

 

marcin_otrba_0-1657789282410.png

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders