Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save as PDF 3

Status
Not open for further replies.

MachineSMMC

Industrial
May 7, 2004
70
Is there anyway to link the save as pdf option in the file --> Save As Pulldown to a button or something to make it a little faster to do?

Thanks
Chris Tellers
 
Replies continue below

Recommended for you

Make sure save as pdf is checked in Tools, Add ins.

¿)

 
I think he means something like -> create macro SaveAsPDF -> rightclick toolbar -> commands -> macro -> new macro button.

Stefan Hamminga
EngIT Solutions
CSWP/Mechanical designer/AI student
 
Stefan

Not follwoing you. Could you give me a little more detail?

Thanks
Chris Tellers
 
You would want to create a macro that saves the current document to a PDF. You could start with the macro in this faq:


Modify it to save as pdf instead (see SW API help).

Then you would assign a button to this macro (to run it straight from the toolbar) with the procedure I described.

Add a macro button to your toolbar:

1. know where you saved the macro
2. right click on the toolbar
3. choose 'customize'
4. choose the 'commands' tab
5. choose the 'macro' category
6. drag the most right button (the 'new macro button') to the desired location on the toolbar
7. a box pops up, fill in the required fields

That should do the trick

Stefan Hamminga
EngIT Solutions
CSWP/Mechanical designer/AI student
 
Stefan

I am having no luck modifying the VBA to get it to work for the pdf.

Chris
 
I checked out the VBA in the FAQ. I've made the following changes for PDF and updating to SW2K6:

1. Change "+" to "&"
2. Eliminate the portion that strips ".sldprt" from modname, since the extension is not returned by GetTitle for a drawing file
3. Add a backslash between MyPath and NewName in the SaveAs line
4. Update to SaveAs4 from SaveAs2
5. Use "Sldworks.Application" instead of CreateObject

Code:
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

' ********************************************************
' Save As Parasolid.swb - Recorded on 02/10/02 by Lee Bell
' Modified for SW2K6 by JB on 3/31/06
' ********************************************************


Sub main()
 
  Set SwApp = Application.SldWorks
  ' This ensures that there are files loaded in SWX

  Set Model = SwApp.ActiveDoc
  If Model Is Nothing Then
      MB = MsgBox("This routine requires files to be loaded before it is ran" & Chr(13) & _
                  "Please load a file and run the routine again", vbCritical)
      Exit Sub
    End
  End If

' Use the current directory
  MyPath = CurDir
' Or specify the directory you want to use
' Comment out the next line if you want to use the current directory
  'MyPath = "C:\Where\Ever\Directory\You\Want\"

  ModName = Model.GetTitle
  NewName = ModName & ".pdf"
  MsgBox "Saving " & NewName & " To" & Chr(13) & MyPath

  MB = Model.SaveAs4(MyPath & "\" & NewName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Errs, Warnings)
  If Not MB Then MsgBox "failed!"
  Set Model = Nothing
  'SwApp.CloseDoc ModName
End Sub
 
How can I get the file to save in the same directory as the original file. What would the code be?

Thanks
Chris Tellers
 
Disregard previos post. Looks like it is already in there.

Handleman

I cannot seem to get this Macro to work

Thanks
Chris Tellers
 
This macro isn't functioning for me quite right. Specifically, it generates the PDF but doesn't seem to be saving to the directory the file originated in. Additionally it always says "Failed!" at the end even though it succeeded.

Any hints?
 
What version of SW are you running?
What kind of error messages are you getting?
Also, it doesn't currently save the file in the same directory as the drawing. It saves in the SolidWorks current directory, which is basically the directory that you last opened from or saved to. If you want to ensure that the PDF goes in the same directory, change the line

MyPath = CurDir

to

MyPath = Left(Model.GetPathName, InStrRev(Model.GetPathName, "\") - 1)
 
Yes, I am now getting the "failed!" message as well, even though the file seems to have saved fine. I didn't get that message when I modified the code originally. Weird. As long as it's working you can get rid of that line of code.
 
No errors, just get the "failed!" message despite the fact that it is performing fine otherwise. I'm using 2006.
 
Got it to work, with the failed message.

The only probelm is it does not come up with the dialog box to prompt you on which prints you want to print.

SolidWorks 2006 - SP 3.1

Thanks
Chris Tellers
 
It doesn't look like saving an individual sheet of a multi-sheet drawing is an option with the SaveAs4 API. The macro at cadimensions.com referenced by smcadman appears to be using the old (2k4) Bluebeam add-in for PDF, as it changes registry key

"HKEY_CURRENT_USER\Software\Bluebeam Software\Pushbutton PDF\SolidWorksLt\WhatToPlot"

to toggle between printing single sheets and printing all sheets. This key does not exist on my machine. The macro at rhapsodydesignsolutions.com does not appear to give the option of separate files for sheets.

Sorry!
 
This macro spontaneously stopped working for me--or possibly gradually as I wasn't here over the weekend. Nevertheless, it worked fine as of handleman's last post and isn't working for me today. I still get the message saying where it is saving but then it never generates the file.

I tried restarting Solid Works as well as disabling and re-enabling the PDF add-in to no effect. It isn't imperative I have this function, but anything that might save me 5 seconds for every single time we export it might save hours on a long enough time line.
 
Sorry, I forgot to mention that all my code is confidential and will self-destruct within 36-48 hours, never to work again.

OK, maybe not. I do feel like that myself sometimes, though. Even/especially with stuff I write for my own use. Something screwy always comes up.

Check the value of Errs and Warnings immediately after the save, as in:

MB = SaveAs4.....
MsgBox "Errors: " & Errs & vbcrlf & "Warnings: " & Warnings

If either of these values is not zero then check the API help for their meaning.

You mentioned disabling/reenabling the PDF add-in. Did you have that prior to 2k6? I actually never used the PDF save option until I got 2k6, which was a fresh install on a new box. I don't have anything listed in my add-ins. I wonder if there's some sort of conflict between what the old add-in is trying to do and what the now built-in SW functionality is trying to do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor