3 Replies Latest reply on Aug 31, 2009 9:31 AM by AdobeScripts

    New To InDesign Scripting; Want To Learn

    ostranderbrown1

      I need to slowly replace several old scripts that we have, and I am trying to teach myself, using the Scripting Guide, and samples of scripts we already have. I am going to need some help along the way, so hopefully this forum can help me.

       

      I am using InDesign CS2, but I may be backwards converting some of our scripts to InDesign 2.0, because that's what we are currently using as a standard (behind the times I know, but what can I do :-)). Our goal is to move forwards into CS2 ... well, CS4 it is now, but we need to have some of our scripts replaced in order to be most functional. We are a windows based environment, and I will be using VB for the language, mostly because I have some minor experience with it already, and also because I believe it will better integrate with our future plans, and the scripts we currently have are already written in that language.

       

      So, to start, I chose our most basic script, which takes a selection of images, aligns them, centers them, embeds them, and sets the attributes to "overprint fill".

       

      I am having a difficult time grasping the concept of how to refer to things in the script. For example, I want to select a couple of images and run the script, but I am stuck on how to refer to those selected images to begin with. The below doesn't work.

       

      Set myInDesign = CreateObject("InDesign.Application.CS2")
      Set myDocument = myIndesign.ActiveDocument
      myDocument.Selection.Move Array("0p0", "0p0")

      Can someone help explain to me how to grab selected items?

       

      I will probably be full of questions, so please bear with me. I have taught myself this kind of stuff before, so I should be able to catch on with some guidance.

       

      Thank-you,

      Christopher

        • 1. Re: New To InDesign Scripting; Want To Learn
          [Jongware] Most Valuable Participant

          (Speaking from a JavaScript bg, but the difference is not as big as you'd think!)

           

          "Selection" is not a single object, rather an array of objects -- even if you only have one single object selected. (And also if you have no objects selected -- its length will be zero.) When you are working with text, you are limited to a single selection, unfortunately. On the other hand, when dealing with images, for example, you can select as many as you want.

           

          If you change the last line to

           

          myDocument.Selection(1).Move Array("0p0", "0p0")

           

          the first item in your selection will move to the zero point. To move all items in a selection, this is the Javascript way

           

          for (a=0; a<app.selection[0].length; a++)

            app.selection[a].move ( [0,0] );

           

          -- I'm not sure how 'selection.length' translates into VB. Note how the loop starts with '0', whereas VB should start with 1, and how it would work with zero, one, or 1,500 items selected.

          • 2. Re: New To InDesign Scripting; Want To Learn
            mmsidon

            Hi Christopher,

             

            instead of using a loop yourself you can also do an action on every item in a collection by using the method "everyItem".

            E.g. if you write / replace the following line, this should do....

             

            myDocument.Selection.everyItem.Move Array("0p0", "0p0")

             

            This works like a loop and does what is defined behind (in this case MOVE) with every Item of the collection but is kind of faster.

             

            In InDesign, a lot of things are collections: pages, spreads, selection, textframes, stories..... and so on.

            This "everyItem" method works with (almost) all of them... (there are some few exceptions).

             

             

            Greetings,

            Marc

            • 3. Re: New To InDesign Scripting; Want To Learn
              AdobeScripts Level 3

              mmsidon wrote:

               

              instead of using a loop yourself you can also do an action on every item in a collection by using the method "everyItem".

              E.g. if you write / replace the following line, this should do....

               

              myDocument.Selection.everyItem.Move Array("0p0", "0p0")

               

              VB doesn't have EVERYITEM functionality

               

              robin

               

              www.adobescripts.co.uk