Scripting to produce new drawings

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
dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Scripting to produce new drawings

Post by dajo » Fri Dec 26, 2014 5:25 am

This is an enquiry about scripting. First I give some background
information, and then ask the questions. I hope you can help.

I have used QCad for a few years now. An early project used QCad 2
soon after scripting was introduced. This project involves setting
design parameters for hardware into external code (thousands of
lines), this programme outputs a .qs script, which is imported into
QCad. The resulting (many) .dxf files then are fed, via yet another
translation, into the driver of a laser cutter, and finally I end up
with my pieces of hardware.

This process took a lot of development effort, but was, and continues
to be, very successful, with QCad playing a very important part.

I have been using QCad 3.0.0 for a year or two for other design
purposes, but have only now been able to reserve the time to update
things (I have just installed QCad 3.7.5). My expectation has been
that I would be able to change the script-writing back-end of my
external code with relative ease, to produce .js files for QCad 3.

I am lost; I cannot see what should be my target code for QCad. So my
questions are these.

1. I have read
http://www.ribbonsoft.com/en/qcad-docum ... -scripting, but
that is too abstract for me. Also I looked at
/scripts/Draw/Text/Text.js, but that has not helped either. What
should an imported file look like? Can I write a main() function as I
did for QCad 2? Can you tell me where to look for an example?

2. Is there a logging system to enable me to see what is going on,
i.e., a debug system?

3. How do I import manually my .js file(s) into QCad 3? Is it via
Misc -> Import/Export? If not, how do I do it; alternatively, where
can I read about how to do it?

4. Under QCad 2, I set autostart.qs to be my input file. Is there an
equivalent automation mechanism for QCad 3?


I hope that you can see that this issue is important to me; also, that
I do not want to do a large amount of re-design, nor need to write a
large ECMAScript wrapper to effect the conversion. I can continue to
use QCad 2, but I really do not want to do that because I am writing
other projects using the same mechanisms; and I want to stay up to
date.

dajo
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

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

Re: Scripting to produce new drawings

Post by andrew » Fri Dec 26, 2014 10:57 am

dajo wrote:1. I have read
http://www.ribbonsoft.com/en/qcad-docum ... -scripting, but
that is too abstract for me. Also I looked at
/scripts/Draw/Text/Text.js, but that has not helped either. What
should an imported file look like? Can I write a main() function as I
did for QCad 2? Can you tell me where to look for an example?
In QCAD 3 there is currently no way to 'import' or 'run' a script loaded from anywhere on the disk using the QCAD application user interface.
The two possibilities you have are:
- Create a script in your QCAD installation directory under scripts in such a way that the script creates a menu for itself to run it. There are plenty of examples in the scripts directory of QCAD. A good staring point for your use case is probably 'scripts/Misc/Examples/MathExamples/ExMathSpiral/ExMathSpiral.js'
- Create a script anywhere on your disk and run it from the command line as a command line tool using the -autostart switch:
./qcad -autostart myscript.js
This essentially replaces the QCAD application with your own application.
Example for this: scripts/Tools/MergeDrawings/MergeDrawings.js
dajo wrote:2. Is there a logging system to enable me to see what is going on,
i.e., a debug system?
To output to stdout, use:
print("text");
To output to stderr, use:
qDebug("text", object, ...);
To set a break point for the integrated script debugger, enter the following line in your code:
debugger;
The debugger also needs to be explicitly enabled since it might influence the behaviour of your code and even lead to crashes:
./qcad -enable-script-debugger
Once enabled, the debugger automatically pops up when there is an error in your script.
3. How do I import manually my .js file(s) into QCad 3? Is it via
Misc -> Import/Export? If not, how do I do it; alternatively, where
can I read about how to do it?
This does currently not exist in QCAD 3. The reason being that this simply never was requested before. It would be possible to create a script that implements a tool which allows the user to run any script from anywhere on the disk. The way I would probably do this is to eval the chosen script:
eval(fileContents);
And then execute a fixed method from that context, e.g. main:
main();
4. Under QCad 2, I set autostart.qs to be my input file. Is there an
equivalent automation mechanism for QCad 3?
The -autostart switch of QCAD 3 can be used to launch any script. However, the QCAD application is not started in this case but rather replaced by the given switch.
QCAD itself is actually started internally with its own autostart script:
./qcad -autostart ./scripts/autostart.js
By replacing this autostart script, you can create your own application as a command line or GUI application.

It's also possible to start a tool immediately after QCAD has launched:

Code: Select all

./qcad -exec ./scripts/File/OpenFile/OpenFile.js
This would launch QCAD and then launch the script OpenFile.js to allow the user to choose a file to open.

dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Re: Scripting to produce new drawings

Post by dajo » Sun Dec 28, 2014 8:18 pm

Thank you for your helpful reply. I am pursuing the -autostart command line
approach at the moment. I am running Linux and Gnome; using this switch enables
me to start QCAD in different configurations by using different desktop
launchers.

I should make clear that I am not conversant with JavaScript; I am having to
learn about it as I go.

I have run into a problem that I think is worth describing because it suggests
to me that there is something other than autostart.js affecting startup.
However, it could be another "cannot find it" problem within that file.

* copied: qcad-directory/scripts/autostart.js to somewhere-else/.

* in the copy: added "scripts/" to the first two include lines.

* in the copy: changed "scripts/" to "qcad-directory/scripts/" in eleven places

* ran in a shell, QCAD started and then stopped, below is the full shell output,
changing the name of autostart.js to dims.js made no difference, I tried it both ways:

WetSteam dajo ~ /home/dajo/.qcad/qcad-3.7.5-pro-linux-x86_64/qcad -autostart /home/dajo/Testing/qcad/storage/dims.js
Debug: RDwgPlugin::init
Debug: RDxfPlugin::init
Debug: RHelpPlugin::init
Debug: RProScriptsPlugin::init
Debug: loading patterns from file: "/homedata/users/dajo/.qcad/qcad-3.7.5-pro-linux-x86_64/linetypes/metric/qcadiso.lin"
Debug: shape found: "ZIG"
Debug: shape found: "BAT"
Debug: shape found: "TRACK1"
Debug: shape found: "BOX"
Debug: shape found: "CIRC1"
Debug: shape found: "RIGHT_ARROW"
Debug: loading patterns from file: "/homedata/users/dajo/.qcad/qcad-3.7.5-pro-linux-x86_64/linetypes/imperial/qcad.lin"
Debug: TIMER: 66 ms - "loading add-ons"
Debug: TIMER: 391 ms - "initializing add-ons"
Warning: RScriptHandlerEcma::eval: script engine exception: "TypeError: Result of expression 'action' [null] is not an object."
Warning: "<anonymous>()@/home/dajo/Testing/qcad/storage/dims.js:681"
Warning: At least one uncaught exception:
Warning: "<anonymous>()@/home/dajo/Testing/qcad/storage/dims.js:681"
Debug: "<global>() at -1"
WetSteam dajo ~

* commented line 681: // action.setChecked(statusBar.visible);

* re-ran successfully, but with no initial "new" command, and its effects, inside QCAD


With regard to the -exec switch. Would this be a suitable way for me to run a
script directly without going via OpenFile?


Where do I find RGuiAction?


Thank you for any help you can give me.
dajo
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

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

Re: Scripting to produce new drawings

Post by andrew » Mon Dec 29, 2014 11:06 am

dajo wrote:I am pursuing the -autostart command line
approach at the moment. I am running Linux and Gnome; using this switch enables
me to start QCAD in different configurations by using different desktop
launchers.
I wouldn't recommend changing or moving the original autostart.js of QCAD. The -autostart switch is intended to create your own application which can be as simple or as complex as required.
To launch QCAD using an alternative configuration (QCAD3.ini), use -config instead:

Code: Select all

./qcad -config /path/to/my/alternative/config/directory
Please refer also to the usage of QCAD for more command line switches:

Code: Select all

./qcad -help
With regard to the -exec switch. Would this be a suitable way for me to run a script directly without going via OpenFile?
With -exec, you can run any script that contains a QCAD action class. That is a class derived from EAction.
Here's a minimal example for such a class (must be stored in a directory called 'MyAction' which is a subdirectory of 'scripts'. The file name is 'MyAction.js':
include("scripts/EAction.js");

function MyAction(guiAction) {
    EAction.call(this, guiAction);
}

MyAction.prototype = new EAction();

MyAction.prototype.beginEvent = function() {
    qDebug("Hello World");
};

// init is called on start up to initialise the action. This typically adds an entry to a menu or tool bar but can also be used to create widgets, etc.
MyAction.init = function(basePath) {
    var action = new RGuiAction(qsTr("My Action"), RMainWindowQt.getMainWindow());
    action.setRequiresDocument(true);
    action.setScriptFile(basePath + "/MyAction.js");
    action.setWidgetNames(["DrawExamplesMenu"]);
};
The init implementation is optional, if you only intend to start the action using -exec:

Code: Select all

./qcad -exec scripts/MyAction/MyAction.js
Where do I find RGuiAction?
In src/core/RGuiAction.h / cpp

riverbuoy
Senior Member
Posts: 121
Joined: Thu Oct 03, 2013 5:37 pm

Re: Scripting to produce new drawings

Post by riverbuoy » Tue Dec 30, 2014 3:37 pm

Hi Andrew
andrew wrote:This does currently not exist in QCAD 3. The reason being that this simply never was requested before. It would be possible to create a script that implements a tool which allows the user to run any script from anywhere on the disk. The way I would probably do this is to eval the chosen script:
See my post "Wallchart and 'Run Script' " in the plugins and addon challenge section. viewtopic.php?f=107&t=2910 The 'run script' init file needs to be changed to match the new ordering scheme.

Does this help?

riverbuoy

dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Re: Scripting to produce new drawings

Post by dajo » Fri Jan 02, 2015 4:07 am

My code conversion project is going very well. Like riverbuoy, I have abandoned using
the -autostart switch and use -exec, which performs about the same as the -autostart
technique in QCAD2. However, I have some questions that need answering in order to
finish what I am doing.

Using the command "quad -exec myfile.js" I am successfully producing a .dxf file.
However, when myfile.js is being processed the drawing is not rendered. If, after the
script has completed execution, I subsequently Open the file via the File menu
everything is normal, I see everything, and I can edit normally. I read about
Attaching a View somewhere, which has led me nowhere. So, the first question is: how
do I arrange within my script for the results of running the script to show in QCAD
without the need to Open the produced file?

A second question concerns some sort of focus. I can successfully create new layers,
but not write to them. Thus after myRDocumentInterface.setCurrentLayer("myNewLayer");
subsequent writes from myfile.js continue to layer 0, not to myNewLayer. What should
I be doing, please?

dajo
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Re: Scripting to produce new drawings

Post by dajo » Fri Jan 02, 2015 4:35 am

andrew wrote: I wouldn't recommend changing or moving the original autostart.js of QCAD. The
-autostart switch is intended to create your own application which can be as
simple or as complex as required.
As indicated in another post, I am no longer pursuing the -autostart method of
running a script. However, apparently I did not make clear what I was doing
with the -autostart switch; and I still think that the point raised is of
interest.

I did not change, nor move, the original autostart.js. In fact what I was doing
was precisely to avoid doing either of those things. What I was trying to do
with my copy, written to somewhere else on my disc, was reproduce what happens
with the original autostart.js by using the -autostart switch and a copy of that
original as my own application.

I needed to change the pathnames of included files in my copy so that QCAD could
find them. After that, there was an error on line 681, which is a line in the
original autostart.js. Commenting that line in the copy enabled QCAD to start,
but without the normal display, which I think is set up by the "new" command.

So that is it; it is quite simple really. I wondered at the time if there was
some other problem similar to the pathname problem preventing QCAD from
completing its startup.

dajo
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

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

Re: Scripting to produce new drawings

Post by andrew » Mon Jan 05, 2015 3:27 pm

dajo wrote:However, when myfile.js is being processed the drawing is not rendered. If, after the
script has completed execution, I subsequently Open the file via the File menu
everything is normal, I see everything, and I can edit normally. I read about
Attaching a View somewhere, which has led me nowhere. So, the first question is: how
do I arrange within my script for the results of running the script to show in QCAD
without the need to Open the produced file?
If I understand you correctly, you would like to start QCAD with a new, empty document and start adding entities to that document.

When launching QCAD without a file name as argument, a new, empty document is created. This document is the current document. Your action automatically operates in the context of that document.
You can access the current document using this.getDocument() in your EAction. To get a reference to the document interface, use this.getDocumentInterface().

If instead you create a new document with new RDocument(...), a new document is created without any view attached to it to visualize it.
A second question concerns some sort of focus. I can successfully create new layers,
but not write to them. Thus after myRDocumentInterface.setCurrentLayer("myNewLayer");
subsequent writes from myfile.js continue to layer 0, not to myNewLayer.
setCurrentLayer is one way of doing this. Perhaps, you are using two different documents to set the layer / add the layer / add the entities?

Another would be to assign the layer to the entity before adding it:
var op = new RAddObjectsOperation();
...
entity.setLayerId(document.getLayerId("myNewLayer"));
op.addObject(entity, false);    // false: don't use current layer and attributes but layer and attributes assigned to entity
...
documentInterface.applyOperation(op);

dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Re: Scripting to produce new drawings

Post by dajo » Tue Jan 06, 2015 7:14 am

At this point I am feeling pretty incompetent. Here is myfile.js which I load
with "qcad -exec myfile.js" and which demonstrates my current difficulties. Can
you help? If you run it you will need to change "disc-address".

/** -*-Mode: C; Coding: emacs-mule; fill-column: 100-*-
* Script for use in QCAD3
* Created by Transition Output
* 5 Jan 2015
* Job: TC Development QCAD3
*/

// See http://www.qcad.org/doc/qcad/latest/dev ... operations
var storage = new RMemoryStorage();
var spcIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spcIndex);
var docIntfc = new RDocumentInterface(document);
var operation = new RAddObjectsOperation();

operation.addObject(new RLayer(document, "component", false, false, new RColor("orange")))
operation.addObject(new RLayer(document, "envelopes", false, false, new RColor("blue")))

docIntfc.setCurrentLayer("envelopes");
operation.addObject(new RLineEntity(document, new RLineData(new RVector(40, 10), new RVector(40, 30))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(40, 30), new RVector(50, 30))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(50, 30), new RVector(50, 10))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(50, 10), new RVector(40, 10))));
docIntfc.setCurrentLayer("component");

var entity = new RLineEntity(document, new RLineData(new RVector(60, 20), new RVector(70, 40)));
entity.setLayerId(document.getLayerId("envelopes"));
operation.addObject(entity, false); // false: don't use current layer and attributes but layer and attributes assigned to entity

operation.apply(document);
docIntfc.autoZoom();
docIntfc.exportFile("/disc-address/TC Development QCAD3.dxf", "DXF 2013");

/**==== end of script created by Transition Output */

dajo
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

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

Re: Scripting to produce new drawings

Post by andrew » Tue Jan 06, 2015 11:07 am

Please have a look at the example action class "MyAction" which I've posted above (viewtopic.php?f=32&t=3193&view=unread#p11372).

This is the basic structure you have to use for a script you pass to -exec.
If you do not use this structure, your script will still be evaluated from top to bottom, but you will not have access to the current document, etc.

Everything you are doing in your script can go into the beginEvent function implementation. You can also add your own function and call them.

My advice is to start simple (with an exact copy of the example posted above). Once this works, get access to the current document:
var doc = this.getDocument();
Then, perhaps add a line to the current document, see if that works, etc.

dpsnet
Registered Member
Posts: 2
Joined: Sat Jan 10, 2015 9:29 am

Re: Scripting to produce new drawings

Post by dpsnet » Sat Jan 10, 2015 9:45 am

dajo wrote:At this point I am feeling pretty incompetent. Here is myfile.js which I load
with "qcad -exec myfile.js" and which demonstrates my current difficulties. Can
you help? If you run it you will need to change "disc-address".

