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.

MarkWalsh
MarkWalshAuthor
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'));


Oh, I have no problem with using Scriptlistener code, I just prefer to use a built-in command to do something whenever one is available.

On a side note, I have run into at least a few scripts which were all scriptlistener, which used all avialable commands, and could have been done with a just few simple lines of readable code.

Thanks again.