Layer group from folders or a text file

Community Beginner ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

This should be easy but like many things, in photoshop it's not.

I would like to load a series of images, and the folder names into group layers with the images inside the groups.

It's basically loading my file folder structure into a PSD file but there is no way to do that.

You can only load images using the stacks load script.

--

Does anyone know how to load folder structures as groups and the images in those sub-folders as groups?

I know this could be a problem but it was a simple csv file, there should be a way to automate this with script.

--

Thanks for any help

Frank

TOPICS
Actions and scripting

Views

2.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Feb 09, 2019 Feb 09, 2019
Perhaps this is what you wanted. var folder = null;try {     activeDocument;     folder = Folder.selectDialog("Select your folder", "C:\\");    }catch(e)    {    alert("No activeDocument", "");    }    if (folder)     {    refresh();            place_files(folder);    alert("Done!", "");         }        function place_files(folder)      {      try          {          var layer = activeDocument.activeLayer;            add_group(folder.name);        add_layer(folder.name);        layer = activeDo...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 04, 2018 Dec 04, 2018

Copy link to clipboard

Copied

Photoshop scripting shoul be able to do that.  Once you write the script it will be easy.

Write you own file stacking Script. Once you have stack the file select the layer you want to group and use action manager code to create a new layer group from the select.  You know menu Layer>New>Group From Layers... . You could stack a sub-folder of image at a time and use the sub-folder name as the Layer group name. Then do the next sub-folder of image files. Till all folders of source files have been processed.

The Image Processors scripts have code in it to Process a file system tree structure of image files.  You could look at the code in these scripts to see how to follow a file system structure and process the image files in that structure. Instead of Saving Files you would stacking image and create layer groups. Also read Load File  into stack script to see how it stacks image files into layers.

You will not find an other image editor that can be scripted as well as Photoshop.

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

Thank you JJMack for that reply, I did not know you could get access to the code of the script, that is a very valuable tip and way of approaching the coding side of Adobe Photoshop.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 09, 2019 Feb 09, 2019

Copy link to clipboard

Copied

Perhaps this is what you wanted.

var folder = null;

try {

    activeDocument;

    folder = Folder.selectDialog("Select your folder", "C:\\");

    }

catch(e)

    {

    alert("No activeDocument", "");

    }

   

if (folder)

    {

    refresh();

       

    place_files(folder);

    alert("Done!", "");    

    }       

function place_files(folder) 

    { 

    try 

        { 

        var layer = activeDocument.activeLayer;

   

        add_group(folder.name);

        add_layer(folder.name);

        layer = activeDocument.activeLayer;

        var f = folder.getFiles(); 

        for (var i = 0; i < f.length; i++) 

            { 

            if (f instanceof Folder)  

                {

                place_files(f); 

                activeDocument.activeLayer = layer;

                }

            else 

                if (f.name.match(/\.(psd|jpg|tif|png)$/i))

                    {

                    place_file(f);

                    }

            } 

        layer.remove();

        f = null; 

        } 

    catch (e) { alert(e); } 

    } 

function add_group(name)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putClass(stringIDToTypeID("layerSection"));

        d.putReference(stringIDToTypeID("null"), r);

        var d1 = new ActionDescriptor();

        d1.putString(stringIDToTypeID("name"), name);

        d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layerSection"), d1);

        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

        }

    catch (e) { alert(e); throw(e); }

    }

function add_layer(name)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putClass(stringIDToTypeID("layer"));

        d.putReference(stringIDToTypeID("null"), r);

        var d1 = new ActionDescriptor();

        d1.putString(stringIDToTypeID("name"), name);

        d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layer"), d1);

        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

        }

    catch (e) { alert(e); throw(e); }

    }

function place_file(file)

    {

    try {

        var d = new ActionDescriptor();

        d.putPath(stringIDToTypeID("file"), file);

        var doc = executeAction(stringIDToTypeID("openViewlessDocument"), d, DialogModes.NO).getData(stringIDToTypeID("document"));

        var d = new ActionDescriptor();

        var l = new ActionList();

        l.putPath(file);

        d.putList(stringIDToTypeID("fileList"), l);

        var l = new ActionList();

        l.putData(doc);

        d.putList(stringIDToTypeID("viewlessDoc"), l);

        executeAction(stringIDToTypeID("addLayerFromViewlessDoc"), d, DialogModes.NO);

        }

    catch (e) { alert(e); throw(e); }

    }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 11, 2019 Feb 11, 2019

Copy link to clipboard

Copied

WOW! WOW! WOW! that is super exactly what I needed, you're a genius thank you!!! r-bin

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2019 Dec 01, 2019

Copy link to clipboard

Copied

Hey Gents!

I'm really interested in this script but I don't know anything about coding at all. I'm interested in getting this script to work because it would allow me to export render layers from Maya and import them as photoshop layers with the folder name as the group name. It sounds perfect for my workflow. Any chance you can point me in the right direction to getting this script?

Thanks so much!
*edit remove name

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Do you get any answer ?  I need to do thisi too but I don't know how to use the script to import my folder structure. 

 

Thanks for any tips. 

Albert

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Thank you SO MUCH! I really appreciate your great help.

 

I'm just having one little issue and hopefully it's not much to ask, but whenever I run the script it loads the first image and makes the group, then throws an error saying TypeError: Undefined is not an object.

 

I'd appreciate the help so much and it would save me a lot of effort.

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

For some reason, this code is incorrect. Perhaps distorted when moving to a new forum.

Use this code (f is replaced by f [i])
for (var i = 0; i < f.length; i++)  
    {  
    if (f[i] instanceof Folder)   
        {
        place_files(f[i]);  

        activeDocument.activeLayer = layer;
        }
    else  
        if (f[i].name.match(/\.(psd|jpg|tif|png)$/i))
            {
            place_file(f[i]);
            }
    }  
 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Good script, but I made first attempt on psd with smart object in CS6 and it crashed Photoshop. Then in same release tried with non smart objects layers and it worked. I didn't check whether 'placed layers' make it doesn't work yet. Maybe that's a problem of something else or bug in CS6. I'll see and let know.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

can you please tell me how to use this script? 

 

Do i need to copy it to a file and save it as a script and then import it as a script in PS?

 

It would be awesome if you could help a felloow photoshop guy in Santa Barbara, CA 🙂 

 

Thanks 

Albert

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Yes, save to .jsx and run with Photoshop.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

what the hell is .jsx ? 🙂 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Ok so I open this script in a .jsx editor and save it to PS's script folder. 

 

If you give me a step by step I'll send you free turkish towels from my store. 

 

www.RivieraTowel.com

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

LATEST

No thx, all was already said 😉

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines