Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Printing to PDF Solidworks macro 1

Status
Not open for further replies.

Zenkai

Mechanical
May 12, 2006
3
Hi, I need a code that prints a drawing file as a PDF, I need something that alowes me to edit the location and name of the PDF save that it is printing.

I dont want to use SaveAS pdf option because some anotations such as weldments come out wrong, and if you use certan fonts then the users on other machines need those fonts to view the text.

I am running Solidworks 2006 3.1

If i try recording a macro
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
Part.PrintDirect
End Sub

The part.printdirect just promts me, and it prompts me for the last saved printer, so if it wasnt PDF it just prints to another printer. Again I would like to manipulate this to print specifially to a PDF and to say which dir and file name to save it as.

I don't want any reference to third party programs either please, I am building a custom macro and this will intergrate into what I am doing.

Thank you!
 
Replies continue below

Recommended for you

Sorry that I'm responding without an API solution. You could do this easy with a Windows level macro program that records keystrokes and mouse movement, like EZ Macros. In combination with my programmable keyboard, I couldn't live without it for repeatitive daily tasks in S/W and in Windows. The only limitation is that you have to be a little cleaver to allow sharing of the macro across systems.
 
Maybe this snippet will help:
partname = "c:\test\part.slddrw"
Set Part = swApp.OpenDoc6(partname, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings)
Set Model = swApp.ActiveDoc
Set ps = Model.PageSetup
ps.Orientation = 2 ' 1=Portrait '2 = Landscape
copies = 1
collate = True
SWPrinter = "\\%userpc%\AdobePDF"
ps.ScaleToFit = False
ps.Scale2 = 100
ps.PrinterPaperSize = 1
Model.Extension.PrintOut2 vPageArray, copies, collate, SWPrinter, ""
Set Part = Nothing

Note: Adobe Distiller will ask for save name for each file, its when you don't want this prompt things get more fun...
 
It's something I haven't done in Solidworks, but any other VBA project usually lets you do the following:

Application.ActivePrinter = "MyPrinterName"

My apologies if SW doesn't let you do that. I have done macros where it lets you run plenty of other VBA code, so I'm just assuming it should work.
 
Apologies

The application.activeprinter isn't going to work in SW. However, I do have a plotting program I did a while back that uses the Windows API to change the current printer/tray/papersize/etc. If you don't have anything working by Monday when I get back, I'll be sure to post it.
 
alexit advice looks good but having a little trouble getitng it the line to work, still testing things out

Got my macro working but have it set up to SaveAs PDF insted of print method for now until I get it working, thank you to all those who replied, if I find a final solution I will post it here.
 
I have a PDF related question. I have a drawing that is simply a bitmap of a suppliers part that I annotate on top of for laser marking details. However, everytime I export to .pdf it mirrors the image vertically causing my notes to be misaligned and any text from the supplier to be upside-down. Is this a commonly known bug? I've noticed it only does it for one of the two bitmaps in the drawing--odd. Also, after I save and reopen the images are blank (though still there). Does anyone have an idea how I can accomplish this?
 
This is a far to general of a description to tell what's going on. I will say that PDF is intentionally limited in editing abilities because its meant to be a standard document distribution format that protects the source, not a standard editing format. My advice is not to use PDF for this function. Save a backup of the bmp and just edit it directly, or use it as the backdrop for an Illustrator format file.
 
Hi,

Before I get stuck into designing a new macro, has anyone seen/developed a macro that exports solidworks files to various cad (& pdf) formats with revision, and possibly date, attached to the filename?


 


Yeah, mine does it typically requires the user to imput the revision level, but then it does it auto doing


Part.SaveAs ("I:\Engineering\Drawings\PDF\" & Folder & "\" & Filenumber & "-" & Rev & ".PDF")

Folder, Filenumber and Rev are all Variable strings, the folder and file number I am able to require automatically by the file name part number of the item I am creating in PDF, and like I said before it is the Revision level I have the user put in. So far it all works great, I Just rather save my PDF by printing rather than save as.

You can change the exention to DXF or DWG if you rather have a cad format
 
Revision and Approval Date? Try this:

'Get properties information
arrPrpName = swModel.GetCustomInfoNames: If IsEmpty(arrPrpName) Then Exit Sub
For Each PrpName In arrPrpName
If PrpName = "Revision" Then
strRev = swModel.GetCustomInfoValue("", "Revision")
End If
If PrpName = "AppDate" Then
strDate = swModel.GetCustomInfoValue ("", "AppDate")
End If
Next PrpName

'strDate = swModel.SummaryInfo(swSumInfoSaveDate)

'Set path to save STP file
strPath = InputBox ("Save Path","","C:\Temp\")

'Determine file name
strFullName = swModel.GetPathName
strFileName = Right(strFullName,13)
strShortName = Left(strFileName, Len(strFileName) - 7)
strSaveName = strPath & strShortName & strRev & strDate & ".STEP"

'Save as STEP to path
swModel.SaveAs2 strSaveName, 0, True, False

For revision and file date uncomment out the strDate line...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor