Scripting - Autozoom, Print to Scale as PDF

Do you have a question you want to ask an existing QCAD user about QCAD and what you can do with it? Do you want to know if a particular feature exists? This is the place to ask.

Moderator: andrew

Post Reply
bmlyvb
Newbie Member
Posts: 3
Joined: Fri Apr 13, 2018 5:20 pm

Scripting - Autozoom, Print to Scale as PDF

Post by bmlyvb » Tue Apr 17, 2018 3:53 pm

Hello,
I'm currently attempting to develop a script to open an unknown filename .dxf, autozoom (part will not always be drawn near the origin) print it as a pdf, and the tricky bit is I'm also attempting to print it to a printer calibration - we've yet to buy QCad Pro (4 copies will need purchased), but plan to if the script in question can be successfully executed.

For our application, the end goal is launching QCad via command line with -autostart; obviously, my current code isn't there yet. We need to apply a printer calibration because we do indeed need to print it, however, our printers are networked - adobe reader has functionality to print to the default printer, whereas I don't believe QCad does. If I'm mistaken, that's great though. If successful, this will be deployed at 4 locations, hence printer IP and name vary.

Things I still need to modify the script for are: open generic file name in location folder (instead of scripting the file name in), integrate printer calibration, integrate autozoom for drawings away from the origin

I am not competent in javascript, so what I have so far is stitched together from various examples and search results from these forums. My current script is as follows:

Code: Select all

// include class Print and OpenFile:
include("scripts/EAction.js");
include("scripts/File/OpenFile/OpenFile.js");
include("scripts/File/Print/Print.js");  

//! [init]
// init application name:
//qApp.applicationName = "ScalePrint";

//! [document]
var document = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel());
// create document interface (needed for file export functionality):
var di = new RDocumentInterface(document);
di.importFile('C:/Users/BML/Desktop/Test/1-1.dxf');
//! [document]

//! [view]
var scene = new RGraphicsSceneQt(di);
var view = new RGraphicsViewImage();
view.setScene(scene,false);
//! [view]

//! [settings]
// set up page and paper settings as document variables:
var pageWidth = 8.5;
var pageHeight = 11;
var bb = document.getBoundingBox(true, true);
var scale = 1.0;

// paper unit:
document.setVariable("PageSettings/PaperUnit", RS.Inch);

// paper width:
document.setVariable("PageSettings/PaperWidth", pageWidth);

// paper height:
document.setVariable("PageSettings/PaperHeight", pageHeight);

// page orientation ("Portrait" | "Landscape"):
document.setVariable("PageSettings/PageOrientation", "Landscape");
 
// color mode ("FullColor" | "GrayScale" | "BlackWhite"):
document.setVariable("ColorSettings/ColorMode", "BlackWhite");

// background color:
document.setVariable("ColorSettings/BackgroundColor", new RColor("white"));

// drawing scale as string:
document.setVariable("PageSettings/Scale", "1:1");

// offset of drawing origin to lower left corner in drawing units:
document.setVariable("PageSettings/OffsetY", -(pageWidth/scale - bb.getWidth()) / 2);
document.setVariable("PageSettings/OffsetX", -(pageHeight/scale - bb.getHeight()) / 2);
 
// number of pages (rows / columns):
document.setVariable("MultiPageSettings/Rows", 1);
document.setVariable("MultiPageSettings/Columns", 1);
// switch on / off crop marks:
document.setVariable("MultiPageSettings/PrintCropMarks", false);
// switch on / off page tags:
document.setVariable("PageTagSettings/EnablePageTags", false);
//! [settings]
 
//! [export]
var print = new Print(undefined, document, view);

