Reload Model Example (VBA)
This example shows how to reload the active model with the last saved
version of the model.
'----------------------------------
'
' Preconditions: Part or assembly document is open.
'
' Postconditions: Active part or assembly model is replaced
with last saved model.
'
' NOTE: Any changes made to the model in the current session
are discarded,
' if
they were not saved previous to running this code.
'
'-----------------------------------
Option Explicit
Public Enum swComponentReloadError_e
swReloadOkay
= 0
swWriteAccessError
= 1
swFutureVersionError
= 2
swModifiedNotReloadedError
= 3
swInvalidOption
= 4
swFileNotSavedError
= 5
swInvalidComponentError
= 6
swUnexpectedError
= 7
swComponentLightWeightError
= 8
swFileDoesntExistError
= 9
swFileInvalidOrSameNameError
= 10
swDocumentHasNoView
= 11
swDocumentAlreadyOpenedError
= 12
End Enum
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
nRetVal As
Long
Set
swApp = CreateObject("SldWorks.Application")
Set
swModel = swApp.ActiveDoc
'
Fails for drawings because functionality is not supported in user interface
nRetVal
= swModel.ReloadOrReplace(False,
swModel.GetPathName, True)
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" ReloadOrReplace
= " & nRetVal
End Sub