8 Replies Latest reply on Oct 4, 2017 1:13 PM by JJMack

    My Photoshop script is giving different results on different machines

    davids41054554

      Hi all.  I want to preface this question by stating that I am by no means an artist, nor am I fluent in Photoshop.  Please be aware when answering that I may or may not know what you are talking about, so please be extremely explicit.

       

      I recently wrote a script for some colleagues that goes through your current PSD and exports "Save For Web" all of the layers inside all of the visible Smart Objects.  So far, 4 people have tried to use the script, and it works as expected for 3 of us.  The 4th person just verified that he is up-to-date on Photoshop CC 2017 like the rest of us, and has reset his personal user preferences to mimic a fresh install like mine.  He is still getting different results than we are.  His exported .png dimensions are much smaller than they should be, and therefore is cropping a majority of the image. 

       

      I am officially out of ideas, and without advanced knowledge of Photoshop, I don't have the slightest idea what could cause his results to be different, especially after a update and reset like he just did.  What other factors could cause such differences? How can I test for them? When identified, how can I account for them to avoid this issue in the future?  Thanks in advance.

       

      Here is the script:

      #target photoshop

       

      var doc = app.activeDocument;

      var parentLayers = doc.artLayers;

      var EXPORT_PATH = doc.path + '/Exports/';

       

      var options = new ExportOptionsSaveForWeb();

      options.format = SaveDocumentType.PNG;

      options.PNG8 = false;

      options.transparency = true;

      options.optimized = true;

       

      var exportFolder = new Folder(EXPORT_PATH);

      if (!exportFolder.exists)

      {

          exportFolder.create();

      }

       

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

      {

          var parentLayer = parentLayers[i];

         

          if (parentLayer.visible && parentLayer.kind == LayerKind.SMARTOBJECT)

          {

              doc.activeLayer = parentLayer;

              EditSmartObject();

             

              var tempSmartObject = app.activeDocument;

              var childLayers = tempSmartObject.artLayers;

             

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

              {

                  thisLayer = childLayers[j];

                 

                  if (thisLayer.visible)

                  {

                      thisLayer.copy();

                     

                      var newWidth = thisLayer.bounds[2] - thisLayer.bounds[0];

                      var newHeight = thisLayer.bounds[3] - thisLayer.bounds[1];

                     

                      var newDoc = app.documents.add(newWidth, newHeight, 72, "temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT);

                      newDoc.artLayers.add();

                      newDoc.paste();

                      newDoc.exportDocument(File(EXPORT_PATH + thisLayer.name +'.png'), ExportType.SAVEFORWEB, options);

                      newDoc.close(SaveOptions.DONOTSAVECHANGES);   

                  }

              }

              tempSmartObject.close(SaveOptions.DONOTSAVECHANGES);

          }

      }

       

      function EditSmartObject()

      {

          var id = stringIDToTypeID( "placedLayerEditContents" );

          var desc = new ActionDescriptor();

          executeAction( id, desc, DialogModes.NO );

      }

        • 1. Re: My Photoshop script is giving different results on different machines
          JJMack Most Valuable Participant

          The first thing you need to check is they are processing exactly the sane document process by the others on they machines.  Document vary and all smart object are not created the same and in some cases Photoshop can not even process the file data in smart object properly Photoshop does not have the capability to for example process AI vector layers as  vector layers.  Processing what is in a smart object layer object is not alway possible to do with Photoshop.  What you are trying to do will not be always posible will be inpossible for things like placed SVG file Ai Files perhaps PDF and ESP files. You function name is EditSamrtObject biu its code does not look like you are even trying to open it to edit it. always in Photoshop a Place RAW file or a Raw file open as a smart Object will open in ACR and a Place AI file will open in AI.  Photoshop will update the object and render new pixels for the object if AI or ACR update the object work file Photoshop creates in you user temp space.  Are you trying to copy the smart layer into a new document somehow  all object are not strictly Photoshop Objects. Also If AI file are associated with Photoshop. Photoshop  does not support them well SVG file and AI file will open as a single Raster layer not multiple vector layers.

           

          function EditSmartObject()

          {

              var id = stringIDToTypeID( "placedLayerEditContents" );

              var desc = new ActionDescriptor();

              executeAction( id, desc, DialogModes.NO );

          }

          The Work File create for placeLayerEditContent will not always open in Photoshop.  The file may be a PSB or RAW an image file or Ai file there are many types of objects.

          • 2. Re: My Photoshop script is giving different results on different machines
            Chuck Uebele Adobe Community Professional & MVP

            I would also put in a line to set your ruler units.

             

            app.preferences.rulerUnits = Units.PIXELS;

            • 3. Re: My Photoshop script is giving different results on different machines
              davids41054554 Level 1

              Thank you for the response.

               

              To clarify, when I said 3 out of 4 people got the expected results, we all were running the script on the same PSD, so I would expect the same results from all 4 of us.

               

              As far as the EditSmartObject function, that is an action that mimics double clicking on a SmartObject in Photoshop to open it in a new document.  When this happens, the new document with the expanded SmartObject layers becomes the activeDocument.  The very next line "var tempSmartObject = app.activeDocument;" grabs this new document and then begins to copy each layer inside that new SmartObject document and export them.

              • 4. Re: My Photoshop script is giving different results on different machines
                davids41054554 Level 1

                Thanks for the response, I will give this a try.

                • 5. Re: My Photoshop script is giving different results on different machines
                  davids41054554 Level 1

                  Thank you very much Chuck, that was the issue we were encountering.  The person who was getting different results had their rulers set to inches, and the rest of us had pixels.

                   

                  I added the following code to the top:

                  var userRulerPreference = app.preferences.rulerUnits;

                  app.preferences.rulerUnits = Units.PIXELS;

                   

                  Then at the bottom:

                  app.preferences.rulerUnits = userRulerPreference;

                   

                  This allowed everyone to get the same results without forcing people to use settings they don't like.

                   

                  Thanks again!

                  • 6. Re: My Photoshop script is giving different results on different machines
                    JJMack Most Valuable Participant

                    Double clicking on an smart object in the layers palette will not alwaye open a  work document in Photoshop.  There  are many type of Objects not all are associated with Photoshop.  A place or open RAW object will onpen in ACR not Photoshop.  A placed Jpeg or Tiff may open in ACR depend one one ACR preferences.  A placed AI file may open in AI.

                     

                    Here  I have a Placed jpeg and a placed tiff i now I Set my ACR preferences  to open TIFF and JPEFG files.

                    Capture.jpg

                    • 8. Re: My Photoshop script is giving different results on different machines
                      JJMack Most Valuable Participant

                      Be careful I do not know if you can test if the laye's object  is a Photoshop object or not. You need to know if it will open in Photshop or not. Photoshop also does not support some file types the way they should be  for example EPS are not process as vector graphice.  The will open as a singel raster layer no vectors. Same with SVG files.