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

How do i rename image layers(?) across the whole project using scripts?

New Here ,
Nov 12, 2022 Nov 12, 2022

Copy link to clipboard

Copied

Hi

I have a puppet i've made for Character Animator with 5 head views, each one having 2 sets of mouth layers. Within each mouth layer there are different layers for each sound, and inside the layer there is an image layer (not sure if it is considered a layer but i don't know what to call it) and another background layer.

I think I have rigging issues because the image inside the layer has the same name as the layer. Something like this:

Mouth Layer

    - Ah

        - Ah

        - background

 

It's a bit of a pain to rename them all manually as there are so many so i'm trying to use a script. I am a Javascript developer by trade so it's not a problem but i'm having trouble finding the names of properties to target.

I found a script which works with layers here (link below) but that does the parent layer rather than the image inside.

https://github.com/seblavoie/adobe-illustrator-layer-renamer

 

I tried modifying it to this but it doesn't work as i'm kind of guessing about what to target:

 

 

var LayerRenamer, layerRenamer;

LayerRenamer = (function() {
  function LayerRenamer() {
    if (app.activeDocument.selection.length > 0) {
      this.replacements = [prompt("What would you like to replace?", "Eg: source"), prompt("What would you like to replace it with?", "Eg: replacement")];
      this.renameLayers(app.activeDocument.selection);
    } else {
      alert("Select the layers you would like to be renamed.");
    }
  }

  LayerRenamer.prototype.renameLayers = function(layers) {
    var layer, placedItems, placedItem, name, _i, _j, _len, _results;
    _results = [];
    for (_i = 0, _len = layers.length; _i < _len; _i++) {
      layer = layers[_i];
      placedItems = layer.placedItems;
      placedItem = placedItems[0].placedItem

      name = placedItem.name;
      _results.push(layer.name = name.replace(this.replacements[0], this.replacements[1]));
    }
    return _results;
  };

  return LayerRenamer;

})();

layerRenamer = new LayerRenamer();

 

 
I imported all the mouth layers from another puppet (provided by Adobe i think) but I don't think they're linked.
 
Can anyone help?
 
Thanks
TOPICS
Scripting

Views

86

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
community guidelines
Advisor ,
Nov 12, 2022 Nov 12, 2022

Copy link to clipboard

Copied

You need to show a screenshot of you fully expanded layers panel. 

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
community guidelines
Community Expert ,
Nov 12, 2022 Nov 12, 2022

Copy link to clipboard

Copied

What @femkeblanco already said.

And furthermore:

Are we talking here about layers, with (deeply?) nested sublayers, (deeply?) nested groups, placedItems, pathItems, compoundPathItems, clipping groups … ?

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
community guidelines
New Here ,
Nov 13, 2022 Nov 13, 2022

Copy link to clipboard

Copied

Peter27059219p74j_0-1668344108804.png

Here's a screenshot of a few of the expanded nodes within 1 of the head views, does this show what is needed? Is there an easy way find out what type of layer something is? I can't find anything to indicate that in illustrator and i've looked online. If i delete the name of the layer/group it tells me then.

 

The top layer +BigLady is a Layer,

Head is a layer,

each profile within head (+Right Quarter etc) is a layer, 

+Mouth is a group,

each vowel parent (top layer D, Ah etc) is a group,

and the duplicate name i want to rename that's inside is an image (just shows up as <image> if i delete the name)

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
community guidelines
Advocate ,
Nov 13, 2022 Nov 13, 2022

Copy link to clipboard

Copied

Bonjour, Si cela peut vous aider...

Supprime les noms doubles entre layer et layer.pageItems[0], seul pageItems est modifié.

 

// JavaScript Document
// change name p0 in layer.js
// Supprime les noms doubles entre layer et layer.pageItems[0], seul pageItems est modifié.
// Removes double names between layer and layer.pageItems[0], only pageItems is changed.
// INIT ------------------
var replace = "";
// -----------------------
var docRef = app.activeDocument;
var tabs = [];
    change_name_p0_in_layer(docRef,replace);
    alert("changed names =\r\r" + tabs.join("\r"))
//------
function change_name_p0_in_layer(relativeObjet,replace)
{
   for (var i = 0 ; i < relativeObjet.layers.length ; i++) {
      change_name_p0_in_layer(relativeObjet.layers[i],replace);
      var Layeri = relativeObjet.layers[i];
      var LayeriName = Layeri.name;

     try {
       if (Layeri.pageItems.length > 0) {
         var obj = Layeri.pageItems[0];
          if (obj.name == LayeriName) {
            tabs.push([ obj.typename,obj.name]);
            obj.name = replace;
          }
      }
     }
     catch(e) {
        alert( e.message, "Alerte de script");
     }
   }
}
//------

 

René

PS Pour constater les modifications et mettre à jour le panneau "Calques", faire un clic sur la zone de travail.

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
community guidelines
Community Expert ,
Nov 13, 2022 Nov 13, 2022

Copy link to clipboard

Copied

Please select one image and run this snippet:

 

alert(app.activeDocument.selection[0].typename);

 

 

Do you get a PlacedItem or RasterItem? That is important!

 

For the parent, you can extend this snippet with:

 

alert(app.activeDocument.selection[0].typename);
alert(app.activeDocument.selection[0].parent.typename);
alert(app.activeDocument.selection[0].parent.name);

 

 

Ilustrator only has layers and objects (items).

Layers are top level layers app.activeDocument.layers[n] and sublayers app.activeDocument.layers[n].layers[m] and so on.

 

Items are pageItems or pathItems or compoundPathItems or all the other things like symbols or images (linked or embed) ... and so on. These can be in layers or sublayers or nested sublayers or groups or nested groups or a combination of all of these.

 

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
community guidelines
Advisor ,
Nov 13, 2022 Nov 13, 2022

Copy link to clipboard

Copied

LATEST

I think @renél80416020's script works based on the assumption that "+Mouth" and the top "Ah" are layers, whereas you implied that they are groups, so you see why one needs to be specific.  One way of knowing what an object is is to open the appearance panel: when you click an object's target circle (on the right-hand side in the layers panel), the appearance panel tells you what it is (layer, group, path, et cetera).  My assumption is your hierarchy is something like this

 

+Right Quarter (layer)
    +Mouth (group)
        Ah (group)
            Ah (?image)
            <Path> (path)

 

What I am less clear about is what you want the script to do.  Do you want to change the bottom "Ah" to something?  Or do you want to change an unnamed <image> to "Ah"?

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
community guidelines