print.print("C:/Users/BML/Desktop/Test/example.pdf");
//! [export] 
What's unusual is that the points print huge, ie, .2" across. The end application of this is to verify mylars on a grid. The default print size of points done manually is perfect, but this size is far too large. From what I'd read previously, I didn't think it was possible to change how points printed in QCad?
Attached are the .dxf currently used, and the output example.pdf.
Any assistance would be greatly appreciated.
Also, I'm sorry if this is in the wrong section - it's a How Do I, yet its Pre-Sales if successful.
Attachments
ScalePrint.js
(2.37 KiB) Downloaded 54 times
1-1.dxf
(174.06 KiB) Downloaded 52 times

User avatar
andrew
Site Admin
Posts: 5603
Joined: Fri Mar 30, 2007 6:07 am

Re: Scripting - Autozoom, Print to Scale as PDF

Post by andrew » Wed Apr 18, 2018 11:47 am

bmlyvb wrote:What's unusual is that the points print huge, ie, .2" across.
Thanks for your report. I can confirm this is a bug. I've fixed this for the next release and also made the point size for printing configurable.

You can download the current snapshot release with this fix applied at:
http://qcad.org/archives/snapshots/
bmlyvb wrote:I'm currently attempting to develop a script to open an unknown filename .dxf, autozoom (part will not always be drawn near the origin) print it as a pdf, and the tricky bit is I'm also attempting to print it to a printer calibration
Are you aware of the dwg2pdf command line tool that comes with QCAD Professional?

dwg2pdf converts a given drawing to PDF and supports auto zoom. In the current snapshot it also supports direct printing to the default or another printer, printing to scale, auto center as follows:

Code: Select all

# print given file to default printer at scale 1:1, auto centered to paper, print points at a size of 0.5mm:
dwg2pdf -scale=1 -center -paper=Letter -point-size=0.5 -printer file.dxf

# print given file to specific printer:
dwg2pdf -a -p Letter -printer=HP_LaserJet_P2055dn file.dxf

# convert given file to PDF:
dwg2pdf -a -p Letter -f file.dxf

# use scale of 0.5 with an offset:
dwg2pdf -p Letter -scale=0.5 -offset=1.4,2.5 -f file.dxf

# list available printer names:
dwg2pdf -list-printers
Printer specific calibration values can be written to a settings file prior to the conversion, e.g.:

File settings.js:

Code: Select all

RSettings.setValue("HP_LaserJet_P2055dn/FactorX", 1.02);
RSettings.setValue("HP_LaserJet_P2055dn/FactorY", 0.98);
Write settings to QCAD3.ini configuration file:

Code: Select all

qcad.exe -autostart settings.js

bmlyvb
Newbie Member
Posts: 3
Joined: Fri Apr 13, 2018 5:20 pm

Re: Scripting - Autozoom, Print to Scale as PDF

Post by bmlyvb » Wed Apr 18, 2018 6:47 pm

I was aware of dwg2pdf, but I wasn't aware of it's extended functionality about to be incorporated! Thank you, I think that might just do the trick.

Is there any way to open a snapshot release without the trial-only mode? We have purchased a single copy for continued trials. I'm assuming there's no way to run the utility silently? Currently, we're planning to execute it via a .bat; @echo off doesn't seem to do much to help.

I'm experiencing a strange error in that although both the QCAD3.ini file and the QCad GUI both register the correct printer calibration, it prints with a separate calibration - that, or there's a strange scaling error happening. Manually printing to the printer works fine with no scaling error.

Thank you for your help!

User avatar
andrew
Site Admin
Posts: 5603
Joined: Fri Mar 30, 2007 6:07 am

Re: Scripting - Autozoom, Print to Scale as PDF

Post by andrew » Wed Apr 18, 2018 9:09 pm

bmlyvb wrote:Is there any way to open a snapshot release without the trial-only mode?
Yes, sure. I'll send you a link to the full version snapshots via private message.
bmlyvb wrote:I'm assuming there's no way to run the utility silently? Currently, we're planning to execute it via a .bat; @echo off doesn't seem to do much to help.
The bat file streams all output into a temporary file and then prints that file to stdout. You can change it (or create your own bat file) as follows:

