Copy link to clipboard
Copied
Hello,
I'm struggling to automate a task where a set of about 300 jpegs are opened, a gradient adjustment layer is added, linear, at a random angle, the gradient type is "noise", with transparency, 25% roughness, and randomized color option, then saved to a new jpeg.
I can get it all to work except for the randomization. I keep getting the same color combination, even though when recording the action I click "randomize" several times. I guess that doesn't work and it saves only that particular seed. I have tried looking everywhere for a script to that gets close to what I need, but haven't found any specific to this. I am very novice and can't even modify the scripts I have found with any success. Can anyone please point me in the right direction?
I should add, the "random angle" is not as critical as the "random colors" so that can be left out if it's not possible...
s2t = stringIDToTypeID;
(r = new ActionReference()).putClass(s2t("contentLayer"));
(d = new ActionDescriptor()).putReference(s2t("null"), r);
(d2 = new ActionDescriptor()).putUnitDouble(s2t("angle"), s2t("angleUnit"), Math.floor(Math.random() * 360));
d2.putEnumerated(s2t("type"), s2t("gradientType"), s2t("linear"));
(d3 = new ActionDescriptor()).putEnumerated(s2t("gradientForm"), s2t("gradientForm"), s2t("colorNoise"));
d3.putBoolean(s2t("showTransparency"), true);
d3.putInteger(s2t("smoothnes
...
Copy link to clipboard
Copied
s2t = stringIDToTypeID;
(r = new ActionReference()).putClass(s2t("contentLayer"));
(d = new ActionDescriptor()).putReference(s2t("null"), r);
(d2 = new ActionDescriptor()).putUnitDouble(s2t("angle"), s2t("angleUnit"), Math.floor(Math.random() * 360));
d2.putEnumerated(s2t("type"), s2t("gradientType"), s2t("linear"));
(d3 = new ActionDescriptor()).putEnumerated(s2t("gradientForm"), s2t("gradientForm"), s2t("colorNoise"));
d3.putBoolean(s2t("showTransparency"), true);
d3.putInteger(s2t("smoothness"), 1024);
d3.putEnumerated(s2t("colorSpace"), s2t("colorSpace"), s2t("RGBColor"));
d3.putInteger(s2t("randomSeed"), Math.random() * 10000000000000);
d2.putObject(s2t("gradient"), s2t("gradient"), d3);
(d1 = new ActionDescriptor()).putObject(s2t("type"), s2t("gradientLayer"), d2);
d.putObject(s2t("using"), s2t("contentLayer"), d1);
executeAction(s2t("make"), d, DialogModes.NO);
Copy link to clipboard
Copied
Hello,
As someone with very basic coding knowledge, I'm trying to adapt this to with pointing to a layer I'm pointing to directly, and not using thie stringID I don't understand.
Am I mistaken those s2t and direct pointing could be interchanged in the code? If I define the layer 2 in group 4 as groupChildArr :
var groupChildArr = app.activeDocument.layerSets[4].layers[2];
Could I use "groupChildArr" in place of each s2t or is your code creating a new gradient instead of modyfing a current gradient layer? Depending on it, I could possibly change how I work and have the code create the gradient instead of modyfing, I just am not proficient with those new action reference, descriptor, putclass, etc.
Currently mostly able to play with if, loops and such basic coding.
Copy link to clipboard
Copied
activeDocument.activeLayer = activeDocument.layerSets[4].layers[2];
updateActiveLayerGradient()
function updateActiveLayerGradient() {
s2t = stringIDToTypeID;
(r = new ActionReference()).putEnumerated(s2t("contentLayer"), s2t("ordinal"), s2t("targetEnum"));
(d = new ActionDescriptor()).putReference(s2t("null"), r);
(d2 = new ActionDescriptor()).putUnitDouble(s2t("angle"), s2t("angleUnit"), Math.floor(Math.random() * 360));
d2.putEnumerated(s2t("type"), s2t("gradientType"), s2t("linear"));
(d3 = new ActionDescriptor()).putEnumerated(s2t("gradientForm"), s2t("gradientForm"), s2t("colorNoise"));
d3.putBoolean(s2t("showTransparency"), true);
d3.putInteger(s2t("smoothness"), 1024);
d3.putEnumerated(s2t("colorSpace"), s2t("colorSpace"), s2t("RGBColor"));
d3.putInteger(s2t("randomSeed"), Math.random() * 10000000000000);
d2.putObject(s2t("gradient"), s2t("gradient"), d3);
d.putObject(s2t("to"), s2t("gradientLayer"), d2);
executeAction(s2t("set"), d, DialogModes.NO);
}
This code uses ActionManager objects. They can be thought of as normal DOM model objects (of type activeDocument, activeLayer), you just need to know that they use special functions to get and set values. That is, it is impossible to simply assign a value to a specific object - we must first specify the reference to it (like a path in intenral objects stucture), then enum all the values ​​that we want to put into it (using a certain structure), then specify which property of the object at this path we want to write and only after that execute a function that assigns a value 🙂
stringIDToTypeID is a function that gets the name of the property in text form from us, and returns its unique numeric representation so that Photoshop can quickly find it in the hash table.