Printing to PDF Solidworks macro
Printing to PDF Solidworks macro
(OP)
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!
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!






RE: Printing to PDF Solidworks macro
RE: Printing to PDF Solidworks macro
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...
RE: Printing to PDF Solidworks macro
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.
RE: Printing to PDF Solidworks macro
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.
RE: Printing to PDF Solidworks macro
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.
RE: Printing to PDF Solidworks macro
RE: Printing to PDF Solidworks macro
RE: Printing to PDF Solidworks macro
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?
RE: Printing to PDF Solidworks macro
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
RE: Printing to PDF Solidworks macro
'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...