Skip to main content
Participating Frequently
December 29, 2008
Question

Retrieving index of a selected Rectangle/Image

  • December 29, 2008
  • 2 replies
  • 511 views
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.
This topic has been closed for replies.

2 replies

Participating Frequently
December 29, 2008
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.
Known Participant
December 29, 2008
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
Inspiring
December 29, 2008
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