Martin Metodiev

Save .JPG with serial

Discussion created by Martin Metodiev on Jun 8, 2019

Hello.
I've written a little macro that lets you save your .jpg files with serial numbers up to 99.
I hope you like it.

 

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim saveFileName As String
Dim nErrors As Long
Dim nWarnings As Long
Dim vnam As String
Dim vbool As Boolean
Dim i As Long

 

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

For i = 1 To 99
   saveFileName = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & "~" & Format(i, "00")
   vnam = Dir(saveFileName & ".jpg")
   If vnam = "" Then
      swModel.Extension.SaveAs saveFileName & ".jpg", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings
      vnam = Left(swModel.GetTitle, Len(swModel.GetTitle) - 7) & "~" & Format(i, "00") & ".jpg"
      vbool = MsgBox(swModel.GetPathName & vbCr & vbCr & "-> " & vnam, vbOKOnly, "Saved As:")
      Exit For
   End If
Next i

End Sub

Outcomes