Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Doc As SldWorks.ModelDoc2
Const swDocDRAWING = 3
Const swMbWarning = 1
Const swMbInformation = 2
Const swMbOk = 2
Dim BoolStatus As Boolean
Dim LongStatus As Long
Dim e As Long
Dim w As Long
Dim Description As String
Dim Msg As String
Dim DocName As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
If ((Doc Is Nothing) Or (Not (Doc.GetType Eqv swDocDRAWING))) Then
Msg = "A drawing document must be active to use this command!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
Else
Description = Doc.CustomInfo2("", "Description")
DocName = Doc.GetPathName
If (Not (DocName = "")) Then
DocName = Left(DocName, Len(DocName) - 7)
Else
Msg = "Please save drawing before creating pdf!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
End If
If (Not (Description = "")) Then
DocName = DocName & "_" & Description & ".pdf"
Else
DocName = DocName & ".pdf"
'at this point, DocName still has the full path
DocName = Mid(DocName, InStrRev(DocName, "\") + 1)
'now, DocName is just Filename.pdf
End If
Dim TargetLocation As String
'don't forget the trailing "\"
TargetLocation = "c:\temp\"
'also, set the pagesetup to adjust on a sheet by sheet basis
Doc.Extension.UsePageSetup = SwConst.swPageSetupInUse_e.swPageSetupInUse_DrawingSheet
'concatenate the TargetLocation and Filename
'if the TargetLocation does not exist, the call will fail
BoolStatus = Doc.SaveAs4(TargetLocation & DocName, 0, 0, e, w)
If BoolStatus = False Then
Msg = "Failed to save PDF document!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
Else
Msg = "Saved drawing as " & DocName
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End If
End If
Set Doc = Nothing
Set swApp = Nothing
End Sub
[\code]
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...