PDM TASK Print macro: PDF printing problem

Programming and macros
User avatar
mp3-250
Posts: 660
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 742
x 361

PDM TASK Print macro: PDF printing problem

Unread post by mp3-250 »

This post is related to another topicI posted in the forum:
https://www.cadforum.net/viewtopic.php?t=2058

I cannot attach samples due to company regulation.

I am trying to modify the PDM Task macro to print in PDF instead of a phisical printer as the export to PDF function (basically save as -> pdf) is bugged and the output pdf differs from what you see on screen. The PDF printer works perfectly from SW interface (File -> Print), but if it run from the macro there are some files in my sample data that often cannot be correctly exported: often they end up as a minuscule drawing in a corner of the paper, like the pdf creation was aborted midway before fitting drawing to the paper size; sometimes the drawing borders are fitted and only the text and some lines remain small in a corner of the "paper space".

The point is that the same files that "fail" with the macro are always printed correctly in PDF from SW UI, so even if there is a problem inside those files that issue is ignored by the print interface within solidworks and ghostscript makes a correct PDF.

With my very limited VBA skills I managed to modify the TASK macro to work with the PDF printer, and I tried to update the method from PrintOut2 to PrintOut3 with the same outcome. Same bugged PDF from the same "problematic" files.
I am looking to upgrade to PrintOut4 in the hope it fixes the PDF and give me the same outcome I get from the SW Print command in the UI, but PrintOut4 is quite different and I am looking for some help to undestand how to do it.

For reference

PrintOut2 Method (IModelDocExtension) https://help.solidworks.com/2010/englis ... tout2.html

Prints the document, without displaying any dialogs or message boxes.

Code: Select all

Dim instance As IModelDocExtension
Dim PageArray As System.Object
Dim Copies As System.Integer
Dim Collate As System.Boolean
Dim Printer As System.String
Dim PrintFileName As System.String
 
instance.PrintOut2(PageArray, Copies, Collate, Printer, PrintFileName)
PrintOut3 Method (IModelDocExtension) https://help.solidworks.com/2015/englis ... tOut3.html

Code: Select all

Dim instance As IModelDocExtension
Dim PageArray As System.Object
Dim Copies As System.Integer
Dim Collate As System.Boolean
Dim Printer As System.String
Dim PrintFileName As System.String
Dim ConvertToHighQuality As System.Boolean
 
instance.PrintOut3(PageArray, Copies, Collate, Printer, PrintFileName, ConvertToHighQuality)
I added a true to convert in high quality to the PrintOut2, and it worked, but PrintOut4 is quite different

PrintOut4 Method https://help.solidworks.com/2015/englis ... tOut4.html

Code: Select all

Dim instance As IModelDocExtension
Dim Printer As System.String
Dim PrintFileName As System.String
Dim PrintSpecification As System.Object
 
instance.PrintOut4(Printer, PrintFileName, PrintSpecification)
As it requires PrintSpecification defined as

Code: Select all

Dim instance As IPrintSpecification
https://help.solidworks.com/2015/englis ... mbers.html

Property Collate Gets or sets whether to collate the pages in multiple copies of this document.
Property ConvertToHighQuality Gets or sets whether to convert draft quality drawing views to high quality.
Property CurrentSheet Gets the index of the current sheet.
Property FromScale Gets or sets the custom "from" scale factor for the current drawing sheet.
Property NumberOfCopies Gets or sets the number of copies to print.
Property PrintBackground Gets or sets whether to print the background.
Property PrintCrossHatchOnOutOfDateViews Gets or sets whether to print a cross hatch on out-of-date views.
Property PrinterQueue Gets or sets the printer to use.
Property PrintFile Gets or sets the path and file name to which to print the document.
Property PrintRange Gets or sets the range of pages to print.
Property PrintToFile Gets or sets whether to print to a file.
Property PrintWhiteItemsBlack Gets or sets whether to print white lines and white text in black.
Property ScaleMethod Gets or sets the page selection option for printing.
Property SheetCount Gets the number of sheets in this drawing.
Property ToScale Gets or sets the custom "to" scale factor for the current drawing sheet.
Property XOrigin Gets or sets the X-coordinate of the print window origin.
Property YOrigin Gets or sets the Y-coordinate of the print window origin.

From what I understand I need to set those properties before printing with PrintOut4.
To export in PDF I need a 100% scale, how it can be set up?
Also how the paper is passed to the printer?
by mp3-250 » Sun Sep 11, 2022 7:38 pm
In the end I solved adding the code below, the rest of printspecification members was already in the script

Code: Select all

Dim swPrintSpec As SldWorks.PrintSpecification
Set swPrintSpec = swExtension.GetPrintSpecification
swPrintSpec.PrintRange = "*"
swExtension.PrintOut4 Printer, "", swPrintSpec
Go to full post
Former Mechanical Engineer (UG-NX ), now a miserable SW CAD/PDM admin... debugging Solidworks since 2014. Please save me from ThE pLaTfOrM...
All the opinions are my own.
SW is bad: a fact not an opinion.
User avatar
mp3-250
Posts: 660
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 742
x 361

Re: PDM TASK Print macro: PDF printing problem

Unread post by mp3-250 »

In the end I solved adding the code below, the rest of printspecification members was already in the script

Code: Select all

Dim swPrintSpec As SldWorks.PrintSpecification
Set swPrintSpec = swExtension.GetPrintSpecification
swPrintSpec.PrintRange = "*"
swExtension.PrintOut4 Printer, "", swPrintSpec
Former Mechanical Engineer (UG-NX ), now a miserable SW CAD/PDM admin... debugging Solidworks since 2014. Please save me from ThE pLaTfOrM...
All the opinions are my own.
SW is bad: a fact not an opinion.
jtja90
Posts: 1
Joined: Wed Dec 11, 2024 2:55 am
Answers: 0

Re: PDM TASK Print macro: PDF printing problem

Unread post by jtja90 »

Hi @mp3-250 ,
I hope you don't mind me asking, but could you elaborate on how you succeeded in updating in your Print to PDF script to print into a single file with all sheets from your drawing? When I try using your provided code:

Dim swPrintSpec As SldWorks.PrintSpecification
Set swPrintSpec = swExtension.GetPrintSpecification
swPrintSpec.PrintRange = "*"
swExtension.PrintOut4 Printer, "", swPrintSpec

I can only get my PDF printer (Adobe PDF) to print out 1 sheet at a time, and only separately at best. Meaning, if I change the "Replace Existing file", in the Adobe PDF printer prereferences, from "Always" to "Never", it will print each sheet into separate files. If I select "always" it will print one sheet a time, and replace the existing file again and again.

I can see that the PDM task (Print to PDF) interprets the sheets as individual configurations, but if I use the traditional "Save as PDF" script, it correctly interprets it as one configuration with "All sheets". Example:
image.png
How did you solve this?

I, too, have issues with the traditional "Save as PDF" because it doesn't correctly print what's being shown in the drawing document by default, and I can't get it to do it even with forcerebuild3.

I hope you can help.

Best regards,
User avatar
mp3-250
Posts: 660
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 742
x 361

Re: PDM TASK Print macro: PDF printing problem

Unread post by mp3-250 »

jtja90 wrote: Wed Dec 11, 2024 6:44 am Hi @mp3-250 ,
I hope you don't mind me asking, but could you elaborate on how you succeeded in updating in your Print to PDF script to print into a single file with all sheets from your drawing? When I try using your provided code:

Dim swPrintSpec As SldWorks.PrintSpecification
Set swPrintSpec = swExtension.GetPrintSpecification
swPrintSpec.PrintRange = "*"
swExtension.PrintOut4 Printer, "", swPrintSpec

I can only get my PDF printer (Adobe PDF) to print out 1 sheet at a time, and only separately at best. Meaning, if I change the "Replace Existing file", in the Adobe PDF printer prereferences, from "Always" to "Never", it will print each sheet into separate files. If I select "always" it will print one sheet a time, and replace the existing file again and again.

I can see that the PDM task (Print to PDF) interprets the sheets as individual configurations, but if I use the traditional "Save as PDF" script, it correctly interprets it as one configuration with "All sheets". Example:

image.png

How did you solve this?

I, too, have issues with the traditional "Save as PDF" because it doesn't correctly print what's being shown in the drawing document by default, and I can't get it to do it even with forcerebuild3.

I hope you can help.

Best regards,
it is not possible apparently.
at least with the print task. the convert task should be able to do it, but it is bugged.

the print task act like a printer. one sheet at time and output to single files.
I suspect you can only post process the single pdf files to collage them into a single one later.

once released to print solidworks has no more control and the pdf driver takes over and it has no way to know the difference from a multiple sheets and a single sheet file.
Post Reply