Message 1 of 3
Switching beween Edit Member Scope & Factory Scope programatically via VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I am trying to cycle through all referenced documents in an assembly and toggle between edit member scope and factory scope, the code works if there is no model state other than the default primary, but if any of the referenced documents has an existing modelstate , regardless of it being active or not, the code fails at the method :
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oPartDoc As PartDocument
Dim oPartCompDef As PartComponentDefinition
Dim oAssDoc As AssemblyDocument
Dim oAssCompDef As AssemblyComponentDefinition
If CommandButton1.Caption = "Set All to Edit Member Scope" Then
CommandButton1.Caption = "Set All to Edit Factory Scope"
Mode = "MS"
Else
CommandButton1.Caption = "Set All to Edit Member Scope"
Mode = "FS"
End If
' Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
Debug.Print oRefDoc.DisplayName
If oRefDoc.DocumentType = kPartDocumentObject Then
Set oPartDoc = oRefDoc
Set oPartCompDef = oPartDoc.ComponentDefinition
If Mode = "MS" Then
Debug.Print oPartCompDef.ModelStates.ActiveModelState.Name
oPartCompDef.ModelStates.MemberEditScope = kEditActiveMember
Else
oPartCompDef.ModelStates.MemberEditScope = kEditAllMembers
End If
End If
If oRefDoc.DocumentType = kAssemblyDocumentObject Then
Set oAssDoc = oRefDoc
Set oAssCompDef = oAssDoc.ComponentDefinition
If Mode = "MS" Then
oAssCompDef.ModelStates.MemberEditScope = kEditActiveMember
Else
oAssCompDef.ModelStates.MemberEditScope = kEditAllMembers
End If
End If
Debug.Print oRefDoc.DisplayName
Next
any idea of what might be the cause, I have also tried to use a factory document where the referenced document has more than one model state, and that doesn't even support setting the model states to "all members" or "member only", so any clue as to how might can this be approached would be greatly appreciated.
Best
Ali