Model States and BOMstructure

Model States and BOMstructure

MD_
Contributor Contributor
186 Views
3 Replies
Message 1 of 4

Model States and BOMstructure

MD_
Contributor
Contributor

Hello, 

 

Can the BOMstructure be changed of an assembly containing more than the default Model State?

I can change this in the active document but not the child-assemblies like in the example below

Following code always throws errors in iLogic (Inventor 2024):

 

Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAssyDoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ' = .iam
		If oRefDoc.ComponentDefinition.ModelStates.Count > 1 Then
			oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
		End If
	End If
Next

 

0 Likes
Accepted solutions (1)
187 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @MD_.  Yes, I believe so.  But you may be encountering a 'ModelState member' Document, which it may not allow edits to.  If that is the case, then you would have to get the 'Factory' version of that Document first, then make changes to that, or force the Document reference you have to become the 'Factory' version, by activating the ModelState that is controlling it.  But attempting to activate the ModelState of a background referenced document that is not visibly showing may throw an error.  There is also the 'MemberEditScope' to keep in mind, which dictates if the changes will be made to only the 'active' ModelState version, to all ModelState versions, or other scenario in newer versions of Inventor.  Take a look at the following, slightly modified version of your code, as an example you could try out, or modify even further.  Whenever some of the referenced documents in assemblies have multiple ModelStates, that does seem to complicate doing things to them by code quite a bit.

'make sure our rule is working with 'FactoryDocument' if it has multiple ModelStates
Dim oAssyDoc As AssemblyDocument = TryCast(ThisDoc.FactoryDocument, AssemblyDocument)
'if current document was not an Assembly, it will be Nothing
If oAssyDoc Is Nothing Then Return
For Each oRefDoc As Document In oAssyDoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ' = .iam
		'creating the AssemblyDocument variable enables Intellisense recognition of later properties
		Dim oRefADoc As AssemblyDocument = oRefDoc
		'might need to check or record name of controlling ModelState (if any)
		Dim sMSName As String = oRefADoc.ModelStateName
		'get 'Factory' version, if there is one (only version we can edit)
		If oRefADoc.ComponentDefinition.IsModelStateMember Then
			oRefADoc = oRefADoc.ComponentDefinition.FactoryDocument
		End If
		'update the referenced document, if it is needed (sometimes necessary)
		If oRefADoc.RequiresUpdate Then oRefADoc.Update2(True)
		'get its ModelStates (if it has any - none in iPart/iAssembly)
		Dim oMSs As ModelStates = oRefADoc.ComponentDefinition.ModelStates
		If oMSs.Count > 1 Then
			'may want to set MemberEditScope, to control area of effect
			oMSs.MemberEditScope = MemberEditScopeEnum.kEditAllMembers
			'oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
			oRefADoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
			'oRefADoc.Update2(True) this may not be necessary
		End If
	End If
Next 'oRefDoc
oAssyDoc.Update2(True)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

WCrihfield
Mentor
Mentor

Oops. Wrong forum topic. Delete this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

MD_
Contributor
Contributor

Thank you for the clear explanation !

0 Likes