Write Script to Change Color of a Line

I don’t have much experience writing JavaScipt for QCAD - although about 10 years ago I was writing quite a lot of JavaScript (for websites).

I’m kludging together code. I’m using the following code (which works fine):

addLine(x0, y0, x1, y1);

Where the variables are the desired coordinates.

I’d like to also change the color of the line as they are drawn. Would the following code be suitable?

RColor(r,g,b);

I’ve tried using RColor() but got some kind of error (shown below)

Script exception in script 'C:/<path>/spiral_trace.js': Error: :-1:-1: RColor(): Did you forget to construct with 'new'? <native>(23, 165, 231) at -1 anonymous() at 31 <anonymous>() at :scripts/Misc/MiscDevelopment/RunScript/RunScript.js:120 <eval>() at 1 <native>() at -1 main() at :scripts\autostart.js:826 <global>() at :scripts\autostart.js:839

From the error message - I guess I didn’t " construct with ‘new’ "

So, what does that mean?

How do I “construct with new”?

Perhaps a example code showing typical use of RColor() would help. QCAD documentation was overwhelming. Searching “color” here yielded the haystack instead of the needle I was looking for.

I’m using QCAD version 3.24.3.0 (3.24.3) and Windows 11 Pro.

Thanks!

HS

Hi,

addLine(x0, y0, x1, y1);

Is part of the Simple API.
This doesn’t allow for additional properties.

One could first set the current pen color with: setCurrentColor(…)
And/or the layer: setCurrentLayer(…)
But not the Linetype.

Another option is to use the full QCAD API

Note that most QCAD tools are implemented as scripts.
Meaning that there is a vast collection of example scripts. :wink:

Regards,
CVH