Created
December 8, 2022 20:12
-
-
Save AmenJlili/1cf3fae21ebe419bdd0fc39f826252c5 to your computer and use it in GitHub Desktop.
SaveAsSWLatestAndRefreshThumbnails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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