Page 1 of 1

Issues with a headless script to a) join curves b) save

Posted: Fri May 28, 2021 4:31 pm
by franksandqvist
Hi!

Looking to get QCAD professional implemented in our vector processing server (Debian in Docker).

What I am aiming to do is this;
a) import an SVG
b) join all lines by selecting all, then doing polylinesfromselection
c) saving as a DXF

I am having some issues, and I feel like I am doing this slightly wrong, and I am currently stuck with this error;
Warning: EAction.prototype.showUiOptions: no options toolbar
Warning: RScriptHandlerEcma::eval: script engine exception: "TypeError: Result of expression 'EAction.getDocumentInterface()' [undefined] is not an object

I believe this is due to the fact that I don't have a "window"/toolbar available for the script. I got it working in the interpreter window on the desktop version, but headless it's another story. Any help or nudges in the right direction would be hugely appreciated!

Code: Select all

./qcad -platform offscreen -allow-multiple-instances testscript.js infile.svg outfile.dxf

Code: Select all

include("scripts/ImportExport/SvgImporter/SvgImporter.js")
include("scripts/Select/SelectAll/SelectAll.js");
include("scripts/File/Save/Save.js");

const document = new RDocument(new RMemoryStorage(), new RSpatialIndexSimple());

const importer = new SvgImporter(document);
importer.importFile(args[1]);

const select = new SelectAll();
select.beginEvent();

RGuiAction.triggerByCommand("polylinefromselection");

const save = new Save();
s.save(args[2])

Re: Issues with a headless script to a) join curves b) save

Posted: Sat May 29, 2021 10:00 am
by andrew
Command line tools should use the lower level APIs that offer no interaction instead of triggering the interactive tools.

Code: Select all

// register SVG importer:
include("scripts/ImportExport/SvgImporter/SvgImporterInit.js");

...

RFileImporterRegistry.registerFileImporter(new SvgImporterFactory());

...

// import SVG:
if (di.importFile(cadFileName) !== RDocumentInterface.IoErrorNoError) {
    // cannot import file..
    // return or exit
}

// select all:
di.selectAll();

// create polylines from selection:
PolylineFromSelection.autoJoinSegments(di, 0.001);
Here's a good starting point for creating a command line tool script:
https://qcad.org/en/tutorial-command-line-tool-scripts

Re: Issues with a headless script to a) join curves b) save

Posted: Sat May 29, 2021 1:22 pm
by franksandqvist
Hi Andrew,

Thanks loads! I think I've misunderstood the script API's a bit. I'll keep going and see where it goes. :)

Re: Issues with a headless script to a) join curves b) save

Posted: Sun May 30, 2021 3:39 pm
by franksandqvist
andrew wrote:
Sat May 29, 2021 10:00 am
Command line tools should use the lower level APIs that offer no interaction instead of triggering the interactive tools.

Code: Select all

// register SVG importer:
include("scripts/ImportExport/SvgImporter/SvgImporterInit.js");

...

RFileImporterRegistry.registerFileImporter(new SvgImporterFactory());

...

// import SVG:
if (di.importFile(cadFileName) !== RDocumentInterface.IoErrorNoError) {
    // cannot import file..
    // return or exit
}

// select all:
di.selectAll();

// create polylines from selection:
PolylineFromSelection.autoJoinSegments(di, 0.001);
Here's a good starting point for creating a command line tool script:
https://qcad.org/en/tutorial-command-line-tool-scripts
Thanks again Andrew, I seem to be on the right track now. However, I cannot seem to find the API for this "PolylineFromSelection.autoJoinSegments". Or was it pseudo-code, perhaps?

I cannot find anything related to joining lines / polylines from segments in the docs or in the GitHub source code - am I looking in the wrong place?

Re: Issues with a headless script to a) join curves b) save

Posted: Sun May 30, 2021 6:29 pm
by CVH
Hi,
Have a look here:
https://qcad.org/rsforum/viewtopic.php?t=7210
https://qcad.org/rsforum/viewtopic.php?t=7057

It is part of the proprietary API of QCAD Professional.

Regards,
CVH

Re: Issues with a headless script to a) join curves b) save

Posted: Sun May 30, 2021 6:36 pm
by franksandqvist
Hi!

Aha - explains why I couldn't find anything. Will be purchasing a license next week! 👍

Thanks again