Skip to main content
MohammadHosseini
Participating Frequently
April 8, 2022
Answered

Photoshop & Table

  • April 8, 2022
  • 2 replies
  • 1088 views

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

This topic has been closed for replies.
Correct answer Kukurykus

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


 

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'))

 

2 replies

Kukurykus
Legend
April 9, 2022

Post entire table.

MohammadHosseini
Participating Frequently
April 9, 2022

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

Kukurykus
Legend
April 9, 2022

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

Stephen Marsh
Community Expert
Community Expert
April 9, 2022

@MohammadHosseini 

 

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

 

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

 

 

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:

 

 

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

 

MohammadHosseini
Participating Frequently
April 9, 2022

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

Stephen Marsh
Community Expert
Community Expert
April 9, 2022

@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.