Skip to main content
MarkWalsh
Inspiring
April 3, 2013
Answered

Javascript - deselect all layers

  • April 3, 2013
  • 1 reply
  • 4836 views

Is there a simple command to deselect all layers in the currrent document via javascript? I'm running a script which is getting fouled up if there is a layer selected in the document.

This topic has been closed for replies.
Correct answer Paul Riggott

This will de-select all layers Mark...

function deselectLayers() {

    var desc01 = new ActionDescriptor();

        var ref01 = new ActionReference();

        ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    desc01.putReference( charIDToTypeID('null'), ref01 );

    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );

};

1 reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
April 3, 2013

This will de-select all layers Mark...

function deselectLayers() {

    var desc01 = new ActionDescriptor();

        var ref01 = new ActionReference();

        ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    desc01.putReference( charIDToTypeID('null'), ref01 );

    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );

};

Inspiring
April 3, 2013

I don't know if this matters to you Mark but even if there are no layers selected in the layers panel

app.activeDocument.activeLayer

will return the top layer.