[SOLVED] RLayer setColor

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
sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

[SOLVED] RLayer setColor

Post by sinase » Thu Mar 18, 2021 11:44 am

Hi,

There is any example to change the current layer color by script code?

I have seen the module RLayer --> setColor but i don't know how his use is.

Thanks
Last edited by sinase on Thu Mar 18, 2021 6:20 pm, edited 1 time in total.

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

Re: RLayer setColor

Post by andrew » Thu Mar 18, 2021 12:55 pm

You can find an example script that changes the color of a layer at:
viewtopic.php?f=32&t=6008&p=22580#p22580

The ID of the current layer can be queried as:

Code: Select all

var id = document.getCurrentLayerId();

sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Re: RLayer setColor

Post by sinase » Thu Mar 18, 2021 4:47 pm

Thank you Andrew,

var di = this.getDocumentInterface();
var document = this.getDocument();
var op = new RModifyObjectsOperation();
var id = document.getCurrentLayerId();
var layer = document.queryLayer(id);
layer.setColor(new RColor("#ff0000"));
op.addObject(layer);
di.applyOperation(op);

This code works for my application.
Regards.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”