Write Script to Change Color of a Line

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
HappyShat
Full Member
Posts: 64
Joined: Thu Jul 25, 2019 9:43 pm

Write Script to Change Color of a Line

Post by HappyShat » Fri Nov 07, 2025 9:54 pm

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

Code: Select all

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?

Code: Select all

RColor(r,g,b);
I've tried using RColor() but got some kind of error (shown below)

Code: Select all

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

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

Re: Write Script to Change Color of a Line

Post by CVH » Tue Nov 11, 2025 9:51 pm

Hi,

Code: Select all

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

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”