Showing / hiding layers

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
User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Showing / hiding layers

Post by andrew » Tue Mar 14, 2017 3:14 pm

From a QCAD user:
How can I show / hide layers of a document in a script?

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

Re: Showing / hiding layers

Post by andrew » Tue Mar 14, 2017 3:18 pm

Showing / hiding a layer is a modification of the document. Like all modifications, this has to happen in an operation, triggering a transaction:

Code: Select all

var operation = new RModifyObjectsOperation();
var layers = document.queryAllLayers();
for (var l = 0; l < layers.length; ++l) {
    var layer = document.queryLayer(layers[l]);
    if (layer.getName()==="MyLayer") {
        // show layer "MyLayer":
        layer.setFrozen(false);
    } else {
        // hide all other layers:
        layer.setFrozen(true);
    }
    operation.addObject(layer);
}
documentInterface.applyOperation(operation);

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”