/** -*-Mode: C; Coding: emacs-mule; fill-column: 100-*-
* Script for use in QCAD3
* Created by Transition Output
* 5 Jan 2015
* Job: TC Development QCAD3
*/

// See http://www.qcad.org/doc/qcad/latest/dev ... operations
var storage = new RMemoryStorage();
var spcIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spcIndex);
var docIntfc = new RDocumentInterface(document);
var operation = new RAddObjectsOperation();

operation.addObject(new RLayer(document, "component", false, false, new RColor("orange")))
operation.addObject(new RLayer(document, "envelopes", false, false, new RColor("blue")))

docIntfc.setCurrentLayer("envelopes");
operation.addObject(new RLineEntity(document, new RLineData(new RVector(40, 10), new RVector(40, 30))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(40, 30), new RVector(50, 30))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(50, 30), new RVector(50, 10))));
operation.addObject(new RLineEntity(document, new RLineData(new RVector(50, 10), new RVector(40, 10))));
docIntfc.setCurrentLayer("component");

var entity = new RLineEntity(document, new RLineData(new RVector(60, 20), new RVector(70, 40)));
entity.setLayerId(document.getLayerId("envelopes"));
operation.addObject(entity, false); // false: don't use current layer and attributes but layer and attributes assigned to entity

operation.apply(document);
docIntfc.autoZoom();
docIntfc.exportFile("/disc-address/TC Development QCAD3.dxf", "DXF 2013");

/**==== end of script created by Transition Output */

dajo
modify

Code: Select all

docIntfc.setCurrentLayer("envelopes");
to

Code: Select all

docIntfc.setCurrentLayer("envelopes");
operation.apply(document);
and modify

Code: Select all

docIntfc.setCurrentLayer("component");
to

Code: Select all

docIntfc.setCurrentLayer("component");
operation.apply(document);
the result is different。

dajo
Junior Member
Posts: 10
Joined: Fri Aug 23, 2013 4:02 pm

Re: Scripting to produce new drawings

Post by dajo » Sun Jan 18, 2015 10:30 pm

Thank you dpsnet for your helpful input.


It appears that I have been successful in achieving what I wanted to do. The
script below shows how I did it. I think that it is worth re-stating my
objectives.

* I have used QCAD2 for years to produce drawing sets from .qs scripts that are
written by external code; these drawings then are fed to a laser cutter which
produces hardware for assembly. The mechanism used is to write an
autostart.qs file. This process is completely automatic, requiring only the
initial launch of QCAD.

* I wanted to convert to using QCAD3 so that I can keep up to date. This
required two things: appropriate target code that will run in QCAD3 (the
scripting language has changed), and a mechanism to load and run
automatically.

The mechanism part has changed significantly in QCAD3 compared with QCAD2, and I
have found that the -exec switch to be more convenient than -autostart. This is
partly because I do not want to modify QCAD itself, which happens if -autostart
is used, since that involves starting my own application. Also, -exec enables
the scripts to reside in my job-specific directories, rather than in the QCAD
scripts directory.

The recommended coding method using EAction seems not to be completely
automatic. The code implements a tool inside QCAD, which then must be activated
by drawing down menus and clicking on the appropriate entry. I wanted to avoid
this busy work if possible; the QCAD2 mechanism is excellent, and anything else
would be a step backward from my point of view.

What is below works in QCAD 3.7.5; it does all that I need:

* Loads, runs, displays, saves output data with one command:
"qcad -exec myscript.js" I have this set in a desktop launcher that is
separate from the launcher used for ordinary QCAD use.

* Creates a multiplicity of .dxf files; i.e., all the drawings for a project.


If you study the script, bear in mind that it was written by another programme
running outside QCAD, which may explain curiosities, e.g., repeated literals.
Of course, such automation is not required.

You should be able to run the script using "qcad -exec this-script.js" if you
first reset the directory addresses for exportFile and openFiles (four places in
total).

dajo

