Hope the title does not sound to confusing.
What i’m trying to do with a script:
- Open Smart object layer in working file.
- Gets first layer name, makes first layer visible, updates smart object.
- Gets name and active layer from a group (color) from the main document.
- 2.Name + 3.Name and Saves as .png.
Please see my diagram attached plus the short screencast here: http://recordit.co/2QnBK0ZV2M
Thanks for any help!
#target photoshop
//This stores the currently active document to the variable mockupDoc
var mockupDoc = app.activeDocument;
//This stores Front.psd file's name so Photoshop can look for the active layers in the correct document.
var designDoc = app.documents.getByName("Front.psd");
//Gets the name of tha active layer of Front.psd
var designlayer = designDoc.activeLayer;
// getting the name and location;
var docName = mockupDoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*).[^.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = mockupDoc.path}
catch (e) {var docPath = "~/Desktop"};
// jpg options, But would love to save trough my Tiny png/jpg PS plugin instead PS native
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
// Saves the Mockup File containing the Name of the active layer in Front.psd
mockupDoc.saveAs((new File(docPath+'/'+basename + ' ' + designDoc.activeLayer.name +'.jpg')),jpegOptions,true);
Added my current code above. I’m struggling with the following tasks:
-
How can i check, which layer is active in layerset/group “Colors” of the mockupDoc document and store this as variable to use it for the name on saving?
-
I need the script to go trough each layer of Front.psd from top to bottom like : Start with top layer make only this layer visible -> save this doc -> return to mockup.psd -> save this file as jpg and png -> return to Front.psd and got to the next layer to repeat these steps (visible/save/previous doc/save png jpg/ and so on)? How would the script know, when the last layer has been processed and stop the script?
-
Right now the script saves the files in the root folder of mockup.psd. Is it possible to have folders in there by colors (i.e. red, yellow..) and check the file i want to save for the variable “colors” i stored earlier and save to the yellow folder if variable is yellow?
-
Hope this does not sound to weird, my english sucks 😉
Thanks everyone for your kind help.
2
Answers
Thank you @Mr Mystery Guest
I solved most of the tasks in the meantime and added my code below. Maybe some other users will find parts of it helpful or have better solutions.
Welcome to Stack Overflow. Normally we’d ask to see what code you’ve have written – even if it doesn’t work, just put in comments to explain what you are trying to do. Broken code is better than none at all when asking questions. But also remember that SO is not a script writing service.
Looping over layers is straight forward – avoid groups for now – that’s more advanced. Look around and you should find code to save out pngs.
This will get you started.