3 Replies Latest reply on Dec 29, 2008 1:37 AM by (Robert_Tkaczyk)

    Retrieving index of a selected Rectangle/Image

    Justin Monsees
      I am currently working on a project in which I need to import images and attach captions to them. I would like to create a script that would allow me to select an image and then run the script to attach a textbox beneath it with a caption. In order to do this I need the index number of the select Image/Rectangle. I tried using the Document.selection property but that returns a Rectangle. Using Document.selection.index only returns "undefined."

      What is the proper syntax to retrieve the index number of Rectangle/Image that is currently selected in a document?

      Thanks,

      Justin M.
        • 1. Re: Retrieving index of a selected Rectangle/Image
          Level 1
          Why do you need the index? Isn't a reference derived from the selection good enough?

          It would help you get specific advice if you mentioned which version of InDesign and which scripting language. Perhaps if you posted some code or a more detailed description of what you have in mind.

          Dave
          • 2. Re: Retrieving index of a selected Rectangle/Image
            Justin Monsees Level 1
            Dave,

            you're right. I'm trying to accomplish this using Javascript. Essentially I'm trying to modify the "LabelGraphics.jsx" file that I was able to download as a sample script. This script adds a text box underneath all of graphics. I just want it to add a text box to the one that is currently selected. Here's the piece of code that I'm trying to modify. Let me know if you need more information.

            function myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myLabelStyleName){
            var myDocument = app.documents.item(0);
            var myGraphics = myDocument.allGraphics;
            myLabelStyle = myDocument.paragraphStyles.item(myLabelStyleName);
            for(var myCounter = 0; myCounter < myGraphics.length; myCounter++){
            myAddLabel(myDocument, myGraphics[myCounter], myLabelType, myLabelHeight, myLabelOffset, myLabelStyle);
            }
            }

            Instead of using a "for" loop I only want to reference the currently selected rectangle.

            Justin M.
            • 3. Re: Retrieving index of a selected Rectangle/Image
              Level 1
              I'm not JS man, but this should work for you:

              myAddLabel(myDocument, myDocument.selection.item(0), myLabelType, myLabelHeight, myLabelOffset, myLabelStyle);

              robin

              --
              www.adobescripts.com