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

Photoshop & Table

Community Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

Hi Dears
How can I read layer names and group names from a table automatically in Photoshop?

I want automatic create empty layers and empty groups in photoshop from a table.

Photoshop version: 2021

Platform: Win 10

Regards

TOPICS
Actions and scripting , Windows

Views

507

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

LEGEND , Apr 09, 2022 Apr 09, 2022

 

with(File('~/desktop/Country GroupName.txt'))
	open('r'), r = read(), close(); arr = r.split('\n')
aD = documents.add(), sTT = stringIDToTypeID
runMenuItem(sTT('screenModeFullScreen'));
(wndw = new Window('palette'))
txt = wndw.add('statictext',
undefined, arr.length)
wndw.show()

while(arr.length) {
	a = 4; if (pop = arr.pop()) {
		with(aD.layerSets.add()) {
			name = pop; while(a--)
				artLayers.add()
		}
	}

	txt.text = arr.length, wndw.update()
}

wndw.close(), runMenuItem(sTT('collapseAl
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

@MohammadHosseini 

 

As nobody has answered yet, to get the ball rolling...

 

A simple text file on the desktop, named "layerName.txt":

 

inputFile.png

 

Sample code:

 

var inputFile = File('~/Desktop/layerName.txt');
if (inputFile.exists && inputFile.length > 0) {
    // Open the input file: r = read mode | w = write mode | a = append | e = edit
    inputFile.open('r');
    // Read the value
    var inputFileValue = inputFile.read();
    // Create the layer
    activeDocument.artLayers.add();
    // Name the layer
    activeDocument.activeLayer.name = inputFileValue;
    // Close the input file
    inputFile.close();
} else {
    alert('There was an error reading the input file!');
}

 

The result:

 

result.png

 

This is a simplified example, you will need to process multiple lines (breaking them on return/newline or comma-separated values) and create layers or layer sets from each line as desired. You could "flag" the line in the text file as either being a layer or layer set and process accordingly. You may also need to nest and or move layers in the stack or possibly do other things that have not been mentioned.

 

Good luck!

 

EDIT: A quick search kicked this up, which may help you with processing multiple lines in the input file:

https://www.rapiddg.com/article/manipulating-photoshop-layers-using-javascript

 

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

Copy link to clipboard

Copied

Thank you, dear friend
Yes, exactly I need a very simple tool. That I can create a lot of layers without rewriting.
This worked but puts all existing text in the "layerName.txt" file as the layer name.
while I want to separate, for example, with a comma or line by line.

With Sincere Appreciation

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 Expert ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied


@MohammadHosseini wrote:

This worked but puts all existing text in the "layerName.txt" file as the layer name.
while I want to separate, for example, with a comma or line by line.

 

Indeed, this is why I wrote:

 

"you will need to process multiple lines (breaking them on return/newline or comma-separated values) and create layers or layer sets from each line as desired."

 

Do you know how to write JavaScript?

 

I'll work on a further example for multiple layers/sets.

 

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

Copy link to clipboard

Copied

Thanks, Stephen
Unfortunately, I'm not a Java user.
Yes, I mean multiple lines.
Without commas
According to the picture

Multiple lines.png
I look forward to the future.
Thank you again

 

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 Expert ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

I mostly have the multi line/layer version working for you. I'll post it tomorrow as bed is calling...

 

I'm curious about your workflow, where do the text file lists come from? Why?

 

Can you post a screenshot of the layer panel stack end result of such a workflow?

 

My example will use two empty layers and a single empty group/set.

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

Copy link to clipboard

Copied

I create group names in Excel. There are usually many of them. (About 200) Then I use the same names in naming groups in Photoshop. Also, three or four raw layers whose names do not matter. It may sound silly, but it's both fun and time-saving, and it also makes data control easier.
Glad it caught your attention.
Thank you very much

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 Expert ,
Apr 09, 2022 Apr 09, 2022

Copy link to clipboard

Copied

LATEST

@MohammadHosseini 

 

Thank you for providing more information.

 

I'm glad that @Kukurykus posted while I was sleeping, it would have taken much more time and effort to come up with the result that you wanted with the layers nested into the sets. I may look into that as a learning exercise, but for now, you have a another solution.

 

For what it is worth, I may as well post the code anyway as I put some time and effort into it and it may help somebody else in the future. I have adjusted the code based on your comments posted overnight, as you previously didn't mention that the majority of the entries were for layer sets. Layers need to be prefixed with a hyphen - character so that the script knows to create a layer rather than a set. Here is an example of the text file:

 

My Layer Set Name 1
-My Layer Name 1
My Layer Set Name 2

 

 

And here is the result:

result2.png

 

The code:

 

/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-amp-table/td-p/12867557
Based on:
https://feedback-readonly.photoshop.com/conversations/photoshop/photoshop-each-line-of-text-to-a-new-layer-shortcut/5f5f461e4b561a3d42747570
Note: Names with a leading hyphen placeholder character will be created as layers, otherwise layer sets are the default
*/

#target photoshop

if (documents.length > 0) {
    var textFile = new File('~/Desktop/layerName.txt');

    if (textFile.exists && textFile.length > 0) {

        // Open the input file: r = read mode | w = write mode | a = append | e = edit
        textFile.open('r');
        // Read in the text file
        var textLine = textFile.readln();

        // Loop over the text file contents, one line at a time
        while (textLine !== '') {

            // Create layer from a leading - hyphen
            if (textLine.match(/^-/)) {
                var newLayer = activeDocument.artLayers.add();
                // Layer name from the text file, removing the leading - hyphen
                newLayer.name = textLine.replace(/^-/, '');
                // Read in the next line from the text file
                textLine = textFile.readln();
            // Create layer set
            } else {
                var newSet = activeDocument.layerSets.add();
                // Layer name from the text file
                newSet.name = textLine;
                // Read in the next line from the text file
                textLine = textFile.readln();
            }
        }
        textFile.close();
    }

} else {
    alert('You must have a document open to run this script.');
}

 

 

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

Copy link to clipboard

Copied

Post entire table.

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

Copy link to clipboard

Copied

In this table, the names of the countries are used to name the groups.
Also four raw layers
Thanks for your attention

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

Copy link to clipboard

Copied

So all of them are names of countries, from which each as group has to contain four layers?

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

Copy link to clipboard

Copied

I want to create groups called countries (Country Names) and also create 4 anonymous layers within groups.

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

Copy link to clipboard

Copied

 

with(File('~/desktop/Country GroupName.txt'))
	open('r'), r = read(), close(); arr = r.split('\n')
aD = documents.add(), sTT = stringIDToTypeID
runMenuItem(sTT('screenModeFullScreen'));
(wndw = new Window('palette'))
txt = wndw.add('statictext',
undefined, arr.length)
wndw.show()

while(arr.length) {
	a = 4; if (pop = arr.pop()) {
		with(aD.layerSets.add()) {
			name = pop; while(a--)
				artLayers.add()
		}
	}

	txt.text = arr.length, wndw.update()
}

wndw.close(), runMenuItem(sTT('collapseAllGroupsEvent'))

 

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

Copy link to clipboard

Copied

Thank you, Dear Kukurykus
Thank you, Dear @Stephen_A_Marsh 
I was very, very happy that it worked, although an interesting mistake occurred that did not matter.
A group was created for each line value in the "Country GroupName.txt" file same name, and four layers were created for each group.
This is very interesting.
Regards
Country GroupName.pngDo IT.png

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

Copy link to clipboard

Copied

Isn't it what you wanted: "also create 4 anonymous layers within groups."?

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

Copy link to clipboard

Copied

This is exactly what I wanted. Perfect and lovely

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