Highlighted

Rename Existing Layers with Data from CSV

Community Beginner ,
Aug 09, 2020

Copy link to clipboard

Copied

Hi there! 

 

Im using this script from someone on here. The orginal script creates the layers and names them appropriately. 

 

I basically need the script to rename all the current layers with names from one cloumn in a csv file. My line in the code renames layer 2 but it stops because I'm only targeting the second item in the array [1]. How can I get it to rename all of the items in the array thus all of the layers? 

 

Thanks in advance!

 

var line,lay,myLayers = [];

var csvFile = File('/Users/user/Desktop/cells_for_scRNA-2.csv');

csvFile.open( 'r' );

while(!csvFile.eof){

line = csvFile.readln();

line = line.replace(',','_');

myLayers.push(line);

}

csvFile.close();

var doc = app.activeDocument;

for(var i = myLayers.length - 1; i > 0; i--){

 //og line -  lay  = doc.layers.add();

 //og line -  lay.name = myLayers[i];

// my line -  doc.layers[1].name = myLayers[i];

}

 

 

var oldLayer = doc.layers.getByName('Layer 1');

oldLayer.remove();

Adobe Community Professional
Correct answer by Silly-V | Adobe Community Professional

Try this:

var line,lay,myLayers = [];
var csvFile = File('/Users/user/Desktop/cells_for_scRNA-2.csv');
csvFile.open( 'r' );
while(!csvFile.eof) {
  line = csvFile.readln();
  line = line.replace(',','_');
  myLayers.push(line);
}
csvFile.close();
var doc = app.activeDocument;
var docLayers = doc.layers;
for (var i = 0; i < docLayers.length; i++) {
  if (i < myLayers.length) {
    docLayers[i].name = myLayers[i];
  }
}

Topics

Scripting

Views

45

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

Rename Existing Layers with Data from CSV

Community Beginner ,
Aug 09, 2020

Copy link to clipboard

Copied

Hi there! 

 

Im using this script from someone on here. The orginal script creates the layers and names them appropriately. 

 

I basically need the script to rename all the current layers with names from one cloumn in a csv file. My line in the code renames layer 2 but it stops because I'm only targeting the second item in the array [1]. How can I get it to rename all of the items in the array thus all of the layers? 

 

Thanks in advance!

 

var line,lay,myLayers = [];

var csvFile = File('/Users/user/Desktop/cells_for_scRNA-2.csv');

csvFile.open( 'r' );

while(!csvFile.eof){

line = csvFile.readln();

line = line.replace(',','_');

myLayers.push(line);

}

csvFile.close();

var doc = app.activeDocument;

for(var i = myLayers.length - 1; i > 0; i--){

 //og line -  lay  = doc.layers.add();

 //og line -  lay.name = myLayers[i];

// my line -  doc.layers[1].name = myLayers[i];

}

 

 

var oldLayer = doc.layers.getByName('Layer 1');

oldLayer.remove();

Adobe Community Professional
Correct answer by Silly-V | Adobe Community Professional

Try this:

var line,lay,myLayers = [];
var csvFile = File('/Users/user/Desktop/cells_for_scRNA-2.csv');
csvFile.open( 'r' );
while(!csvFile.eof) {
  line = csvFile.readln();
  line = line.replace(',','_');
  myLayers.push(line);
}
csvFile.close();
var doc = app.activeDocument;
var docLayers = doc.layers;
for (var i = 0; i < docLayers.length; i++) {
  if (i < myLayers.length) {
    docLayers[i].name = myLayers[i];
  }
}

Topics

Scripting

Views

46

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
Aug 09, 2020 0
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

Try this:

var line,lay,myLayers = [];
var csvFile = File('/Users/user/Desktop/cells_for_scRNA-2.csv');
csvFile.open( 'r' );
while(!csvFile.eof) {
  line = csvFile.readln();
  line = line.replace(',','_');
  myLayers.push(line);
}
csvFile.close();
var doc = app.activeDocument;
var docLayers = doc.layers;
for (var i = 0; i < docLayers.length; i++) {
  if (i < myLayers.length) {
    docLayers[i].name = myLayers[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
Reply
Loading...
Aug 09, 2020 0
Community Beginner ,
Aug 09, 2020

Copy link to clipboard

Copied

Wow!! Perfect!!! Thank you so much!!

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
Reply
Loading...
Aug 09, 2020 0