Hide Table of Contents

Roll Back Model Example (VBA)

This example shows how to step through the FeatureManager design tree of a model by rolling back to each feature in reverse sequence. Running an example like this can provide insight into the design intent of the user.

'-----------------------------------

'

' Preconditions: Part or assembly is open.

'

' Postconditions: None

'

' NOTES: The delay between steps is set to 1 second.

'

'-----------------------------------

Option Explicit

Public Enum swDocumentTypes_e

    swDocNONE = 0       

    swDocPART = 1       

    swDocASSEMBLY = 2   

    swDocDRAWING = 3    

End Enum

Public Enum swMoveRollbackBarTo_e

    swMoveRollbackBarToEnd = 1

    swMoveRollbackBarToPreviousPosition = 2

    swMoveRollbackBarToBeforeFeature = 3

    swMoveRollbackBarToAfterFeature = 4

End Enum

Sub main()

    ' Delay in seconds

    Const DELAY                     As Single = 1#

    

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swPart                      As SldWorks.PartDoc

    Dim swAssy                      As SldWorks.AssemblyDoc

    Dim swFeatMgr                   As SldWorks.FeatureManager

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swFeat                      As SldWorks.feature

    Dim vFeatFace                   As Variant

    Dim swFace                      As SldWorks.face2

    Dim sFeatName()                 As String

    Dim sNow                        As Single

    Dim nDocType                    As Long

    Dim i                           As Long

    Dim j                           As Long

    Dim bRet                        As Boolean

    

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swFeatMgr = swModel.FeatureManager

    Set swFeat = swModel.FirstFeature

    

    nDocType = swModel.GetType

    Select Case nDocType

        Case swDocPART

            Set swPart = swModel

    

        Case swDocASSEMBLY

            Set swAssy = swModel

    End Select

    

    

    ReDim sFeatName(0)

    

    Do While Not swFeat Is Nothing

        sFeatName(UBound(sFeatName)) = swFeat.Name

        

        ReDim Preserve sFeatName(UBound(sFeatName) + 1)

    

        Set swFeat = swFeat.GetNextFeature

    Loop

    

    ' Loop over-allocates array by 1, so remove last (empty) entry

    ReDim Preserve sFeatName(UBound(sFeatName) - 1)

    

    

    ' Playback each feature in the FeatureManager design tree

    For i = 0 To UBound(sFeatName)

        Debug.Print sFeatName(i)

        

        bRet = swFeatMgr.EditRollback(swMoveRollbackBarToAfterFeature, sFeatName(i))

        

        ' Do not assert because you may be trying to roll back or roll forward

        ' to a feature that cannot be rolled back or forward to; for example,

        ' the Lighting or Annotations folder

        'Debug.Assert bRet

        

        ' Remove any previous highlights

        swModel.GraphicsRedraw2

        

        

        ' Highlight feature if it has any geometry

        Select Case nDocType

            Case swDocPART

                Set swFeat = swPart.FeatureByName(sFeatName(i))

        

            Case swDocASSEMBLY

                Set swFeat = swAssy.FeatureByName(sFeatName(i))

        End Select

        

        vFeatFace = swFeat.GetFaces

        If Not IsEmpty(vFeatFace) Then

            For j = 0 To UBound(vFeatFace)

                Set swFace = vFeatFace(j)

                

                swFace.Highlight True

            Next j

        End If

        

        

        ' Only pause if rollback is successful

        If bRet Then

            sNow = Timer

            While sNow + DELAY > Timer

                ' Allow SolidWorks to refresh screen

                DoEvents

            Wend

        End If

    Next i

        

    ' Remove highlight from last feature

    swModel.GraphicsRedraw2

End Sub

'-----------------------------------



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Roll Back Model Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2010 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.