Here is the code that I have for a macro that saves a drawing as a PDF. Most of this code has came from a macro that I downloaded somewhere. I am attempting to change it, but I am having problems. Originally Line 25 works great, but it saves the PDF to the directory of the drawing. I don't want that, so I added Lines 20-24 to make up my path. I then added Line 26 and commented out 25. The Macro did not work at all. I need to know why line line 25 works and why line 26 will not. If I debug.print either one of them, they are exactly the same. What am I doing wrong, and how can I make it work the way I want.
1 Public swApp As SldWorks.SldWorks 2 Public DrawingDoc As SldWorks.DrawingDoc 3 Dim ModelDoc As SldWorks.ModelDoc2 4 Dim objWShell As Object 5 Dim strRegKey As String 6 Dim lngWarnings As Long 7 Dim lngErrors As Long 8 Dim strPDFName As String 9 Sub main() 10 Set swApp = Application.SldWorks 11 Set ModelDoc = swApp.ActiveDoc 12 If Not ModelDoc Is Nothing Then 13 If ModelDoc.GetType = swDocDRAWING Then 14 Set DrawingDoc = ModelDoc 15 strRegKey = "HKEY_CURRENT_USER\Software\Bluebeam Software\Pushbutton PDF\SolidWorksLt\WhatToPlot" 16 Set objWShell = CreateObject("WScript.Shell") 17 objWShell.RegWrite strRegKey, 1 18 Set objWShell = Nothing 19 Set objFS = CreateObject("Scripting.FileSystemObject") 20 FullPath = ModelDoc.GetPathName ' gets the path of the file 21 SlashPosition = InStrRev(FullPath, "\") 'gets the position of last \ 22 FileName = Right(FullPath, Len(FullPath) - SlashPosition) 'removes path and leaves part name 23 FileNameNoExt = Left(FileName, Len(FileName) - 7) 'takes off the SLDPRT 24 FolderName = Left$(FileName, 4) 'give 1st 4 characters of part name 25 'strPDFName = objFS.buildpath(objFS.GetParentFolderName(DrawingDoc.GetPathName), objFS.GetBaseName(DrawingDoc.GetPathName) & ".PDF") 26 'strPDFName = "H:\DWGS\" & FolderName & "\" & FileNameNoExt & ".PDF" 27 DrawingDoc.SaveAs4 strPDFName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, lngErrors, lngWarnings 28 Else 29 MsgBox "A SolidWorks Drawing document must be open in order to SaveAs a PDF!", vbInformation 30 End If 31 Else 32 MsgBox "A SolidWorks Drawing document must be open in order to SaveAs a PDF!", vbInformation 33 End If 34 End Sub- posted
17 years ago