1 Reply Latest reply on May 29, 2015 4:26 AM by Sebastien Lavoie

    Regexp rename a layer from its unique symbol's name

    Franck Payen MVP & Adobe Community Professional

      Hi there, just wanted to contribute if it can help.


      I had this Ai structure:







      and I wanted to have:








      So i tweaked the RenameLayers.jsx script from Sebastien Lavoie to use regex AND to insert the symbol's name at the right place.


      // Generated by CoffeeScript 1.7.1
      #target "illustrator-18";
      var LayerRenamer, layerRenamer;
      LayerRenamer = (function () {
        function LayerRenamer() {
        if (app.activeDocument.selection.length > 0) {
        this.replacements = [new RegExp(prompt("Where would you like to replace via RegExp?", "Eg: source S12 (S\\d\\d)")), prompt("What would you like to replace it with?", "Eg: replacement $1")];
        } else {
        alert("Select the layers you would like to be renamed.");
        LayerRenamer.prototype.renameLayers = function (layers) {
        var layer, name, _i, _len, _results, symbolName;
        _results = [];
        symbolName = "";
        for (_i = 0, _len = layers.length; _i < _len; _i++) {
        layer = layers[_i];
        layer = layer.parent;
        if (layer.pageItems.length == 1) {
        symbolName = layer.pageItems[0].symbol.name;
        name = layer.name;
        _results.push(layer.name = name.replace(this.replacements[0], (this.replacements[1] + "-" + symbolName)));
        return _results;
        return LayerRenamer;
      layerRenamer = new LayerRenamer();



      Hope this can help someone.


      PS: no, this was not a question.

      PPS:  Of course the real use case had more than 3 layers, and more than one document, I would have done it faster by hand.