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
ECMAScript examples
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Re: ECMAScript examples
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"
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":
You can activate a layer with:
You might also want to show the ECMAScript console which offers a great way to experiment with the script interface:
Misc > Development > Script Shell
Have a look for instance at "scripts/Misc/Examples"
There's a complete example script at:Eric123 wrote:Make a layer.
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);
To draw entities, you can use operations just like when adding a layer or again use the QCAD Simple API:Eric123 wrote:Add a horizontal line to that layer.
Code: Select all
include("simple.js");
...
addLine(x1,y2, x2,y2);
Code: Select all
var di = getDocumentInterface();
di.setCurrentLayer("MyLayer");
Misc > Development > Script Shell