AnsweredAssumed Answered

API Flat Pattern ModifyDefinition bugging out when executed from Assembly

Question asked by Brian Smith on Mar 3, 2017
Latest reply on Mar 3, 2017 by Raghvendra Bhargava

The below macro is extracted from a larger macro, but I tried to extract the basic structure that is causing issues. The below code runs and it completes the desired actions (turning off merge faces from the flat pattern feature). The problem or buggy nature is that it after it completes, you cannot click on or highlight ANYTHING in the feature tree. It is stuck in a weird state what you can double click on a feature (or part) and expand it but you cannot highlight or right click it. Weirder, after it runs if you open a part (by right clicking in the model view) and close the part it allows you to select normally in the feature tree.


I am completely at a loss at what the problem is. I imagine it is maybe because I am editing the flat pattern feature when it is suppressed? Maybe because it is executing from a top level assembly? Any help is appreciated.




Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim SwAssembly As SldWorks.AssemblyDoc

    Dim SwComponent As SldWorks.Component2

    Dim swConf As SldWorks.Configuration

    Dim boolstatus As Boolean

    Dim i As Long

    Dim swModel As SldWorks.ModelDoc2

    Dim swFlatPattern As SldWorks.FlatPatternFeatureData

    Dim swFeatMgr As SldWorks.FeatureManager

    Dim vChildComp As Variant

    Dim swChildComp As SldWorks.Component2

    Dim swFeat As SldWorks.Feature


    Set swApp = Application.SldWorks

    Set SwAssembly = swApp.ActiveDoc

    Set swConf = SwAssembly.GetActiveConfiguration

    Set SwComponent = swConf.GetRootComponent3(True)

    vChildComp = SwComponent.GetChildren


    For i = 0 To UBound(vChildComp)

        Set swChildComp = vChildComp(i)

        Set swModel = swChildComp.GetModelDoc2

        Set swFeatMgr = swModel.FeatureManager

        Set swFeat = swModel.FirstFeature

        While Not swFeat Is Nothing

            If swFeat.GetTypeName2() = "FlatPattern" Then

                Set swFlatPattern = swFeat.GetDefinition

                swFlatPattern.AccessSelections swModel, Nothing

                swFlatPattern.MergeFace = False 'Turns off Merge Face Option in flat pattern feature

                swFeat.ModifyDefinition swFlatPattern, swModel, Nothing

                boolstatus = swFeatMgr.EditRollback(swMoveRollbackBarToAfterFeature, swFeat.Name)  'Required or assembly says it is in a roll back state.

            End If

            Set swFeat = swFeat.GetNextFeature


    Next i

End Sub