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

(Not an Autodesk Employee)