1 Reply Latest reply on Jul 9, 2015 5:37 PM by Qwertyfly...

    Swatch Replacement Script - works in CS6 but not CC

    ZINGERERs

      Hi All,

       

      I've been using this javascript to batch replace specific swatches. It works great in CS6 but I get the following  error message in CC. Any help much appreciated. Thanks!

       

      Message:

      Error 1200: an illustrator error occurred: 1346458189 ('MRAP)

      Line:76

      -> if (fillColor.spot.name == 'Orange TEMP') fillColor = replaceColor1;

       

      Script:

       

      var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, svgSaveOpts;

       

      // Select the source folder.

      sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to SVG', '~' );

       

      // If a valid folder is selected

      if ( sourceFolder != null )

      {

        files = new Array();

        fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );

       

        // Get all files matching the pattern

        files = sourceFolder.getFiles( fileType );

       

        if ( files.length > 0 )

        {

        // Get the destination to save the files

        destFolder = sourceFolder;

        for ( i = 0; i < files.length; i++ )

        {

        sourceDoc = app.open(files[i]); // returns the document object

       

        // Call function getNewName to get the name and file to save the SVG

        var doc = app.activeDocument;

      clearLayerOverrides(doc);

       

      function clearLayerOverrides(doc){

          var layers=doc.layers;

          for(var i=0;i<layers.length;i++){

          if (!layers[i].visible){

             layers[i].visible=true;

           }

          if (layers[i].locked){

             layers[i].locked=false;

           }

         }

       

       

       

       

      getInfoC = app.activeDocument.pageItems;

       

      for ( a = 0; a < getInfoC.length; a++ )

      {

           try {

                      getInfoC4 = getInfoC[a];

                      getInfoC4.locked = false;

                  } catch (e) {}

      }

      }

        app.paste()

        app.cut()

        targetFile = recoloring();

       

       

       

       

        sourceDoc.save();

       

       

        sourceDoc.close();

        }

        }

        else

        {

        alert( 'No matching files found' );

        }

      }

       

       

      function recoloring()

      {

        var docRef = app.activeDocument;

                 with (docRef) {

                    var replaceColor1= swatches.getByName('New Orange 123').color;

       

      for (var i = 0; i < pathItems.length; i++) {

      with (pathItems[i]) {

      if (filled == true && fillColor instanceof SpotColor) {

      if (fillColor.spot.name == 'Orange TEMP') fillColor = replaceColor1;

      }

      if (stroked == true && strokeColor instanceof SpotColor) {

      if (strokeColor.spot.name == 'Orange TEMP') strokeColor = replaceColor1;

      }

      }

      }

       

      for (var j = 0; j < stories.length; j++) {

      with (stories[j]) {

      for (var k = 0; k < characters.length; k++) {

      with (characters[k].characterAttributes) {

      if (fillColor instanceof SpotColor) {

      if (fillColor.spot.name == 'Orange TEMP') fillColor = replaceColor1;

      }

      if (strokeColor instanceof SpotColor) {

      if (strokeColor.spot.name == 'Orange TEMP') strokeColor = replaceColor1;

      }

      }

      }

      }

      }

      }

       

       

        

        var docRef = sourceDoc;

                 with (docRef) {

                    var replaceColor3= swatches.getByName('New Blue HCT').color;

       

      for (var i = 0; i < pathItems.length; i++) {

      with (pathItems[i]) {

      if (filled == true && fillColor instanceof SpotColor) {

      if (fillColor.spot.name == 'Blue TEMP') fillColor = replaceColor3;

      }

      if (stroked == true && strokeColor instanceof SpotColor) {

      if (strokeColor.spot.name == 'Blue TEMP') strokeColor = replaceColor3;

      }

      }

      }

       

      for (var j = 0; j < stories.length; j++) {

      with (stories[j]) {

      for (var k = 0; k < characters.length; k++) {

      with (characters[k].characterAttributes) {

      if (fillColor instanceof SpotColor) {

      if (fillColor.spot.name == 'Blue TEMP') fillColor = replaceColor3;

      }

      if (strokeColor instanceof SpotColor) {

      if (strokeColor.spot.name == 'Blue TEMP') strokeColor = replaceColor3;

      }

      }

      }

      }

      }

      }

       

       

       

       

       

      }

        • 1. Re: Swatch Replacement Script - works in CS6 but not CC
          Qwertyfly... Level 4

          would really help if you placed the code using syntax highlighting so that it can be read.

          you will get more help that way.

           

           

          http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scrip ting/cs6/Readme.txt

          "An Illustrator error occurred: 1346458189 ('PARM')" alert (1459349)  Affects: JavaScript  Problem: This alert may appear when carelessly written scripts are repeatedly run in Illustrator from the ExtendScript Toolkit.  Each script run is executed within the same persistent ExtendScript engine within Illustrator. The net effect is that the state of the ExtendScript engine is cumulative across all scripts that ran previously.  The following issues with script code can cause this problem:  - Reading uninitialized variables. - Global namespace conflicts, as when two globals from different scripts have the same name.  Workaround: Be very careful about variable initialization and namespace conflict when repeatedly pushing a batch of Illustrator scripts for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a single Illustrator session.  Initialize variables before using them, and consider the scope of your variables carefully. For example, isolate your variables by wrapping them within systematically named functions. Instead of:  var myDoc = app.documents.add(); // Add code to process myDoc  Wrap myDoc in a function that follows a systematic naming scheme:  function myFeatureNameProcessDoc() { var myDoc = app.documents.add(); // Add code to process myDoc } myFeatureNameProcessDoc(); 

           

           

          First thing I would try is restart illustrator and see if that helps.

          next, go through the code line by line and make sure all vars are initalized.

          may help to enclose if statements correctly. it's not necessary to enclose a single statement  if, but it helps readability. and it may be what is causing the illustrator javascript engine to get confused.

          ie.

          if (fillColor.spot.name == 'Orange TEMP') fillColor = replaceColor1;
          

          is better as,

          if (fillColor.spot.name == 'Orange TEMP') {
              fillColor = replaceColor1;
          }
          

           

          correct indenting really helps you see what is going on.

           

          for instance:

          if (filled == true && fillColor instanceof SpotColor) {

          if (fillColor.spot.name == 'Orange TEMP') fillColor = replaceColor1;

          }

           

          no gain in having 2 if statements here, 1 would do it and code becomes cleaner: (maybe that's just opinion though)

          if (filled == true && fillColor instanceof SpotColor && fillColor.spot.name == 'Orange TEMP') {
              fillColor = replaceColor1;
          }
          

           

          hope something here helps.

          if your still stuck, re-post and I'll take another look.