Copy link to clipboard
Copied
Hi,
Following some guides, I was able to mostly do the thing I want: recolor all shapes, one by one (because each shape can have different target color).
Looking at ScriptingListener, I found this part (I didn't try cleaning it yet, like removing the strokes, as I want it to work first):
var idsetd = charIDToTypeID( "setd" );
var desc1113 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref169 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref169.putEnumerated( idcontentLayer, idOrdn, idTrgt );
desc1113.putReference( idnull, ref169 );
var idT = charIDToTypeID( "T " );
var desc1114 = new ActionDescriptor();
var idFlCn = charIDToTypeID( "FlCn" );
var desc1115 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc1116 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc1116.putDouble( idRd, 90.038912 );
var idGrn = charIDToTypeID( "Grn " );
desc1116.putDouble( idGrn, 16.245135 );
var idBl = charIDToTypeID( "Bl " );
desc1116.putDouble( idBl, 28.404669 );
var idRGBC = charIDToTypeID( "RGBC" );
desc1115.putObject( idClr, idRGBC, desc1116 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc1114.putObject( idFlCn, idsolidColorLayer, desc1115 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc1117 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc1117.putInteger( idstrokeStyleVersion, 2 );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc1117.putBoolean( idfillEnabled, true );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
desc1114.putObject( idstrokeStyle, idstrokeStyle, desc1117 );
var idshapeStyle = stringIDToTypeID( "shapeStyle" );
desc1113.putObject( idT, idshapeStyle, desc1114 );
executeAction( idsetd, desc1113, DialogModes.NO );
The first ActionReference (169 in this case) should be responsible for which layer gets this change applied to (selected in this case).
I've tried changing it to:
var ref = new ActionReference();
// ref=.putIdentifier(s2t('layer'), getLayerProperty(index, 'layerID'));
ref.putIndex(s2t('layer'), index);
desc1113.putReference( idnull, ref );
Trying both the index and identifier (separately and together), trying "contentLayer" as class, etc etc.
But I can't get it to apply this effect on the layer (by index or identifier, doesn't really matter, as I can get both). Any help please?
I am not sure if whether applies here but not all operations can be run on unselected Layers.
So you might have to select the Layer first.
Some properties cannot be changed until you select layer. That is, you can read data from this layer using an index or identifier, but you cannot assign new parameters in the same way. You need to first select the layer.
In Photoshop script to iterate through all layers and change shape stroke size!??! thread, I wrote a script that changes the stroke width of shapes. You can look at the overall logic of the script and do the same just using a fill.
@c.pfaffenbichler, i only saw your answer
...Copy link to clipboard
Copied
I am not sure if whether applies here but not all operations can be run on unselected Layers.
So you might have to select the Layer first.
Copy link to clipboard
Copied
I didn't even think this could be the case.
Anyways, this code should do the trick? (the syntax is indeed terrible now, but it's the idea)
ref new ActionReference();
ref.putIndex('layer', index);
desc new ActionDescriptor();
desc.putReference(null, ref);
executeAction(s2t("select"), desc);
Copy link to clipboard
Copied
Some properties cannot be changed until you select layer. That is, you can read data from this layer using an index or identifier, but you cannot assign new parameters in the same way. You need to first select the layer.
In Photoshop script to iterate through all layers and change shape stroke size!??! thread, I wrote a script that changes the stroke width of shapes. You can look at the overall logic of the script and do the same just using a fill.
@c.pfaffenbichler, i only saw your answer after I posted mine 🙂
Copy link to clipboard
Copied
I'll look through that, thank you.
(I will mark the answer when I verify it works in my case, which might be a week or two).
Copy link to clipboard
Copied
As suggested by @c.pfaffenbichler and @jazz-y , the issue indeed was, that you can't change color by id, but you have to select the layer, and change it that way. If anyone else is looking at this, here's the code I've used:
function setLayerColor(index, rgb_color) {
selectLayer(index);
var ref = new ActionReference();
ref.putEnumerated(
s2t( "contentLayer" ),
s2t("ordinal"),
s2t("targetEnum")
);
var desc = new ActionDescriptor();
desc.putReference(s2t( "null" ), ref);
var desc_c = new ActionDescriptor();
desc_c.putDouble(s2t("red"), rgb_color.red);
desc_c.putDouble(s2t("grain"), rgb_color.green);
desc_c.putDouble(s2t("blue"), rgb_color.blue);
var desc3 = new ActionDescriptor();
desc3.putObject(
s2t("color"),
s2t("RGBColor"),
desc_c
);
var desc2 = new ActionDescriptor();
desc2.putObject(
s2t("fillContents"),
s2t("solidColorLayer"),
desc3
);
desc.putObject(
s2t("to"),
s2t("shapeStyle"),
desc2
);
executeAction(s2t("set"), desc, DialogModes.NO );
}
function selectLayer(index) {
var ref = new ActionReference();
ref.putIndex(s2t('layer'), index);
var desc = new ActionDescriptor();
desc.putReference(s2t( "null" ), ref);
executeAction(s2t("select"), desc, DialogModes.NO);
}
Copy link to clipboard
Copied
* you select a layer not by its ID (a unique identifier within a document), but by its index (a relative identifier whose value depends on the position of the layer in the palette). I don't know how you get the indexes, but just in case, check if the code works correctly if the document has or does not have a background layer.
Copy link to clipboard
Copied
Yes, that is correct. I used your (I believe it was) loop:
var start = getObjectProperty('document', 'hasBackgroundLayer') ? 0 : 1;
var end = getObjectProperty('document', 'numberOfLayers');
for(var i = start; i <= end; i++)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now