QX.js Scripting Guide

Working with Layers

QXML for layer

Layer is represented by the  <qx-layer> node. It contains the following attributes:

Attribute

Value

Description

layer-name

text

Name of layer

layer-id

number

Unique ID of layer as generated by QuarkXPress

Create new layer

To create a new layer:

  1. Get the DOM of the active layout.

  2. Create a new <qx-layer> element.

  3. Set the layer-name attribute in the <qx-layer> element.

  4. Append the <qx-layer> element as a child of the <qx-layout> node.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var layer = document.createElement('qx-layer');
layer.setAttribute('layer-name','My Layer');
layout.appendChild(layer);

Delete an existing layer

To delete an existing layer:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node corresponding to the layer to be deleted.

  3. Remove the <qx-layer> child node from the <qx-layout> node.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
layout.removeChild(layer);

Hide a layer

To hide a layer:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node .

  3. Set the qxVisibility styling attribute to hidden.

var layout = app.activeLayoutDOM();
var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
layer.style.qxVisibility = 'hidden';

Lock a layer

To lock a layer:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node .

  3. Set the qxLocked styling attribute to true.

var layout = app.activeLayoutDOM();
var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
layer.style.qxLocked = 'true';

Suppress output for a layer

To suppress output for a layer:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node .

  3. Set the qxSuppressOutput styling attribute to true.

var layout = app.activeLayoutDOM();
var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
layer.style.qxSuppressOutput = 'true';

Keep runaround for layer

To remote keep runaround property for a layer:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node .

  3. Set the qxKeepRunaround styling attribute to false.

var layout = app.activeLayoutDOM();
var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
layer.style.qxKeepRunaround = 'false';

Specify layer color

To specify the color for a layer using RGB values:

  1. Get the DOM of the active layout.

  2. Get the <qx-layer> node .

  3. Specify the RGB color value qxColor styling attribute.

    var layout = app.activeLayoutDOM();
    var layer = layout.querySelector("qx-layer[layer-name='My Layer']");
    layer.style.qxColor= 'rgb(240,55, 217)';