4 Replies Latest reply on Dec 11, 2008 5:27 AM by (kasicki_roland)

    Step and Repeat Script help

      hi everyone,

      I'm a scripting virgin and was wondering if someone could help with what I imagine is a simple bit of script to add two fields in the dialogue box - no of copies horizontal and vertical:

      I've got a step and repeat script, but this works the same as CS3 step and repeat from the Edit menu, where you get n copies of a placed object on an offset of x and y. What I'd like is to make n by m copies of a placed object in one go (i.e. impose a grid of objects on a defined offset to get a sheet full of copies).

      Any takers? Thanx in advance if you have any eye-deers... :D

      The step and repeat script I've got is as follows:

      --
      tell application "Adobe InDesign CS3"
      if (count documents) > 0 then
      set mySelection to selection
      if (count mySelection) > 0 then
      set myObjects to {}
      repeat with myCounter from 1 to (count mySelection)
      if class of item myCounter of mySelection is rectangle or ¬
      class of item myCounter of mySelection is oval or ¬
      class of item myCounter of mySelection is polygon or ¬
      class of item myCounter of mySelection is graphic line or ¬
      class of item myCounter of mySelection is text frame then
      copy item myCounter of mySelection to end of myObjects
      end if
      end repeat
      if (count myObjects) > 0 then
      my myDisplayDialog(myObjects)
      end if
      else
      display dialog "Please select an object and try again."
      end if
      else
      display dialog "Please open a document, select an object, and try again."
      end if
      end tell

      on myDisplayDialog(myObjects)
      set myProxyList to {"TopLeft", "Top", "TopRight", "Left", "Center", "Right", "BottomLeft", "Bottom", "BottomRight"}
      tell application "Adobe InDesign CS3"
      set myDialog to make dialog with properties {name:"StepAndRepeat"}
      tell myDialog
      tell (make dialog column)
      make static text with properties {static label:"Repeat Count:"}
      --Spacer.
      make static text
      make static text with properties {static label:"Horizontal Offset:"}
      make static text with properties {static label:"Vertical Offset:"}
      --Spacer.
      make static text
      make static text with properties {static label:"Rotation:"}
      make static text with properties {static label:"Skew:"}
      --Spacer.
      make static text
      make static text with properties {static label:"Fill Tint:"}
      make static text with properties {static label:"Stroke Tint:"}
      end tell
      tell (make dialog column)
      set myRepeatField to make integer editbox with properties {edit value:2}
      --Spacer.
      make static text
      set myXOffsetField to make measurement editbox with properties {edit value:0}
      set myYOffsetField to make measurement editbox with properties {edit value:0}
      --Spacer.
      make static text
      set myRotationField to make angle editbox with properties {edit value:0}
      set mySkewField to make angle editbox with properties {edit value:0}
      --Spacer.
      make static text
      set myFillTintField to make real editbox with properties {edit value:0}
      set myStrokeTintField to make real editbox with properties {edit value:0}
      end tell
      tell (make dialog column)
      --Spacer.
      make static text
      --Spacer.
      make static text
      make static text with properties {static label:"Stroke Weight:"}
      make static text with properties {static label:"Opacity:"}
      --Spacer.
      make static text
      make static text with properties {static label:"Horizontal Scale:"}
      make static text with properties {static label:"Vertical Scale:"}
      --Spacer.
      make static text
      --Spacer.
      make static text
      make static text with properties {static label:"Proxy:"}
      end tell
      tell (make dialog column)
      --Spacer.
      make static text
      --Spacer.
      make static text
      set myStrokeWeightField to make measurement editbox with properties {edit value:0}
      set myOpacityField to make real editbox with properties {edit value:0}
      --Spacer.
        • 1. Re: Step and Repeat Script help
          Level 1
          Hi kasicki roland,

          Take a look at the MakeGrid.applecript example script that was installed with your copy of CS3. That should get you started.

          Thanks,

          Ole
          • 2. Re: Step and Repeat Script help
            Level 1
            Thanks Ole,

            I've made this script which duplicates the selected object in both x and y directions, but does not complete the grid - how can I set myObjects to be all the x duplicates BEFORE it runs the y duplicates?

            thanks for your help so far!

            -------

            tell application "Adobe InDesign CS3"
            if (count documents) > 0 then
            set mySelection to selection
            if (count mySelection) > 0 then
            set myObjects to {}
            repeat with myCounter from 1 to (count mySelection)
            if class of item myCounter of mySelection is rectangle or ¬
            class of item myCounter of mySelection is oval or ¬
            class of item myCounter of mySelection is polygon or ¬
            class of item myCounter of mySelection is graphic line or ¬
            class of item myCounter of mySelection is text frame then
            copy item myCounter of mySelection to end of myObjects
            end if
            end repeat
            if (count myObjects) > 0 then
            my myDisplayDialog(myObjects)
            end if
            else
            display dialog "Please select an object and try again."
            end if
            else
            display dialog "Please open a document, select an object, and try again."
            end if
            end tell

            on myDisplayDialog(myObjects)
            tell application "Adobe InDesign CS3"
            set myDialog to make dialog with properties {name:"StepAndRepeat"}
            tell myDialog
            tell (make dialog column)
            make static text with properties {static label:"Rows:"}
            make static text with properties {static label:"Cols:"}
            --Spacer.
            make static text
            make static text with properties {static label:"Horizontal Offset:"}
            make static text with properties {static label:"Vertical Offset:"}
            end tell
            tell (make dialog column)
            set myRowsField to make integer editbox with properties {edit value:2}
            set myColsField to make integer editbox with properties {edit value:2}
            --Spacer.
            make static text
            set myXOffsetField to make measurement editbox with properties {edit value:0}
            set myYOffsetField to make measurement editbox with properties {edit value:0}
            end tell
            end tell
            set myResult to show myDialog
            if myResult is true then
            --Gather the user input from the dialog controls.
            set myNumberOfRows to edit value of myRowsField
            set myNumberOfCols to edit value of myColsField
            set myXOffset to edit value of myXOffsetField
            set myYOffset to edit value of myYOffsetField
            destroy myDialog
            my myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfCols, myXOffset, myYOffset)
            else
            destroy myDialog
            end if
            end tell
            end myDisplayDialog

            on myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfCols, myXOffset, myYOffset)
            tell application "Adobe InDesign CS3"
            repeat with myCounter from 1 to myNumberOfRows
            repeat with myObjectCounter from 1 to (count myObjects)
            set myObject to item myObjectCounter of myObjects
            set myObject to duplicate myObject
            tell myObject
            move by {myXOffset * myCounter, 0}
            end tell
            end repeat
            end repeat
            repeat with myCounter from 1 to myNumberOfCols
            repeat with myObjectCounter from 1 to (count myObjects)
            set myObject to item myObjectCounter of myObjects
            set myObject to duplicate myObject
            tell myObject
            move by {0, myYOffset * myCounter}
            end tell
            end repeat
            end repeat
            end tell
            end myStepAndRepeat
            • 3. Re: Step and Repeat Script help
              sstanleyau Level 4
              On 5/12/08 9:20 PM, "kasicki roland" <member@adobeforums.com> wrote:<br /><br />> if class of item myCounter of mySelection is rectangle or ¬<br />> class of item myCounter of mySelection is oval or ¬<br />> class of item myCounter of mySelection is polygon or ¬<br />> class of item myCounter of mySelection is graphic line or ¬<br />> class of item myCounter of mySelection is text frame then<br /><br />This is not a very efficent way to do things -- it potentially asks InDesign<br />for the class of the same object five times. Better to ask once, and compare<br />the results:<br /><br />set theClass to class of item myCounter of mySelection<br />if theClass is rectangle or ¬<br />theClass is oval or ¬<br />theClass is polygon or ¬<br />theClass is graphic line or ¬<br />theClass is text frame then<br /><br />Or even simpler:<br /><br />set theClass to class of item myCounter of mySelection<br />if theClass is in {rectangle, oval, polygon, graphic line, text frame} then<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
              • 4. Re: Step and Repeat Script help
                Level 1
                Just to say I have re-made a functional version of this script in Javascript. Find it in the indesign scripts section of the adobe exchange: http://www.adobe.com/cfusion/exchange/

                //StepAndRepeatImposition.jsx
                //An InDesign CS JavaScript
                //www.theonconnection.com
                //Duplicates objects in a grid. Useful to impose for print.

                if (app.documents.length != 0){
                if (app.selection.length > 0){
                myObjects = app.selection;
                if(myObjects.length > 0){
                myDisplayDialog(myObjects);
                }
                else{
                alert("Please select a rectangle, polygon, graphic line, oval, or text frame and try again.");
                }
                }
                else{
                alert("Please select an object and try again.");
                }
                }
                else{
                alert("Please open a document, select an object, and try again.");
                }

                //Display dialog.
                function myDisplayDialog(myObjects){
                myDialog = app.dialogs.add();
                myDialog.name = "Step And Repeat Imposition";
                //myProxyColumn = myDialog.dialogColumns.add();
                myLabelsColumn1 = myDialog.dialogColumns.add();
                myLabelsColumn1.staticTexts.add({staticLabel:"Rows:"});
                myLabelsColumn1.staticTexts.add({staticLabel:"Columns:"});
                //Spacer.
                myLabelsColumn1.staticTexts.add();
                myLabelsColumn1.staticTexts.add({staticLabel:"Horizontal Offset:"});
                myLabelsColumn1.staticTexts.add({staticLabel:"Vertical Offset:"});
                //Spacer.
                myControlsColumn1 = myDialog.dialogColumns.add();
                myRowsField = myControlsColumn1.integerEditboxes.add({editValue:2});
                myColumnsField = myControlsColumn1.integerEditboxes.add({editValue:2});
                myControlsColumn1.staticTexts.add();
                myXOffsetField = myControlsColumn1.measurementEditboxes.add({editValue:0});
                myYOffsetField = myControlsColumn1.measurementEditboxes.add({editValue:0});
                //Spacer.
                myResult = myDialog.show();
                if(myResult == true){
                //Gather the user input from the dialog controls.
                myNumberOfRows = myRowsField.editValue;
                myNumberOfColumns = myColumnsField.editValue;
                myXOffset = myXOffsetField.editValue;
                myYOffset = myYOffsetField.editValue;
                myDialog.destroy();
                myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfColumns, myXOffset, myYOffset);
                }
                else{
                myDialog.destroy();
                }
                }
                function myStepAndRepeat(myObjects, myNumberOfRows, myNumberOfColumns, myXOffset, myYOffset){
                //looping here for the rows
                for (myYCounter = 0; myYCounter <= myNumberOfRows-1; myYCounter++){
                //looping here for the cols
                for (myXCounter = 0; myXCounter <= myNumberOfColumns-1; myXCounter++){
                if (myXCounter!=0 || myYCounter !=0) {
                for (myObjectCounter=0; myObjectCounter < myObjects.length; myObjectCounter++){
                myObject = myObjects[myObjectCounter];
                myObject = myObject.duplicate();
                myObject.move(undefined, [myXOffset*myXCounter, myYOffset*myYCounter]);
                }
                }
                }
                }
                }