Copy link to clipboard
Copied
Hey guys. First posting here. 🙂
I simplify the problem a bit:
- There are 3 PSDs
- In each PSD there are 10 smart objects
- In each smart object there is one layer named e.g. "OUTLINE"
What do I want? I want to color of each OUTLINE layer to be changed (e.g. by layer style "color overlay").
As in the real life projekt there are about 10 psds containing about 700 smart objects in total, I reaaallyyy don't want to click every single smart object and apply the layer style by hand.
It would already easen the process if I had just to go through 10 PSDs.
The final idea is that I export each smart object (can I make this automatic as well? 😉 ) in OUTLINE color red, then blue, then ...brown. Whatever.
Can you help me? I am an absolute beginner in scripts, but I can handle actions. 🙂
I am working from a mac, but could change platform easily if needed.
Have a great day, thx, cheers
wulfgarrr
OK, although I tested, it appears that a last-minute addition to the base code broke the script, probably because I did not test to see if there was an existing layer style before attempting to clear it. Probably a newb mistake!
I have removed the function and call to clear layer styles, this should hopefully now work for you.
// Apply Layer Style To Content Of All Smart Object Layers.jsx
/*
community.adobe.com/t5/photoshop/how-to-action-script-for-changing-layer-styles-in-different-smart
...
Copy link to clipboard
Copied
Sounds Script-able and a platform-switch would seem unnecessary as the generally preferred Photoshop-Scripting-language JavaScript works on both Windoes and MacOS.
Could you provide sample-files?
But it’s possible I won’t have time to properly look into it until next weekend.
I am not sure how frequently the regulars of the former Photoshop Scripting Forum post on this Forum nowaways, so you might also try looking for help over on
Copy link to clipboard
Copied
From the month it's not possible to post on ps-scripts forum. Regular log in button vanished, and when logging by other and then trying to post something you find out the text area is too small to enter there anything. If you know how to contact Administrator, please do it.
Copy link to clipboard
Copied
Sorry, I don’t.
And sorry I posted a Link that is not usefull; I had assumed the Forum was still operational even though I had not been active there myself for a while.
Personally I suspect it was not a great decision to merge the old forums.adobe.com-Photoshop Scripting Forum with the general -Photoshop Forum.
Anway, as you already noticed this thread are you able to help the original poster at current?
Copy link to clipboard
Copied
Weekend starts for me too, but I hope r-bin to visit this thread soon.
Copy link to clipboard
Copied
Wow, thanks a lot for your fast responses. I didnt try to write on ps-scripts, yet. But as seen now, that's fine. 🙂
I create a sample. How do I upload sth?
Until then I used dropbox: https://www.dropbox.com/s/ag6u53ixgx2c30v/test%20overview%20Folder.zip?dl=0
Its not super urgent, but I'd love to hear your ideas/feedback on this matter when you find the time. ❤️
Have a great weekend
Cheers
Copy link to clipboard
Copied
If I can understand your question then things may be doable using actions. Can you confirm some facts:
You want to change color overlay for specific layer inside Smart Object layer.
You want to change color inside 10 smart object layers per document.
If I understand what you want then here are some questions since there are some requirements to fully automate process:
Do you have layers on which you want to change color overlay always named with the same name or, at least in the same relative position to top most or bottom most layer? If answer is yes then we can proceed, otherwise if you have random arranged layers to change color you can automate process with pause to select layer then to resume playing action.
Copy link to clipboard
Copied
I have looked at your sample file and this is all possible. The devil is in the details, your production files will not be exactly the same, which will require some changes to any sample code based on the test file.
(1) You will need to automatically target all of the smart object layers in the main PSD file: "test_rocks" and "test_trees" in your sample file. Will this be done by name, position in the layer stack, based on the layer content being a smart object etc? How will this be automated/repeated?
(2) Once you have the required smart object layer selected/targeted, then the following code can open the smart object:
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
(3) With the smart object layer file open, you will need to iterate/loop/cycle over all layers and change their colour by applying the desired colour overlay layer effect or some other method, then saving and closing the file.
var doc = activeDocument;
for(var i=0;i<doc.layers.length;i++){
try{
doc.activeLayer = doc.layers[i];
doc.activeLayer.applyStyle('Button'); // Change layer style name as required
}
catch(e){}
}
So, automating the colour change of the multiple embedded smart object layers in the parent linked smart object layers should not be too great a challenge – the main issue will probably be selecting the correct SO layers in the main file.
Building upon the previous two blocks of code, the following "proof of concept" code example will process a single targeted (SO) layer in the main PSD file and apply the layer style "Button" to all of the linked SO layer's embedded layers:
// Presuming that the appropriate SO layer is selected...
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
var doc = activeDocument;
for(var i=0;i<doc.layers.length;i++){
try{
doc.activeLayer = doc.layers[i];
doc.activeLayer.applyStyle('Button'); // Change layer style name as required
}
catch(e){}
}
doc.close(SaveOptions.SAVECHANGES);
Again, the key step is automating the selection of the multiple SO layers. It would be best if you could provide better info on your production files layer structure.
All of this is the first stage of the project... Then, the second stage would be changing the initial colour overlay style to other styles/colours.
Copy link to clipboard
Copied
Wow, thanks a lot for your incredible support.
To answer Bojan's questions:
You want to change color overlay for specific layer inside Smart Object layer. > YES
You want to change color inside 10 smart object layers per document. > YES, but more like 600 SO/doc.
Do you have layers on which you want to change color overlay always named with the same name or, at least in the same relative position to top most or bottom most layer? > They're always the top layer and always named "OUTLINE".
Thanks to you, Stephan, as well.
(1) How will this be automated/repeated? First layer in each SO everytime, AND I'd rename them "OULINE". But maybe thats not even neeeded if targeting first (or only) layer.
(2) … worked! ❤️
(3) … didn't work. The loop code results in a message "The command "Apply" is not currently available." What did I do wrong? I am really new to JS. I also tried to find a list for layer styles js code (e.g. color overlay + color input code), but I didnt find one yet. Maybe its also the wrong approach^^
Thank you so much for your support until now.
Copy link to clipboard
Copied
The code works for me if I have a smart object layer selected before running the 3rd combined "proof of concept" script... But I'm just a beginner.
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
The question remains:
How will you automate the selection of the linked smart object layers in the main file?
They are called "test_rocks" and "test_trees" in the sample file and they are linked smart objects and they are the bottom and next layer up in that test file. I'm guessing that the real production file is not the same.
Are you happy to manually select all of the layers, before the script loops through them all and adjusts everything else automatically?
Copy link to clipboard
Copied
Mh. SO layer selected (tried with test_tree SO and also with rock 4 SO), but I always receive the message "The command "Apply" is not currently available." What do I do wrong? I tried saving the code in an *.jsx and *.js file.
In the main file I'd love to also automate the selection of all the SOs … But if thats not possible I'd go through each manually. 😕 In the main file I will have abot 10 PSDs linked, in in them there will be up to 60 SOs each.
Copy link to clipboard
Copied
Do you have a layer style called "Button"?
Have you changed the script code to match your particular style name? If so, double-check the name of the style and the name in the script.
Try this version, it still references a style called "Button"...
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
var doc = activeDocument;
for (var i = 0; i < doc.layers.length; i++) {
try {
doc.activeLayer = doc.layers[i];
applyStyle(true);
function applyStyle(group) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
var reference2 = new ActionReference();
reference.putName(s2t("style"), "Button"); // Change style name here
descriptor.putReference(c2t("null"), reference);
reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("to"), reference2);
descriptor.putBoolean(s2t("group"), group);
executeAction(s2t("applyStyle"), descriptor, DialogModes.NO);
}
} catch (e) {}
}
doc.close(SaveOptions.SAVECHANGES);
Copy link to clipboard
Copied
I am sorry for my late reply. Somehow I didnt find the time until now.
Thanks a lot for your new script!
I dont have any layer style called "Button". Maybe that's the problem? I searched for code for layer styles, but didnt find them. Also tried the old ExtendScript Toolkit CC, but I dont really get it. 😄 Maybe this is a bit too much code for me. 😕
So, the script you send openes, when a SO layer is selected, the file behind it, and closes again. But there is no change.
Even if I type, very naiveley, "Stroke" nothing happens. But I could imagine that Stroke needs more information, e.g. color, size, etc.
Thanks for your support. I can hardly change or check the code you send, cause I dont know code. 😄 Maybe manually then … I am payed hourly^^
Copy link to clipboard
Copied
OK, perhaps this visual will help... I selected the layer style called "Button" as it was a factory default, which I hoped would exist on your system which would have made the testing/demo easy. So, you need to use the exact same layer style name in the script code as is found in the style panel.
If I remember your original sample file which I deleted a few days ago, your layer style was called OUTLINE or similar... So change "Button" to "OUTLINE" or whatever the required layer style is called, then test again.
Once you can successfully change one selected layer's linked/embedded smart objects using this script, we can then move forward into the discussion about how to automatically change all of the parent SO layers content...
Good luck!
Copy link to clipboard
Copied
And here is the final working code to automate everything!
// Apply Layer Style To Content Of All Smart Object Layers.jsx
/*
community.adobe.com/t5/photoshop/how-to-action-script-for-changing-layer-styles-in-different-smart-objects-in-different-documents/m-p/10879157
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework:
feedback.photoshop.com/photoshop_family/topics/rasterize_all_smart_objects_in_a_psd_file_to_shrink_down_its_size
*/
#target photoshop
var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");
////// Function to process all smart objects //////
function processSOLayers(theParent) {
for (var m = theParent.layers.length - 1; m >= 0; m--) {
var theLayer = theParent.layers[m];
// apply the funtion to layersets;
if (theLayer.typename == "ArtLayer") {
if (theLayer.kind == LayerKind.SMARTOBJECT) {
var theVisibility = theLayer.visible;
myDocument.activeLayer = theLayer;
////////// Start: Apply layer style to all child layers inside parent smart object layer //////////
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
var doc = activeDocument;
for (var i = 0; i < doc.layers.length; i++) {
try {
doc.activeLayer = doc.layers[i];
// Apply Cleaner Function
clearLayerStyle();
// Change layer style name as required
doc.activeLayer.applyStyle('Button');
} catch (e) {}
}
doc.close(SaveOptions.SAVECHANGES);
////////// Finish: Apply layer style to all child layers inside parent smart object layer //////////
// Reset visibility;
theLayer.visible = theVisibility;
};
} else {
processSOLayers(theLayer)
}
}
return
};
// Define Cleaner Function
function clearLayerStyle() {
var iddisableLayerStyle = stringIDToTypeID( "disableLayerStyle" );
var desc536 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref134 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref134.putEnumerated( idLyr, idOrdn, idTrgt );
desc536.putReference( idnull, ref134 );
executeAction( iddisableLayerStyle, desc536, DialogModes.NO );
}
Copy link to clipboard
Copied
Wow! Thank you so much for putting together every puzzle piece ❤️ Thats really awesome. I found the problem/solution:
I dont have a layer style called "Button". Maybe this is why nothing happens. I also didnt really think that you mean these layer styles! I didnt have in mind that there is this list. …
I was thinking of these layer styles: (so I was looking for "color overlay" etc. ;))
But no I got it! 😄 I just created my own layer style "Button".
I am still figuring out why I doesnt work … I'll keep oyu posted.
Copy link to clipboard
Copied
Dont know if it helps. I capured the mac results, and made a mobile video from the effects on the pc.
https://www.dropbox.com/sh/628gtdwsf3k24n5/AABVIlvxmwfmcZGQmZNr0OmGa?dl=0
As you see the results are different, and no layer styles, even named Button is applied. 😞
Copy link to clipboard
Copied
OK, although I tested, it appears that a last-minute addition to the base code broke the script, probably because I did not test to see if there was an existing layer style before attempting to clear it. Probably a newb mistake!
I have removed the function and call to clear layer styles, this should hopefully now work for you.
// Apply Layer Style To Content Of All Smart Object Layers.jsx
/*
community.adobe.com/t5/photoshop/how-to-action-script-for-changing-layer-styles-in-different-smart-objects-in-different-documents/m-p/10879157
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework:
feedback.photoshop.com/photoshop_family/topics/rasterize_all_smart_objects_in_a_psd_file_to_shrink_down_its_size
*/
#target photoshop
var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");
////// Function to process all smart objects //////
function processSOLayers(theParent) {
for (var m = theParent.layers.length - 1; m >= 0; m--) {
var theLayer = theParent.layers[m];
// apply the funtion to layersets;
if (theLayer.typename == "ArtLayer") {
if (theLayer.kind == LayerKind.SMARTOBJECT) {
var theVisibility = theLayer.visible;
myDocument.activeLayer = theLayer;
////////// Start: Apply layer style to all child layers inside parent smart object layer //////////
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
var doc = app.activeDocument;
for (var i = 0; i < doc.layers.length; i++) {
try {
doc.activeLayer = doc.layers[i];
// Change layer style name as required
doc.activeLayer.applyStyle('Button');
} catch (e) {}
}
doc.close(SaveOptions.SAVECHANGES);
////////// Finish: Apply layer style to all child layers inside parent smart object layer //////////
// Reset visibility;
theLayer.visible = theVisibility;
};
} else {
processSOLayers(theLayer)
}
}
return
};
Copy link to clipboard
Copied
Ohhh it worked! You were right! 😄 First time it worked. Awesome. I like scripts.
Thank you so much for your effort! I'll use it immidiately on the task. 🙂
Find more inspiration, events, and resources on the new Adobe Community
Explore Now