1 Reply Latest reply on Jul 26, 2016 7:20 AM by JJMack

    CC 2015.5 Scripting Bug

    JJMack Most Valuable Participant

      Several of may Photoshop do not work in CC 2015.5 because of a new bug in CC 2015.5 scripting support. While it easy for me to program around it because I know how it bites.   It could effect other script and go undetected for some time.

       

      I have created script the use the file info  instruction metadata for operation instruction.   The scripts add and remove their private information there.  The problem only happens when one of the script tries the remove its information it had added and that is the only data in the  instruction metadata.  CC 2015.5 fails to remove the data when the script set the field to empty to nothing.  Prior versions of Photoshop scripting worked correctly.

       

      Its is easy to program around all one need to is add garbage that will not be removed. the removing every thing else will work.  Here is a simple toggle center guide script shoe work in PS 7 with optional scripting Plug-in to CC 2015.   It will not in CC 2015.5.  However in you add something to the document info instructions it will start working on that document in CC 2015.5.

        • 1. Re: CC 2015.5 Scripting Bug
          JJMack Most Valuable Participant

          ToggleCenterGuides.jsx

           

          /* ======================================================================================
          // 2015  John J. McAssey (JJMack)  http://www.mouseprints.net/
          //  
          // This script is supplied as is. It is provided as freeware. 
          // The author accepts no liability for any problems arising from its use.
          //
          // This script is designed to Toggle centering guides.
          //      assign a shortcut I use this in an action assigned to F12. 
          //
          // ===================================================================================== */
          
          /*
          <javascriptresource>
          <about>$$$/JavaScripts/AddRemoveCenterGuides/About=JJMack's AddRemoveCenterGuides.^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^r^rFirst Run Set Guides on camvas bounds and center.^rSecond Run clears the set guides.</about>
          <category>JJMack's Action Run Twice Utility</category>
          </javascriptresource>
          */
          
          if (app.documents.length > 0) app.activeDocument.suspendHistory('ToggleCenterGuides','main()' );
          else alert("You must have at least one open document to run this script!"); 
          /////////////////////////////////////////////////////////////////////////////////////////// 
          function main() {
            if (app.activeDocument.info.instructions.indexOf("<CenterGuides>") == -1 ){ // no footprint fisrt useage 
            var orig_ruler_units = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
            try { 
            activeDocument.guides.add(Direction.VERTICAL, 0);
            activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/4);
            activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/2);
            activeDocument.guides.add(Direction.VERTICAL, activeDocument.width*3/4);
            activeDocument.guides.add(Direction.VERTICAL, activeDocument.width);
            activeDocument.guides.add(Direction.HORIZONTAL, 0);
            activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/4);
            activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/2);
            activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height*3/4);
            activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height);
            }
            // display error message if something goes wrong
            catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
            app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
            // put footprint in metadata info instructions
            app.activeDocument.info.instructions = app.activeDocument.info.instructions + "<CenterGuides>" + " Show" + "</CenterGuides>"; 
            } 
            else { 
            clearGuides();
            // Remove footprint from metadata info instructions
            before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexOf("<CenterGuides>"));
            afterOffset = app.activeDocument.info.instructions.indexOf("</CenterGuides>") + "</CenterGuides>".length;
            after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);
            //alert ("before = " + before + " after = " + after);
            app.activeDocument.info.instructions = before + after; // Fails in CC 2015.5 when before and after are null
            //alert("app.activeDocument.info.instructions = " + app.activeDocument.info.instructions);  
            } 
          //////////////////////////////////////////// Action Manager Code to Clear all Guides ///////////////////////////////////
          function clearGuides() { 
             var id556 = charIDToTypeID( "Dlt " ); 
                 var desc102 = new ActionDescriptor(); 
                 var id557 = charIDToTypeID( "null" ); 
                     var ref70 = new ActionReference(); 
                     var id558 = charIDToTypeID( "Gd  " ); 
                     var id559 = charIDToTypeID( "Ordn" ); 
                     var id560 = charIDToTypeID( "Al  " ); 
                     ref70.putEnumerated( id558, id559, id560 ); 
                 desc102.putReference( id557, ref70 ); 
             executeAction( id556, desc102, DialogModes.NO ); 
            };