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

Rename Existing Layers with Data from CSV

Community Beginner ,
Aug 09, 2020 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();

TOPICS
Scripting

Views

444

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

Valorous Hero , Aug 09, 2020 Aug 09, 2020

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];
  }
}

Votes

Translate

Translate
Adobe
Valorous Hero ,
Aug 09, 2020 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];
  }
}

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

LATEST

Wow!! Perfect!!! Thank you so 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