Page 1 of 1

Showing / hiding layers

Posted: Tue Mar 14, 2017 3:14 pm
by andrew
From a QCAD user:
How can I show / hide layers of a document in a script?

Re: Showing / hiding layers

Posted: Tue Mar 14, 2017 3:18 pm
by andrew
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);