Update a Simplify Substitute

Update a Simplify Substitute

gaetan.lucas
Contributor Contributor
447 Views
1 Reply
Message 1 of 2

Update a Simplify Substitute

gaetan.lucas
Contributor
Contributor

Hello,

 

I would creat a code to update a simplify Substitute as here (chapter "To Edit a Simplify Substitute")

but I can't code the action "Edit Simplified Assembly":

Sub ActualiseSubstitute()
    ' Set a reference to the active assembly document
Dim oDoc As AssemblyDocument
Dim oDef As AssemblyComponentDefinition
Dim oModelStates As ModelStates
Dim oModelState As ModelState
Dim oSubstitute() As String
Dim i As Long
Dim MyModelState As ModelState
Dim AssName As String

    Set oDoc = ThisApplication.ActiveDocument
    Set oDef = oDoc.ComponentDefinition
    Set oModelStates = oDef.ModelStates
    
    'Active Master state
    If oModelStates.ActiveModelState.Name <> oModelStates.Item(1).Name Then
        Set MyModelState = oModelStates.Item(1)
        MyModelState.Activate
    End If
    AssName = oDoc.DisplayName
    
    
    'for future if i want have the choice
    i = 1
    For Each oModelState In oModelStates
        If oModelState.ModelStateType = kSubstituteModelStateType Then
            ReDim Preserve oSubstitute(1 To i)
            oSubstitute(i) = oModelState.Name
            i = i + 1
        End If
    Next
    
Dim MyOccName As String

Dim oCompOccSympl As ComponentOccurrence
Dim oCompOccAssSympl As ComponentOccurrence
    
    Set oDoc = ThisApplication.ActiveDocument
    Set oDef = oDoc.ComponentDefinition
    Set oModelStates = oDef.ModelStates
    
    'Active the first Substitute
    If oModelStates.ActiveModelState.Name <> oModelStates.Item(oSubstitute(1)).Name Then
        Set MyModelState = oModelStates.Item(oSubstitute(1))
        MyModelState.Activate
    End If
    MyOccName = MyModelState.Name
    
    'Edit the first Substitute
    Set oDoc = ThisApplication.ActiveDocument
    Set oDef = oDoc.ComponentDefinition
    Set oCompOccSympl = oDef.Occurrences.ItemByName(MyOccName & ":1")
    oCompOccSympl.Edit
    
    'Edit Simplified Assembly
Dim oSimplDoc As PartDocument
Dim oSimplDef As PartComponentDefinition
Dim oShrinkComp As ShrinkwrapComponent
    Set oSimplDoc = ThisApplication.ActiveEditDocument
    Set oSimplDef = oSimplDoc.ComponentDefinition
    Set oShrinkComp = oSimplDef.ReferenceComponents.ShrinkwrapComponents.Item(1)
   
End Sub

Could you help me ?

0 Likes
448 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @gaetan.lucas.  I haven't really used Simplified/Shrinkwrap Assemblies as ModelStates before, but after reading down through your code, and looking at the online documentation for the associated API objects/methods/properties involved, I am making a relatively educated guess that in order for you to 'update' that ShrinkwrapComopnent, you may need to access its ShrinkwrapComponent.Definition (a ShrinkwrapDefinition), then try changing one or more of its Propertys, and maybe change them back if no changes are were actually needed, then see if that causes the 'update' to happen.  If some of those properties actually need to change, do so.  That is similar to 'editing' it through the dialog, but by code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes