' This code is off the SW website ...
'-----------------------------------
' How to playback a model
'
' Problem:
' For a complicated part/assy, it is often very instructive
' to proceed, step by step, through the history tree.
' This shows each step of how the model was developed and
' can give insight into the design intent of the user.
'
' This sample code shows how to step through the history
' tree of a model by rolling back to each feature in
' reverse sequence. As each feature is played back, it
' is highlighted in the graphics window.
'
' Preconditions:
' 1) a part or assy is open
'
' Postconditions:
' none
'
' Notes:
' 1) delay between steps is set at 1 second
'
' Further Work:
' 1) zoom to each feature:
' Part/AssemblyDoc::FeatureByName
'
' Feature::GetBox
' ModelDoc2::ViewZoomTo2
' or
' Feature::Select2
' ModelDoc2::ViewZoomToSelection
'
' probably also require some view manipulation...
Option Explicit
Public Enum swDocumentTypes_e
swDocNONE = 0 ' Used to be TYPE_NONE
swDocPART = 1 ' Used to be TYPE_PART
swDocASSEMBLY = 2 ' Used to be TYPE_ASSEMBLY
swDocDRAWING = 3 ' Used to be TYPE_DRAWING
swDocSDM = 4 ' Solid data manager.
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 = CreateObject("SldWorks.Application"

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 will over allocate array by one,
' so remove last (empty) entry
ReDim Preserve sFeatName(UBound(sFeatName) - 1)
' now playback each feature in the FMT
For i = 0 To UBound(sFeatName)
Debug.Print sFeatName(i)
bRet = swFeatMgr.EditRollback(swMoveRollbackBarToAfterFeature, sFeatName(i))
' do not assert since may be trying to rollback/forward
' to a feature which cannot be rolled back/forward to
' eg Lighting or Annotations folder
'Debug.Assert bRet
' will 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 we have successfully rolled back
If True = bRet Then
sNow = Timer
While sNow + DELAY > Timer
' need to allow SW to refresh screen
DoEvents
Wend
End If
Next i
' remove highlight from last feature
swModel.GraphicsRedraw2
End Sub
'-----------------------------------