Showing / hiding layers

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
User avatar
andrew
Site Admin
Posts: 5607
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: 5607
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 Developers and Contributors”