Skip to content

Instantly share code, notes, and snippets.

@AmenJlili
Created December 8, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmenJlili/1cf3fae21ebe419bdd0fc39f826252c5 to your computer and use it in GitHub Desktop.
Save AmenJlili/1cf3fae21ebe419bdd0fc39f826252c5 to your computer and use it in GitHub Desktop.
SaveAsSWLatestAndRefreshThumbnails
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Sub Main()
Set swApp = Application.SldWorks
Dim FolderLocation As String
FolderLocation = "C:\Users\jlili\Desktop\DXF Assembly"
Dim FileSystemObject As Object
Dim Folder As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set Folder = FileSystemObject.GetFolder(FolderLocation)
For Each file In Folder.Files
If EndsWith(file.Name, "sldprt") Then
'process part
Set swModel = swApp.OpenDoc(file.Name, SwConst.swDocumentTypes_e.swDocPART)
swModel.Visible = True
RefreshToIsometric swModel
swModel.Save
swApp.QuitDoc swModel.GetTitle
ElseIf EndsWith(file.Name, "sldasm") Then
'process assembly
Set swModel = swApp.OpenDoc(file.Name, SwConst.swDocumentTypes_e.swDocASSEMBLY)
swModel.Visible = True
RefreshToIsometric swModel
swModel.Save
swApp.QuitDoc swModel.GetTitle
End If
Set swModel = Nothing
Next file
End Sub
Sub RefreshToIsometric(ByRef swModel As ModelDoc2)
swModel.ShowNamedView2 "*Isometric", -1
swModel.ViewZoomtofit2
End Sub
Public Function EndsWith(str As String, ending As String) As Boolean
Dim endingLen As Integer
endingLen = Len(ending)
EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment