Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 82585

Rename all layers

$
0
0

Hi!

 

I've a problem to solve this issue.

I need to rename a lot of layers (near 1000).

 

I've found 2 scripts.

First select object in the document, I've little edit it to cycle selection and remove selection. Here the result:

 

// Adobe Illustrator CC Scripting
// Select and rename layers

var i, j, k, l;
if (app.documents.length > 0) {  var doc = app.activeDocument;  if (doc.selection.length == 0) {  for (i = 0; i < doc.pageItems.length; i++) {  //Select object  doc.pageItems[i].selected = true;  // HERE I NEED TO RENAME SELECTED LAYER, BEFORE "remove selection".  //   ????  //Remove selection  doc.pageItems[i].selected = false;  }  }
}

Second script make me able to create var "pixelArea" of each object. I need to put that value at the end of each layer name.

I try to put that between in the red area, but give me loop, so Illustrator die.

 

if (app.documents.length > 0) {  if (app.activeDocument.selection.length < 1) {    alert('Select a path first');  }  else if (app.activeDocument.selection[0].area) {    var objects =  app.activeDocument.selection;  }  else if (app.activeDocument.selection[0].pathItems) {    var objects = app.activeDocument.selection[0].pathItems;  }  else {   alert('Please select a path or group.');  }  var pixelArea = 0;  for (var i=0; i<objects.length; i++) {  if (objects[i].area) {  var pixelArea = pixelArea + objects[i].area;  if (pixelArea < 0) var pixelArea = -pixelArea;  // HERE WE HAVE pixelArea VAR. NEED TO ADD THIS VALUE AT THE END OF SELECTED LAYER NAME  // SOMETHING LIKE THAT: layer[n].name = layer[n].name + "-" + pixelArea;  }  }
}

Both works (selection/remove selection and area calc, I don't find orking solution for layer name change), but when I combine them together generates the loop.

I'm new with Illustrator scripts, every help could be appreciate.

 

Really thanks!


Viewing all articles
Browse latest Browse all 82585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>