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 );

};

MarkWalsh
MarkWalshAuthor
Inspiring
April 3, 2013

Thanks, I had considered using the scriptlistener, but had hoped there was an actual command to do so. I've been swamped with work, and thought I was just missing something obvious. I guess this means there isn't any other way.

I appreciate the help, thanks again.

Inspiring
April 3, 2013

Scriptlistener or Action Manager code is really nothing that should be avoided. But if you really want an Object Model version this is the best I can offer.

app.runMenuItem(stringIDToTypeID('selectNoLayers'));