Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Target action in javascript to specific layer instead of current layer

New Here ,
May 01, 2020 May 01, 2020

I am trying to set the tag color of a lyer in Photoshop. For this I used the action script listener and got the result below which is for the current selected layer. From an example I found on internet but for getting the current tag color I modified:

 

    ref10.putEnumerated( idLyr, idOrdn, idTrgt );

 

to

 

      ref10.putIdentifier(idLyr , layer.id );
 

 

But this still targets the currently selected layer, not the LayerSet one I passed via layer

 

Any hints would be welcome. Unfortunately I found no information about modifying logged actions for current layer for addressing a specific layer via its id.

 

// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc33 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref10 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref10.putEnumerated( idLyr, idOrdn, idTrgt );
desc33.putReference( idnull, ref10 );
var idT = charIDToTypeID( "T " );
var desc34 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var idClr = charIDToTypeID( "Clr " );
var idVlt = charIDToTypeID( "Vlt " );
desc34.putEnumerated( idClr, idClr, idVlt );
var idLyr = charIDToTypeID( "Lyr " );
desc33.putObject( idT, idLyr, desc34 );
executeAction( idsetd, desc33, DialogModes.NO );

TOPICS
Actions and scripting
4.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
LEGEND ,
May 02, 2020 May 02, 2020

That may be the reason, at least this one time I'm excused.

You know that 'property' thing, common for you both 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 02, 2020 May 02, 2020

In most cases, DOM and AM have the same interaction features with objects that are accessible to the user through the Photoshop interface. In other words, if you cannot change the color of the layer label in the Photoshop interface without selecting it, then with a high probability it will not be possible to do this using a script.

 

If you have a pre-compiled array with laуerIDs, then the fastest way is not to select each layer separately, but to select all the necessary layers at once:

 

    function selectLayerByIDList (IDList) {
        var ref = new ActionReference()

        for (var i = 0; i < IDList.length; i++) {
            ref.putIdentifier(s2t("layer"), IDList[i])
        }

        var desc = new ActionDescriptor()
        desc.putReference(s2t("null"), ref)
       // desc.putEnumerated(s2t("selectionModifier"), s2t("addToSelectionContinuous"), s2t("addToSelection"))

        executeAction(s2t("select"), desc, DialogModes.NO)
    }

    function s2t(s) { return stringIDToTypeID(s) }

 

 

after that, apply the function with the assignment of a color label - it will be assigned to all layers in the current selection.

 

$.hiresTimer;
s2t = stringIDToTypeID;

(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
ref.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(ref).getInteger(p)

var ids = []
for (var i = 1; i <= len; i++) {
    (ref = new ActionReference()).putProperty(s2t('property'), p = s2t('layerID'));
    ref.putIndex(s2t('layer'), i);
    ids.push(executeActionGet(ref).getInteger(p))
}

selectLayerByIDList(ids)
setLayerLabelCol('violet') 

alert ($.hiresTimer);

function selectLayerByIDList(IDList) {
    var ref = new ActionReference()
    for (var i = 0; i < IDList.length; i++) { ref.putIdentifier(s2t('layer'), IDList[i]) }
    (desc = new ActionDescriptor()).putReference(s2t('null'), ref)
   // desc.putEnumerated(s2t('selectionModifier'), s2t('addToSelectionContinuous'), s2t('addToSelection'))
    executeAction(s2t('select'), desc, DialogModes.NO)
}

function setLayerLabelCol(labelCol) {
    /*
        No Color = "none"
        Red = "red"
        Orange = "orange"
        Yellow = "yellowColor"
        Green = "green"
        Blue = "blue"
        Violet = "violet"
        Gray = "gray"
    */
    (ref = new ActionReference).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
    (desc = new ActionDescriptor()).putReference(s2t('null'), ref);
    (desc1 = new ActionDescriptor()).putEnumerated(s2t('color'), s2t('color'), s2t(labelCol));
    desc.putObject(s2t('to'), s2t('layer'), desc1);
    executeAction(s2t('set'), desc, DialogModes.NO);
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 02, 2020 May 02, 2020

desc.putEnumerated(s2t("selectionModifier"), s2t("addToSelectionContinuous"), s2t("addToSelection"))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 02, 2020 May 02, 2020

Well, yes, there isn’t much sense in this line.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 02, 2020 May 02, 2020

Some properties can only be set for the active layer. These include, for example, the name and color of the layer.
In the DOM model fiction occurs, because the target layer temporarily becomes active, and this is done incorrectly. The layer visibility may will turn on and the current selections of layers will be removed.

 

UPD.

It is better to set such properties immediately when creating a layer (with the "make" command).
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2020 May 03, 2020
LATEST

Ok, thanks to all the posters! Very much appreciated.

 

I see I need to give some more details. At first I was writing code to export icons automatically by showing and hiding layers. This code was building the entire layer tree using javascript classes for later processing and generating of the icons.  This code may actually benefit from AM code, but... (see below).

 

The current project (linked to the first one) uses the same code to build the  javascript via DOM but then needs to generate and modify a lot of layers. As this code requires quite a lot of information provided by th eDOM, generating the tree with the DOM may be not so bad (i.e. AM not winning that much time).

 

But my base question remains, is there any reliable documentation of AM ? Just using the listener is not a good approach.

 

For instance do I understand you correctly that it would be possible to set layer name, placement and color in one single MAKE action ? Or do you refer "only" that it woul dbe better to do this all while it is selected from the MAKE anyway?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines