Copy link to clipboard
Copied
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
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 );
Copy link to clipboard
Copied
That may be the reason, at least this one time I'm excused.
You know that 'property' thing, common for you both 😉
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
desc.putEnumerated(s2t("selectionModifier"), s2t("addToSelectionContinuous"), s2t("addToSelection"))
Copy link to clipboard
Copied
Well, yes, there isn’t much sense in this line.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more