Switching beween Edit Member Scope & Factory Scope programatically via VBA

Switching beween Edit Member Scope & Factory Scope programatically via VBA

3DAli
Collaborator Collaborator
237 Views
2 Replies
Message 1 of 3

Switching beween Edit Member Scope & Factory Scope programatically via VBA

3DAli
Collaborator
Collaborator

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 :

3DAli_0-1697478065609.png

    ' 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 

0 Likes
238 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

have a look at this iLogic code. I expect that it does what you want.

Sub Main()

	Dim doc As AssemblyDocument = ThisDoc.Document
	SetMemberEditScope(doc)

End Sub

Public Sub SetMemberEditScope(doc As Document)

	If (doc.ComponentDefinition.IsModelStateMember) Then
		doc = doc.ComponentDefinition.FactoryDocument
	End If

	Dim modelstates = doc.ComponentDefinition.ModelStates
	modelstates.MemberEditScope = MemberEditScopeEnum.kEditAllMembers

	If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
		For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences
			SetMemberEditScope(occ.Definition.Document)
		Next
	End If
End Sub

You might also consider moving away from VBa, and stop developing in VBa, it's obsolete.

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

Frederick_Law
Mentor
Mentor

There was a post last week.

MemberEditScrope is not available until 2024.

Before that, need to add Windows Environment Variable to turn it on.

Here: https://forums.autodesk.com/t5/inventor-programming-ilogic/update-parameter-using-ilogic-in-all-mode...

0 Likes