'forces rebuild of top assembly and all subassemblies
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim model As SldWorks.ModelDoc2
Dim swModel3D As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swActiveView As SldWorks.View
Dim bRet As Boolean
Dim nErrors As Long
Sub main()
Dim nomFichier As String
Set swApp = Application.SldWorks
Set model = swApp.ActiveDoc
' termine execution if not file is openned
If model Is Nothing Then
End
End If
' if the current file is a drawing, get external references to rebuild thems
If model.GetType = swDocDRAWING Then
Dim extFilesPath As Variant
Dim extFile As Variant
Set swDraw = model
Set swSheet = swDraw.GetCurrentSheet
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Set extFilesPath = New Dictionary
' get external references. Filter list in oder to get only once reference by file
While Not swView Is Nothing
If Not extFilesPath.Exists(swView.GetReferencedModelName) Then
extFilesPath.Add swView.GetReferencedModelName, swView.GetReferencedModelName
End If
Set swView = swView.GetNextView
Wend
For Each extFile In extFilesPath
Debug.Print extFile
swApp.ActivateDoc2 extFile, True, nErrors
Set swModel3D = swApp.ActiveDoc
swModel3D.ForceRebuild3 (False)
'swModel3D.Save
swApp.CloseDoc extFile
Next
swApp.ActivateDoc2 model.GetTitle, True, nErrors
Set model = swApp.ActiveDoc
model.ForceRebuild3 (False)
Else
model.ForceRebuild3 (False)
End If
End Sub