6 Replies Latest reply on Nov 26, 2015 10:21 PM by Qwertyfly...

    I require script for multiups?

    mohannegi

      Hi,

       

      I require javascript for a simple job like

       

      I have an object size (w X h).

       

      I need a rectangle outside of this object bigger than it. For creating this rectangle, i will input value separately to add with objects width & height.

       

      This rectangle will be clip mask of object.

       

      Both object and its rectangle selected and it it copy and move with its width value to add many multiups horizontly. need dialog box for input multiups.

       

      all multi ups get selected and this time it copy and move with its height value to add many multi ups vertically. need dialog box for input multi ups.

       

      Thanks for your kind help.

        • 1. Re: I require script for multiups?
          Qwertyfly... Level 4

          group your art. select it. then run this.

           

          function vertical_layout(){ 
              var gap = prompt("enter Gap between selected group and its new Clipping path in mm",5,"Set Clipping Size");
              var qty = prompt("how many would you like?",5,"Set Qty");
              gap = gap*2.83466796875; // convert mm to points for the script (for inches change to "gap*72")
              var doc = app.activeDocument;
              var sel = doc.selection;
              if(sel.length<1){
                  alert("Please select a group before running this script");
                  return;
              }
              if(sel.length>1){
                  alert("Please group Items before selecting and running this script");
                  return;
              }
              var Ibounds = sel[0].visibleBounds;
              var clip = doc.pathItems.rectangle(Ibounds[1]+gap,Ibounds[0]-gap,Ibounds[2]-Ibounds[0]+(gap*2),Ibounds[1]-Ibounds[3]+(gap*2));
              clip.move(sel[0], ElementPlacement.PLACEATBEGINNING);
              sel[0].clipped = true;
              sel[0].pathItems[0].clipping = true;
              sel[0].pathItems[0].selected = true;
              var newSel = doc.selection;
              var shift = Ibounds[1]-Ibounds[3]+(gap*2);
              for(var i = 0; i<qty; i++){
                  var copy = newSel[0].duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
                  copy.translate(0,shift*(i+1),true,true,true,true);
              }
              
          }
          vertical_layout();
          
          • 2. Re: I require script for multiups?
            Stephen_A_Marsh Adobe Community Professional

            Step and Repeat scripts are also covered here:

             

            Step and repeat

            • 3. Re: I require script for multiups?
              Qwertyfly... Level 4

              oops I missed the horizontal.

               

              this will, with default settings, create a 5 x 5 grid, but will leave the original at bottom left.

               

              function vertical_layout(){ 
                  var gap = prompt("enter Gap between selected group and its new Clipping path in mm",5,"Set Clipping Size");
                  var qty = prompt("how many would you like UP?",5,"Set Qty");
                  var qty2 = prompt("how many would you like ACROSS?",5,"Set Qty");
                  gap = gap*2.83466796875; // convert mm to points for the script (for inches change to "gap*72")
                  var doc = app.activeDocument;
                  var sel = doc.selection;
                  if(sel.length<1){
                      alert("Please select a group before running this script");
                      return;
                  }
                  if(sel.length>1){
                      alert("Please group Items before selecting and running this script");
                      return;
                  }
                  var Ibounds = sel[0].visibleBounds;
                  var clip = doc.pathItems.rectangle(Ibounds[1]+gap,Ibounds[0]-gap,Ibounds[2]-Ibounds[0]+(gap*2),Ibounds[1]-Ibounds[3]+(gap*2));
                  clip.move(sel[0], ElementPlacement.PLACEATBEGINNING);
                  sel[0].clipped = true;
                  sel[0].pathItems[0].clipping = true;
                  sel[0].pathItems[0].selected = true;
                  var newSel = doc.selection;
                  var shift = Ibounds[1]-Ibounds[3]+(gap*2);
                  var shift2 = Ibounds[2]-Ibounds[0]+(gap*2);
                  for(var i = 0; i<qty; i++){
                      var copy = newSel[0].duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
                      copy.translate(0,shift*(i+1),true,true,true,true);
                      for(var j = 0; j<qty2-1; j++){
                          var copy2 = copy.duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
                          copy2.translate(shift2*(j+1),0,true,true,true,true);
                      }
                  }
              }
              vertical_layout();
              
              
              • 4. Re: I require script for multiups?
                Qwertyfly... Level 4

                the post stephen mentions looks like a more complex version.

                it also includes some extra idiot proofing.

                 

                for a production robust script you should look at confirming that (gap, qty, qty2) variables are numbers and don't contain letters etc..

                • 5. Re: I require script for multiups?
                  mohannegi Level 1

                  Thanks for your help. when I run the script after selecting my object, it giving me following error? what should be done.multiups script error.JPG

                  • 6. Re: I require script for multiups?
                    Qwertyfly... Level 4

                    sorry it was built to deal with groups.

                    press ctrl+G (guessing cmd+G on mac) to put your shape in a group, then run the script.

                    I can fix this in the script but am running late and will not be around for a few days...