Code: Select all

@echo off
qcad.exe -no-gui -allow-multiple-instances -autostart scripts\Pro\Tools\Dwg2Pdf\Dwg2Pdf.js %0 %* 1>NUL 2>&1
bmlyvb wrote:I'm experiencing a strange error in that although both the QCAD3.ini file and the QCad GUI both register the correct printer calibration, it prints with a separate calibration - that, or there's a strange scaling error happening. Manually printing to the printer works fine with no scaling error.
Does the error also occur when producing a PDF?
Can you provide a file to reproduce the error along with the exact parameters used to convert? Thanks.

bmlyvb
Newbie Member
Posts: 3
Joined: Fri Apr 13, 2018 5:20 pm

Re: Scripting - Autozoom, Print to Scale as PDF

Post by bmlyvb » Wed Apr 18, 2018 9:41 pm

Thank you! Message/download received.

The error doesn't occur on printing PDFs, only on printing, which is why I think I've got a printer calibration problem somewhere - I'd not at all be surprised if it's a local issue and not reproduce-able. I've attached the dxf I've been using. My .bat that's calling it is as follows:

Code: Select all

cd "C:\Users\BML\Desktop\qcad-3.20.1.2-trial-win64\qcad-3.20.1.2-trial-win64\" 

dwg2pdf -scale=1 -center -paper=Letter -landscape -printer "C:\Users\BML\Desktop\Test\1-1.dxf"

pause
Additionally, attached is the scanned output/printed page. Roughly, the points measure .77 across X and 1.30 across Y. Should be a 1" grid. I know I messed around and set my default printer's calibration for 0.5 and 1.0, but I don't recall using 1.3 ever, nor .77. Anywhere I can check calibration settings besides the GUI and a .ini? Also interesting is that it appears to autocenter, then calibrate X-Y, given the intersection point of the lines. Curious!

Before posting the above, I tried removing the "-landscape" callout, and it printed perfectly...so I think there might be something wrong with that part? Unless I misused the argument of course!

Thank you again


EDIT: After thinking about it, I think something's wrong with the -landscape command; the dimensions I'm getting almost perfectly match the 8.5x11 factor; ie, 8.5/11 = .772 and 11/8.5 = 1.294
Attachments
Scan.pdf
(190.64 KiB) Downloaded 53 times
1-1.dxf
(174.06 KiB) Downloaded 52 times

User avatar
andrew
Site Admin
Posts: 5603
Joined: Fri Mar 30, 2007 6:07 am

Re: Scripting - Autozoom, Print to Scale as PDF

Post by andrew » Thu Apr 19, 2018 8:38 pm

bmlyvb wrote:The error doesn't occur on printing PDFs, only on printing, which is why I think I've got a printer calibration problem somewhere - I'd not at all be surprised if it's a local issue and not reproduce-able.
Yes, I cannot reproduce this here. -landscape seems to work just fine for both PDF output and direct printing. Also calibration has the desired effect in both cases.
bmlyvb wrote:Anywhere I can check calibration settings besides the GUI and a .ini?
No. Unless the printer driver has a setting for this.
bmlyvb wrote:Also interesting is that it appears to autocenter, then calibrate X-Y, given the intersection point of the lines. Curious!
This would be expected behavior, yes. Calibration values are typically somewhere in the range of 0.98-1.02 to correct paper slippage or other printer inaccuracies.
bmlyvb wrote:Before posting the above, I tried removing the "-landscape" callout, and it printed perfectly...so I think there might be something wrong with that part?
Perhaps the printer driver in use needs to be configured separately to print landscape. I don't have this issue here with a HP LaserJet. dwg2pdf uses the exact same code for scaling, calibration, etc. for PDF creation and printing. The only difference is the printer driver in use and of course the device self.

Creating a PDF and printing that might be an alternative if that works as expected.

Post Reply

Return to “Pre-sales Questions”