/** -*-Mode: C; Coding: emacs-mule; fill-column: 100-*-
* Script for use in QCAD3
* Created by transitions.el
* 18 Jan 2015 at 12:20:28
* Job: Forum Record
*/


// See http://www.qcad.org/doc/qcad/latest/dev ... operations
var storage = new RMemoryStorage();
var spcIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spcIndex);
var docIntfc = new RDocumentInterface(document);
var operation = new RAddObjectsOperation();
var entity;
var layername;


/**==== Face Before, blank size 1 x 1 x 0.02 or 25 x 25 x 1 ====*/

storage = new RMemoryStorage();
spcIndex = new RSpatialIndexNavel();
document = new RDocument(storage, spcIndex);
docIntfc = new RDocumentInterface(document);
operation = new RAddObjectsOperation();

operation.addObject(new RLayer(document, "brownthings", false, false, new RColor("brown")));
operation.addObject(new RLayer(document, "redthings", false, false, new RColor("red")));
operation.addObject(new RLayer(document, "yellowthings", false, false, new RColor("yellow")));
operation.addObject(new RLayer(document, "greenthings", false, false, new RColor("green")));

layername = "yellowthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RCircleEntity(document, new RCircleData(new RVector(0, 0), 1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "greenthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RCircleEntity(document, new RCircleData(new RVector(0.3, 0.3), 0.1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RCircleEntity(document, new RCircleData(new RVector(-0.3, 0.3), 0.1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "redthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RArcEntity(document, new RArcData(new RVector(0, -1.4), 1, 1.1, 2.0416, false)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "brownthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RLineEntity(document, new RLineData(new RVector(0, 1), new RVector(0, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RLineEntity(document, new RLineData(new RVector(-0.3, 0.954), new RVector(-0.3, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RLineEntity(document, new RLineData(new RVector(0.3, 0.954), new RVector(0.3, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

operation.apply(document);
docIntfc.autoZoom();
docIntfc.exportFile("/home/dajo/tmp/QCAD-Forum/face-before.dxf", "DXF 2013");
openFiles(["/home/dajo/tmp/QCAD-Forum/face-before.dxf"]);


/**==== Face After, blank size 30 x 24 x 0.02 or 762 x 610 x 1 ====*/

storage = new RMemoryStorage();
spcIndex = new RSpatialIndexNavel();
document = new RDocument(storage, spcIndex);
docIntfc = new RDocumentInterface(document);
operation = new RAddObjectsOperation();

operation.addObject(new RLayer(document, "brownthings", false, false, new RColor("brown")));
operation.addObject(new RLayer(document, "yellowthings", false, false, new RColor("yellow")));
operation.addObject(new RLayer(document, "bluethings", false, false, new RColor("blue")));

layername = "yellowthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RCircleEntity(document, new RCircleData(new RVector(0, 0), 1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "brownthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RLineEntity(document, new RLineData(new RVector(0, 1), new RVector(0, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RLineEntity(document, new RLineData(new RVector(-0.3, 0.954), new RVector(-0.3, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RLineEntity(document, new RLineData(new RVector(0.3, 0.954), new RVector(0.3, 1.3))));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "bluethings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RCircleEntity(document, new RCircleData(new RVector(0.3, 0.3), 0.1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);
entity = (new RCircleEntity(document, new RCircleData(new RVector(-0.3, 0.3), 0.1)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

layername = "yellowthings";
docIntfc.setCurrentLayer(layername);
operation.apply(document);
entity = (new RArcEntity(document, new RArcData(new RVector(0, 0.3), 0.8, 4.141592653589793, 5.283185307179586, false)));
entity.setLayerId(document.getLayerId(layername));
operation.addObject(entity, false);

operation.apply(document);
docIntfc.autoZoom();
docIntfc.exportFile("/home/dajo/tmp/QCAD-Forum/face-after.dxf", "DXF 2013");
openFiles(["/home/dajo/tmp/QCAD-Forum/face-after.dxf"]);


/**==== end of script created by transitions.el */
dajo
Trisquel 10.0.1, QCad Pro 3.27.8

Post Reply

Return to “QCAD 'How Do I' Questions”