Hi @richterBKSAC. I copied your code from 'Message 19', and altered it. The document type check part may be unnecessary, but usually good practice to include. I also included a lot of comments in there. In general, the 'factory' document is the only version that is Read/Write, while the 'member' versions are ReadOnly, so before we start trying to change or activate anything under a document reference, we need to stop at the document reference, and make sure which one we are working with. What the next step is depends on what your plans are. For instance, if you want to make exactly the same changes to all ModelStates in the file, then the specific document reference you have stored in your variable is not that important. However sometimes you may want to make unique changes to that specific document, that you do not want to make to other specific documents in that file. If the first case is true, you can simply set your document variable to pointing to the factory document, even if that is a different document than you started with. But if the second situation is true, you will want to maintain your specific document reference after this next step. If your original document is not already the factory document, then in order to maintain your reference to the original document, you may need to record which ModelState that original document represents, then get a reference to the factory document, then activate the ModelState that the original document represented, in order to make it become the factory document, then switch back to that original document reference again.
Here is the altered code:
Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim refdocs As DocumentsEnumerator = oDoc.ReferencedDocuments
'stop at getting the referenced document, because we need to make sure it is the Factory document
'if it is not the factory document, we may need to make it the factory document
'because we can only make changes to the factory document, if one exists
'there will only be a factory document when the file has more than one ModelState present
Dim refdoc As Inventor.Document = refdocs.Item(1)
If refdoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
refdoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub 'it is neither an assembly or part
End If
'only parts and assemblies have this property that we can check
If refdoc.ComponentDefinition.IsModelStateMember Then
'if it is not currently the factory, we have two options
'1) switch the value of our document reference 'refdoc' to pointing to the factory document
'2) cause 'refdoc' to be the factory document, by activating the ModelState it represents
'here we get the name of the ModelState that 'refdoc' represents (we already know it is not active)
Dim sMSName As String = refdoc.ModelStateName
'now since we can only make changes to the factory document, we need to get that first
refdoc = refdoc.ComponentDefinition.FactoryDocument
'now we activate that other ModelState, which will shift which document is the factory document
refdoc.ComponentDefinition.ModelStates.Item(sMSName).Activate
'now set 'refdoc' back to that document which represents the active ModelState, and is now the factory document
refdoc = refdoc.ComponentDefinition.FactoryDocument
End If
Dim oModelStates As ModelStates = refdoc.ComponentDefinition.ModelStates
oModelStates.MemberEditScope = MemberEditScopeEnum.kEditAllMembers
Wesley Crihfield

(Not an Autodesk Employee)