Is active file .sldprt or .sldasm? Yes->run 'Save', No->run 'Save' and 'Save as PDF macro'
'Save as PDF macro'
Take current file location (ex: X:\Design\Test\5884.SLDDRW). Test if new location exists (ex: X:\Production\PDF\Test\5884.SLDDRW). If No->Create Folder, If Yes->Use new folder location. (This would be nice, but not necessary)
Run 'Save as PDF', Add "-REV" to PDF name (where "REV" = Revision Level from Drawing Custom Property), all pages saved into one document, overwrite if existing. It would be nice to have previous revisions moved into an Archive folder stored within the directory (ex: X:\Production\PDF\Test\ARCHIVE\5884-A.pdf). This archive would need to be created if not existing already.
I'd love to learn how to do this, but the sample code I've found on the SolidWorks forums isn't intuitive to me. If there's any way the code could be notated to describe what is going on so that I can make changes in the future, I would be eternally grateful. Thanks.
Below is the code I'm working with right now. It works, but it saves all file types, and it puts them in the same location.
Code: Select all
Option Explicit
Dim swApp As Object
Dim Part As Object
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtention As String
Dim NewFilePath As String
Dim Rev As String
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
FilePath = Part.GetPathName
PathSize = Strings.Len(FilePath)
Rev = Part.CustomInfo("Revision") ' Change Custom Property Here
PathNoExtention = Strings.Left(FilePath, PathSize - 7)
NewFilePath = PathNoExtention & "-" & Rev
Part.SaveAs2 NewFilePath & ".PDF", 0, True, False
End Sub