• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

3.3K

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

People's Champ , 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

...

Votes

Translate

Translate
Adobe
Community Expert ,
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

Votes

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.

Votes

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
People's Champ ,
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); }

    }

Votes

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

Votes

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

Votes

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

Votes

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!

Votes

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
People's Champ ,
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]);
            }
    }  
 

Votes

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 ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Hello @r-bin ! This script is almost exactly what I am needing. Would it be possible to show me where to tweak it in order to import the files without their extension in the name (jpg/png/etc.)? 

I also noticed that the files gets imported being rasterized instead of smart objects. Is there a way to import them directly as smart objects?

Thanks a lot! 

Votes

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 ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

This made it work!  Thanks r-bin!  As a helper to others:  Paste the code into a code editor, such as Sublime.  Replace the matching code with snippet above to fix it.  Save out with extention .jsx.  With a file open in PS, to run it: in PS File drop down menu, click Scripts, then Browse.  Select your folder.  Done.  This is how I did it in PS 2024 R25.7.

Votes

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 ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

...I forgot to add:  After Browse, select the .jsx file that you created first, then select the folder structure to process.

Votes

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 ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

LATEST

One other thing about r-bin's script.  It adds all hidden folders as well.  I haven't been able to figure out yet how to filter out those in the script.  I guess that I'll have to learn a bit of this scripting language.

Votes

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
LEGEND ,
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.

Votes

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

Votes

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
LEGEND ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Yes, save to .jsx and run with Photoshop.

Votes

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 ? 🙂 

Votes

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
LEGEND ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Votes

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

Votes

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
LEGEND ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

No thx, all was already said 😉

Votes

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