PS script - I can not achieve a proper continuous selection

  • 1
  • Problem
  • Updated 2 years ago
I am trying to do performance improvments in my scripting and select multiple layers at once instead one by one.

This is my test case: http://sklad.bereza.cz/00-jarda/00_screenshot/2016-06-07_214102.jpg
This is what code from script listener did: http://sklad.bereza.cz/00-jarda/00_screenshot/2016-06-07_214232.jpg

It's somehow broken. "addToSelectionContinuous" should start from last "addToSelection" but it probably has start point from "slct"? My code:
// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc92 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref74 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref74.putName( idLyr, "Rectangle 1" );
    desc92.putReference( idnull, ref74 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc92.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list70 = new ActionList();
        list70.putInteger( 8 );
    desc92.putList( idLyrI, list70 );
executeAction( idslct, desc92, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc93 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref75 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref75.putName( idLyr, "Rectangle 1 copy 2" );
    desc93.putReference( idnull, ref75 );
    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelectionContinuous = stringIDToTypeID( "addToSelectionContinuous" );
    desc93.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelectionContinuous );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc93.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list71 = new ActionList();
        list71.putInteger( 8 );
        list71.putInteger( 9 );
        list71.putInteger( 10 );
    desc93.putList( idLyrI, list71 );
executeAction( idslct, desc93, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc94 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref76 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref76.putName( idLyr, "Group 1" );
    desc94.putReference( idnull, ref76 );
    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelection = stringIDToTypeID( "addToSelection" );
    desc94.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc94.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list72 = new ActionList();
        list72.putInteger( 8 );
        list72.putInteger( 9 );
        list72.putInteger( 10 );
        list72.putInteger( 18 );
    desc94.putList( idLyrI, list72 );
executeAction( idslct, desc94, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc95 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref77 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref77.putName( idLyr, "Rectangle 1 copy 7" );
    desc95.putReference( idnull, ref77 );
    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelectionContinuous = stringIDToTypeID( "addToSelectionContinuous" );
    desc95.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelectionContinuous );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc95.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list73 = new ActionList();
        list73.putInteger( 8 );
        list73.putInteger( 9 );
        list73.putInteger( 10 );
        list73.putInteger( 18 );
        list73.putInteger( 14 );
        list73.putInteger( 15 );
    desc95.putList( idLyrI, list73 );
executeAction( idslct, desc95, DialogModes.NO );
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 763 Posts
  • 157 Reply Likes

Posted 2 years ago

  • 1
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 141 Reply Likes
//////////////////////////////
//Select range of layers from active layer to supplied ID layer
////////////////////////////
function selectRange(toID) {
var desc3 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putIdentifier(charIDToTypeID('Lyr '), toID);
desc3.putReference( charIDToTypeID('null'), ref2 );
desc3.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') );
desc3.putBoolean( charIDToTypeID('MkVs'), false );
executeAction( charIDToTypeID('slct'), desc3, DialogModes.NO );
};
selectRange(13);
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 763 Posts
  • 157 Reply Likes
Thx for code, but this doesn't solve my problem. I want do multiple continuous selections. First one selection range and then second. And I want have unselected layers between this ranges.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 141 Reply Likes
In that case I would use this function.

function selectLayerById(ID,add){
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){}
};