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

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
franksandqvist
Newbie Member
Posts: 4
Joined: Fri May 28, 2021 4:25 pm

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

Post by franksandqvist » Fri May 28, 2021 4:31 pm

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])

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

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

Post by andrew » 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

franksandqvist
Newbie Member
Posts: 4
Joined: Fri May 28, 2021 4:25 pm

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

Post by franksandqvist » Sat May 29, 2021 1:22 pm

Hi Andrew,

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

franksandqvist
Newbie Member
Posts: 4
Joined: Fri May 28, 2021 4:25 pm

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

Post by franksandqvist » Sun May 30, 2021 3:39 pm

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?

CVH
Premier Member
Posts: 3415
Joined: Wed Sep 27, 2017 4:17 pm

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

Post by CVH » Sun May 30, 2021 6:29 pm

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

franksandqvist
Newbie Member
Posts: 4
Joined: Fri May 28, 2021 4:25 pm

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

Post by franksandqvist » Sun May 30, 2021 6:36 pm

Hi!

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

Thanks again

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”