8 Replies Latest reply on Sep 8, 2014 9:33 PM by JJMack

    Placing smart objects in order

    jksukino

      Hello everyone,

       

      I'm working with a photoshop template where i constantly place smart objects evenly spaced from left to right. Its quite a repetetive job, and i know this can be automated but don't really know how to approach this problem.

       

      What i do is, i open my template with fixed dimentions and place smartobjects from left to right next to eacother.

       

      All objects have the same dimentions but different names.

      Sometimes i place four and sometimes 5 or more smartobjects on the canvas.

      All objects should have the same width as the template witdh combined.

      All smartobject should keep their aspectratio so height won't be a problem

       

      it should look something like this:

       

      [X][X][X][X][X][X][X]

       

      with [X] being one smart opbject.

       

      can someone send me in the right direction on how to do this?

      And i only have a basic understanding of javascript so scripting this myself won't be an option

       

      thanks for looking in tho this

        • 1. Re: Placing smart objects in order
          c.pfaffenbichler Level 9

          Does this help?

          // select files and place as smart objects then scale and distribute them horizontally;

          // 2014, use it at your own risk;

          #target "photoshop-70.032"

          if (app.documents.length > 0) {

          var myDocument = app.activeDocument;

          // select files;

          if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", '*.jpg;*.tif;*.pdf;*.psd;*.bmp', true)}

          else {var theFiles = File.openDialog ("please select files", getFiles, true)};

          // if files were selected;

          if (theFiles.length > 0) {

          var originalRulerUnits = app.preferences.rulerUnits;

          app.preferences.rulerUnits = Units.PIXELS;

          var theCenter = myDocument.width / 2;

          var thePlaced = new Array;

          var theTotalWidth = 0;

          // place files;

          for (var m = 0; m < theFiles.length; m++) {

            var theLayer = placeScaleRotateFile(theFiles[m], 0, 0, 100, 100, 0);

            var theWidth = theLayer.bounds[2] - theLayer.bounds[0];

            thePlaced.push([theLayer, theWidth, theLayer.bounds[0]]);

            theTotalWidth = theTotalWidth + theWidth;

            };

          // scale files;

          var theScale = myDocument.width / theTotalWidth;

          var theAdded = 0;

          for (var n = 0; n < theFiles.length; n++) {

            var theHalf = thePlaced[n][1] * theScale / 2;

            var thisCenter = theAdded + theHalf;

            duplicateMoveRotateScale (thePlaced[n][0], theCenter - thisCenter, 0, theScale * 100, theScale * 100, 0, false)

            theAdded = theAdded + thePlaced[n][1] * theScale;

            };

          // reset;

          app.preferences.rulerUnits = originalRulerUnits;

          };

          };

          ////// get psds, tifs and jpgs from files //////

          function getFiles (theFile) {

              if (theFile.name.match(/\.(eps|ai|jpg|tif|psd|pdf|)$/i)) {

                  return true

                  };

            };

          ////// place //////

          function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle) {

          // =======================================================

          var idPlc = charIDToTypeID( "Plc " );

              var desc5 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

              desc5.putPath( idnull, new File( file ) );

              var idFTcs = charIDToTypeID( "FTcs" );

              var idQCSt = charIDToTypeID( "QCSt" );

              var idQcsa = charIDToTypeID( "Qcsa" );

              desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

              var idOfst = charIDToTypeID( "Ofst" );

                  var desc6 = new ActionDescriptor();

                  var idHrzn = charIDToTypeID( "Hrzn" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc6.putUnitDouble( idHrzn, idPxl, xOffset );

                  var idVrtc = charIDToTypeID( "Vrtc" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc6.putUnitDouble( idVrtc, idPxl, yOffset );

              var idOfst = charIDToTypeID( "Ofst" );

              desc5.putObject( idOfst, idOfst, desc6 );

              var idWdth = charIDToTypeID( "Wdth" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc5.putUnitDouble( idWdth, idPrc, theYScale );

              var idHght = charIDToTypeID( "Hght" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc5.putUnitDouble( idHght, idPrc, theXScale );

              var idAngl = charIDToTypeID( "Angl" );

              var idAng = charIDToTypeID( "#Ang" );

              desc5.putUnitDouble( idAngl, idAng,theAngle );

              var idLnkd = charIDToTypeID( "Lnkd" );

              desc5.putBoolean( idLnkd, true );

          executeAction( idPlc, desc5, DialogModes.NO );

          return app.activeDocument.activeLayer;

          };

          ////// duplicate layer and move, rotate and scale it //////

          function duplicateMoveRotateScale (theLayer, theX, theY, theScaleX, theScaleY, theRotation, duplicate) {

          app.activeDocument.activeLayer = theLayer;

          try{

          // =======================================================

          var idTrnf = charIDToTypeID( "Trnf" );

              var desc10 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref6 = new ActionReference();

                  var idLyr = charIDToTypeID( "Lyr " );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idTrgt = charIDToTypeID( "Trgt" );

                  ref6.putEnumerated( idLyr, idOrdn, idTrgt );

              desc10.putReference( idnull, ref6 );

              var idFTcs = charIDToTypeID( "FTcs" );

              var idQCSt = charIDToTypeID( "QCSt" );

              var idQcsa = charIDToTypeID( "Qcsa" );

              desc10.putEnumerated( idFTcs, idQCSt, idQcsa );

              var idOfst = charIDToTypeID( "Ofst" );

                  var desc11 = new ActionDescriptor();

                  var idHrzn = charIDToTypeID( "Hrzn" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc11.putUnitDouble( idHrzn, idPxl, theX );

                  var idVrtc = charIDToTypeID( "Vrtc" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc11.putUnitDouble( idVrtc, idPxl, theY );

              var idOfst = charIDToTypeID( "Ofst" );

              desc10.putObject( idOfst, idOfst, desc11 );

              var idWdth = charIDToTypeID( "Wdth" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc10.putUnitDouble( idWdth, idPrc, theScaleX );

              var idHght = charIDToTypeID( "Hght" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc10.putUnitDouble( idHght, idPrc, theScaleY );

              var idAngl = charIDToTypeID( "Angl" );

              var idAng = charIDToTypeID( "#Ang" );

              desc10.putUnitDouble( idAngl, idAng, theRotation );

              var idIntr = charIDToTypeID( "Intr" );

              var idIntp = charIDToTypeID( "Intp" );

              var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );

              desc10.putEnumerated( idIntr, idIntp, idbicubicAutomatic );

              var idCpy = charIDToTypeID( "Cpy " );

              desc10.putBoolean( idCpy, duplicate );

          executeAction( idTrnf, desc10, DialogModes.NO );

          return app.activeDocument.activeLayer

          } catch (e) {}

          };

          • 2. Re: Placing smart objects in order
            JJMack Most Valuable Participant

            My Photo Collage Toolkit Scripts populate templates with smart object layer the layers are sized for the image area and mask to virtually crop the image to the image area so the may have any shape.  Images are place in in order they can also be stamped with their file name text.  Have layer style added to stamp and image layer.  There are four simple rules creating templates.  Interactive scripts, batch scripts and automated scripts are included.  A simple script that require no template can be use to  tile images into a document however that script just paste in re-sized masked image .  Image can be any Photoshop supported image file types any size and resolution. Photo collages like this are simple and easy to make: Here a video http://www.mouseprints.net/old/dpr/Populate911_720p.mp4 for the collate:

             

            Documentation and Examples and the no template required script documentation Paste Image Roll Script and Picture Package Support>

            Collage_1_4_6x4+FDNYonTopG.jpg

            • 3. Re: Placing smart objects in order
              jksukino Level 1

              Thanks for the reactions,

               

              Unfortunally i can't seem to get your script to work C.pfaffenbichler.

               

              And the collage tool you give JJMack doesn't let me use a fixed width for the template and a reletive width for the smartobjects. as the combined with of the smart objects should not exceed the template with but should be equal (or less if the height exeeds the template height)

               

              I'm not that great of a javascripter so i don't know how to alter it.

              • 4. Re: Placing smart objects in order
                c.pfaffenbichler Level 9

                Please change the line

                #target "photoshop-70.032"

                to

                 

                #target photoshop

                 

                 

                If it still does not work what exactly happens? Do you get the file selection dialog at all?

                • 5. Re: Placing smart objects in order
                  jksukino Level 1

                  It works! thanks a lot!

                  • 6. Re: Placing smart objects in order
                    c.pfaffenbichler Level 9

                    You’re welcome.

                     

                    There is no check for their height, though; I hadn’t gathered that from the original post.

                    • 7. Re: Placing smart objects in order
                      jksukino Level 1

                      Well the height shouldn't be a problem as i normally load more than enough pictures to fill it horizontally. But on the rare occation it doesn't i'll just fix it by hand. Not that big of a problem

                      • 8. Re: Placing smart objects in order
                        JJMack Most Valuable Participant

                        You just don't understand how the template and script work together.  You have absolute control over the templates for you create them using four rules. You control all. Size, shape, position, resolution,

                        composition, stacking order you name you have control.  The script just place in you image files in order positioning them, transforms  them and masking them to your template you have design and crafted. 

                        The scripts may have additional options for adding text and layer styles to images and text.  You have creative freedom however for the scripting to work you template must adhere to four simple rules. You

                        should not find them restriction at all

                         

                        Four Rules

                        Size the photo collage templates for the print size you want - width, height and print DPI resolution.

                        Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.

                        Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".

                        Photo collage templates layers above the background layers must provide transparent areas to let the images that will be placed below them show through.

                         

                        Rule 1 you control the absolute Print Size and Resolution

                         

                        Rule 2 just state that you must have a background layer for the script will place  the images in the order you create you image mapping Alpha Channels. They will be placed into  the layer stack starting right

                        above the background layer.

                         

                        Rule 3 you create the mapping Alpha Channels in image order  Image 1, Images 2 ... Image N. N is limited to 53 because that the max Alpha channels Photoshop supports. You have absolute control over the

                        size, location and shape of the mapping alpha channels.   You image file can be any image file format that Photoshop supports any size and resolution. The scripts will place them your images in order Image 1

                        right above the background later. Image 2 above Image 1 and so on.  Each Place image will be positioned and transformed to fill the bounds of it mapping Alpha channels then masked with the alpha channel

                        to virtually corp it to the shape of the mapping.

                         

                        Rule 4 is just a reminder not to cover you image completely frame them add embellishment over them like the center imag