Prev: Free IGES Viewer?????
Next: Installation Problem
From: inthepickle on 5 May 2006 15:05 I was trying to take the first 4 characters of the Solidworks file name and use that variable as a folder name in the path of the place where the PDF was going to be saved. In hindsight, my problem was that it would only save to a folder that was manually created. I have now figured out how to create one on the fly now. Sorry for all of the confusion.
From: SW Monkey on 12 May 2006 17:45 fcsuper wrote: > Hope you don't mind my input...This is assembled from various sources > and input on eng-tips. I've left in three methods to set where to > save the PDF. Just comment out the methods not in use. It set it up > to limit PDFs only of drawings, but it can be changed to produce them > for models and assemblies too. This code includes error handling. > > > Dim SwApp As SldWorks.SldWorks > Dim Model As SldWorks.ModelDoc2 > Dim MyPath, ModName, NewName As String > Dim MB As Boolean > Dim Errs As Long > Dim Warnings As Long > > Sub main() > > Set SwApp = Application.SldWorks > > ' This ensures that there are files loaded in SolidWorks > Set Model = SwApp.ActiveDoc > If Model Is Nothing Then > MB = MsgBox("No drawing loaded!", vbCritical) > Exit Sub > End > End If > > ' Admonish user if attempted to run macro on part or assy file > If Model.GetType <> 3 Then > SwApp.SendMsgToUser "Current document is not a drawing." > End > End If > > ' Use one of the three following options for PDF save location > ' Comment out the options with are not used. > > ' Option 1: Use the current directory > ' MyPath = CurDir > ' > ' Option 2: Specify the directory you want to use > ' MyPath = "C:\PDF" > > ' Option 3: Use the drawing folder > MyPath = Left(Model.GetPathName, InStrRev(Model.GetPathName, "\") - > 1) > > ' Status > ModName = Left(Model.GetTitle, InStrRev(Model.GetTitle, " Sheet") - > 3) > NewName = ModName & ".pdf" > MsgBox "Save " & NewName & " to" & Chr(13) & MyPath & Chr(13) & > Chr(13) & "(No notification will occur " & Chr(13) & "for success PDF > creation.)" > > ' PDF Creation > MB = Model.SaveAs4(MyPath & "\" & NewName, swSaveAsCurrentVersion, > swSaveAsOptions_Silent, Errs, Warnings) > > ' Warnings to user on Error > ' MsgBox "Errors: " & Errs & vbCrLf & "Warnings: " & Warnings > If Warnings <> 0 Then > MsgBox "There were warnings. PDF creation may have failed. > Verify" & Chr(13) & "results and check possible causes.", vbExclamation > Else > End If > > If MB = False Then > MsgBox "PDF creation has failed! Check save location, available" > & Chr(13) & "disk space or other possible causes.", vbCritical > Else > End If > > 'Clear immediate values > Set Model = Nothing > Set MyPath = Nothing > > > End Sub fcsuper , Im looking at the macro you posted to replace mine. The issue I have with mine and yours is it doesnt notify you if the PDF already exist. In SW 2004, my macro did this. Something must have changed in the code, but I cant figure it out. Any ideas? If a PDF already exist in the directory its saving to, I want a message asking "are you sure you want to overwrite".
From: Seth Renigar on 13 May 2006 00:10 I know nothing about programming. But if you can't figure it out within the code, there is something else you can do that should prevent automatic overwrites. After you create your PDF's set them to read-only. Windows shouldn't allow you to overwrite the file (although I've seen stranger thing happen). -- Seth Renigar Emerald Tool and Mold Inc. (Remove ".no.spam" from my address) __ "SW Monkey" <2google311.50.spydermonkey(a)spamgourmet.com> wrote in message news:1147470303.360266.105580(a)u72g2000cwu.googlegroups.com... > > fcsuper wrote: >> Hope you don't mind my input...This is assembled from various sources >> and input on eng-tips. I've left in three methods to set where to >> save the PDF. Just comment out the methods not in use. It set it up >> to limit PDFs only of drawings, but it can be changed to produce them >> for models and assemblies too. This code includes error handling. >> >> >> Dim SwApp As SldWorks.SldWorks >> Dim Model As SldWorks.ModelDoc2 >> Dim MyPath, ModName, NewName As String >> Dim MB As Boolean >> Dim Errs As Long >> Dim Warnings As Long >> >> Sub main() >> >> Set SwApp = Application.SldWorks >> >> ' This ensures that there are files loaded in SolidWorks >> Set Model = SwApp.ActiveDoc >> If Model Is Nothing Then >> MB = MsgBox("No drawing loaded!", vbCritical) >> Exit Sub >> End >> End If >> >> ' Admonish user if attempted to run macro on part or assy file >> If Model.GetType <> 3 Then >> SwApp.SendMsgToUser "Current document is not a drawing." >> End >> End If >> >> ' Use one of the three following options for PDF save location >> ' Comment out the options with are not used. >> >> ' Option 1: Use the current directory >> ' MyPath = CurDir >> ' >> ' Option 2: Specify the directory you want to use >> ' MyPath = "C:\PDF" >> >> ' Option 3: Use the drawing folder >> MyPath = Left(Model.GetPathName, InStrRev(Model.GetPathName, "\") - >> 1) >> >> ' Status >> ModName = Left(Model.GetTitle, InStrRev(Model.GetTitle, " Sheet") - >> 3) >> NewName = ModName & ".pdf" >> MsgBox "Save " & NewName & " to" & Chr(13) & MyPath & Chr(13) & >> Chr(13) & "(No notification will occur " & Chr(13) & "for success PDF >> creation.)" >> >> ' PDF Creation >> MB = Model.SaveAs4(MyPath & "\" & NewName, swSaveAsCurrentVersion, >> swSaveAsOptions_Silent, Errs, Warnings) >> >> ' Warnings to user on Error >> ' MsgBox "Errors: " & Errs & vbCrLf & "Warnings: " & Warnings >> If Warnings <> 0 Then >> MsgBox "There were warnings. PDF creation may have failed. >> Verify" & Chr(13) & "results and check possible causes.", vbExclamation >> Else >> End If >> >> If MB = False Then >> MsgBox "PDF creation has failed! Check save location, available" >> & Chr(13) & "disk space or other possible causes.", vbCritical >> Else >> End If >> >> 'Clear immediate values >> Set Model = Nothing >> Set MyPath = Nothing >> >> >> End Sub > > fcsuper , > Im looking at the macro you posted to replace mine. The issue I have > with mine and yours is it doesnt notify you if the PDF already exist. > In SW 2004, my macro did this. Something must have changed in the > code, but I cant figure it out. > > Any ideas? > > If a PDF already exist in the directory its saving to, I want a message > asking "are you sure you want to overwrite". >
From: Mr. Who on 14 May 2006 22:49 A simple FileExists call should ensure that you don't overwrite a pre-existing file. Only a few additional lines of code.
From: SW Monkey on 15 May 2006 11:33
Mr. Who wrote: > A simple FileExists call should ensure that you don't overwrite a > pre-existing file. Only a few additional lines of code. I want the user to be allowed to overwrite the file, I just want them to be notified that a file exist already. Do you know the code I can use for this? Like I said, the macro does this in SW 2004, but not in SW 2005. |