Deselect all causes strange results later

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

paulemasters

Deselect all causes strange results later

Post by paulemasters »

PC PhotoShop CS3 on Windows 7 64 bit.

In a dialog I am giving the user the ability to specify how / what layers to select.
Select all layers or don't change the existing selection or select a total of some items they have entered starting at the top.

Perhaps I don't have to do this, but I was going to do the deselect all layers I got from the listener first to have a known starting point.

However, I discovered that:
When this is run, if no layers are selected - either by me or the deslectAllLayers call only the last layer in the 'list' is selected - in this case the fifth layer.
When this is run and deslectAllLayers call is commented AND there is at least one active/selected layer, then this selects the first 5 layers.

There must be something I don't understand (so what else is new?).

Here is my initial test.

Code: Select all#target PhotoShop
app.bringToFront();
main();
function main()
   {
//   deselectAllLayers();
   app.activeDocument.activeLayer = app.activeDocument.layers[0];
   var toLayerName = app.activeDocument.layers[4].name;
   activeLayerRange(toLayerName);
   }
//  Note: a beginning layer must be selected. 
function activeLayerRange(toLayerName)
   {
   var id18 = charIDToTypeID( "slct" );
   var desc5 = new ActionDescriptor();
   var id19 = charIDToTypeID( "null" );
   var ref4 = new ActionReference();
   var id20 = charIDToTypeID( "Lyr " );
   ref4.putName( id20, toLayerName );
   desc5.putReference( id19, ref4 );
   var id21 = stringIDToTypeID( "selectionModifier" );
   var id22 = stringIDToTypeID( "selectionModifierType" );
   var id23 = stringIDToTypeID( "addToSelectionContinuous" );
   desc5.putEnumerated( id21, id22, id23 );
   var id24 = charIDToTypeID( "MkVs" );
   desc5.putBoolean( id24, false );
   executeAction( id18, desc5, DialogModes.NO );
   }
//  Deselect all layers
function deselectAllLayers()
   {
   var id9 = stringIDToTypeID( "selectNoLayers" );
   var desc3 = new ActionDescriptor();
   var id10 = charIDToTypeID( "null" );
   var ref2 = new ActionReference();
   var id11 = charIDToTypeID( "Lyr " );
   var id12 = charIDToTypeID( "Ordn" );
   var id13 = charIDToTypeID( "Trgt" );
   ref2.putEnumerated( id11, id12, id13 );
   desc3.putReference( id10, ref2 );
   executeAction( id9, desc3, DialogModes.NO );
   }


Also if all layers are selected by me and the deslect is commented out, the first 5 layers are selected! But if the Select/Select all layers is used to select all layers, the first 5 are not selected and all the rest are.

However, if a group of layers are selected, then this works as desired - the first 5 layers are the only ones selected.

It's also interesting that the History only shows the Deselect Layers but not the other two commands.

Thanks for any thoughts.

Paul Masters