ECMAScript examples

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
Eric123
Newbie Member
Posts: 3
Joined: Tue Nov 29, 2016 3:45 am

ECMAScript examples

Post by Eric123 » Fri Jun 23, 2017 5:20 pm

Where can I find some ECMAScript examples?
Some simple like:
Make a layer.
Add a horizontal line to that layer.
Make another layer.
Add a horizontal dimension to that layer.

QCAD PRO/CAM 3.17
Linux Mint

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

Re: ECMAScript examples

Post by andrew » Wed Jun 28, 2017 7:36 am

Each QCAD package comes with plenty of scripts you can browse through for example code in "scripts".

Have a look for instance at "scripts/Misc/Examples"
Eric123 wrote:Make a layer.
There's a complete example script at:
scripts/Misc/Examples/LayerExamples/ExAddLayer
The script adds the tool under:
Misc > Script Examples > Layer > Add Layer

Alternatively, you can update your QCAD Simple API (file scripts/simple_create.js) from:
https://raw.githubusercontent.com/qcad/ ... _create.js

This will give you a global convenience function "addLayer":

Code: Select all

addLayer("MyLayer1");
addLayer("MyLayer2", "white", "CONTINUOUS", RLineweight.Weight025);
Eric123 wrote:Add a horizontal line to that layer.
To draw entities, you can use operations just like when adding a layer or again use the QCAD Simple API:

Code: Select all

include("simple.js");
...
addLine(x1,y2, x2,y2);
You can activate a layer with:

Code: Select all

var di = getDocumentInterface();
di.setCurrentLayer("MyLayer");
You might also want to show the ECMAScript console which offers a great way to experiment with the script interface:
Misc > Development > Script Shell

Post Reply

Return to “QCAD 'How Do I' Questions”