8 Replies Latest reply: Nov 19, 2010 4:56 PM by Robes Baum RSS

    Does anybody know how to remove all "copy" word from AI layers name line?

    Robes Baum

      I downloaded a PSD script that auto remove the word "copy" from all layers. Inside AI, I can't do that. Does anyone can help me? Here is the jsx PSD script file:

       

      ----------

       

      ///////////////////////////////////////////////////////////////////////////////
      // Script Name: RenameLayers.jsx
      // Version: 1.0
      // Date: 2/27/08
      // Usage: Removes 'copy 1, copy 2, etc' from name of all layers
      ///////////////////////////////////////////////////////////////////////////////

       

      #target photoshop
      //$.localize = true;
      var displayDialogMode = app.displayDialogs;

       

      app.bringToFront();
      app.bringToFront();
      app.displayDialogs = DialogModes.NO;

       

      processObjects(app.documents, processDocument,function () {alert("You have no documents open")})
      app.displayDialogs = displayDialogMode;

       

      ///////////////////////////////////////////////////////////////////////////////
      // Function: processObjects
      // Usage: Runs theMainFunction on every object in list theObjects
      // Input: List of objects (documents, layers, etc.), Function to run on each object, Function to run on parent if there are no object
      // Return: value returned from function used
      ///////////////////////////////////////////////////////////////////////////////
      function processObjects(theObjects, theMainFunction, theAlternateFunction) {
      var returnValue = null;
      if (theObjects.length ==0) {
      if (!(theAlternateFunction == undefined) && !(theAlternateFunction == null) && !(theAlternateFunction == "")) {
      returnValue = theAlternateFunction (theObjects.parent);
      }
      } else {
      if (!(theMainFunction == undefined) && !(theMainFunction == null) && !(theMainFunction == "")) {
      for (var i = theObjects.length -1; i> -1; i--) {
      returnValue += theMainFunction (theObjects[i], i);
      }
      }
      }
      return returnValue;
      }

       

      ///////////////////////////////////////////////////////////////////////////////
      // Function: processDocument
      // Usage: Processes layers of document with 'processLayer' function
      // Input: Document object, Document object index
      // Return: none
      ///////////////////////////////////////////////////////////////////////////////
      function processDocument(objectRef, i) {
      app.activeDocument = objectRef
      processObjects(objectRef.layers, processLayer, null);
      }

       

      ///////////////////////////////////////////////////////////////////////////////
      // Function: processLayer
      // Usage: Removes 'copy' from layer name (processes Layer Set contents)
      // Input: Layer object, Layer Object index
      // Return: none
      ///////////////////////////////////////////////////////////////////////////////
      function processLayer(objectRef, i) {
      if (objectRef.typename == 'LayerSet') {
      var layerCount = processObjects(objectRef.layers, processLayer);
      }
      renameLayer(objectRef)
      return 0
      }

       

      ///////////////////////////////////////////////////////////////////////////////
      // Function: renameLayer
      // Usage: Removes 'copy' from layer name (processes Layer Set contents)
      // Input: Layer object, Layer Object index
      // Return: none
      ///////////////////////////////////////////////////////////////////////////////
      function renameLayer(objectRef) {
      var theRegEx = new RegExp(/(\s*copy\s*\d*)+$/)

       

      if (theRegEx.test(objectRef.name)) {
      // save state of layer (visible or invisible)
      var layerVisible = objectRef.visible
      var indexNumber = 0
      indexnumber = objectRef.name.indexOf(" copy")
      objectRef.name = objectRef.name.substr(0,indexnumber)
      objectRef.visible = layerVisible
      }
      return 0
      }


      ----------

       

      Anyone?