Assumed there are page items named "box1" and "box 2" anywhere inside mDoc:
mDoc = app.activeDocument; mDoc.pageItems.item("box1").select(); mDoc.pageItems.item("box2").select(SelectionOptions.ADD_TO);
other select options:
Adobe InDesign CS5 (7.0) Object Model
or another placed here: http://jongware.mit.edu
@Jarek – "anywhere"? No.
They have to be on the same spread, if you want to select them…
@Virender – if you want to address the two text frames without selecting them, this limitation does not apply.
Addressing objects by name is tricky. You have to make sure, that there are no objects with the same name. Otherwise you could end up with the wrong object…
A unique identifier could be the ID number of a text frame…
@Uwe - sure, you're right
Dear Jarek, Dear Uwe,
thanks much but I am using CS6 (Adobe Indesign CS6(8.0) model), above coding is not working. Please advise alternative method for selecting both text boxes. They are on same page.
Jumping to the next alternative method is a never ending story. First try to figure out why the basic method doesn't work.
- What error is shown?
- Is this 3-liner code a part of the bigger one?
- Are the assumings done properly?
agreed . Lets resolve the existing coding.
var myDoc = app.activeDocument;
myDoc.pageItems.item("box1").select(); //error appear here (Object is invalid)
myDoc.pageItems.item("box2").select(SelectionOptions.ADD_TO); // even if delete this line.
- Object is invalid.
- no i just used above code in a separate new script. only above these lines are present.
- Yes, you can see coding above.
@Virender – as I remember, something changed from Indesign CS4 to CS5 (and still applies to the recent versions of InDesign).
There are three different methods to apply something as a "Name" to a text frame:
1. The "Label" method in the UI with the Scripting Label Panel
You can retrieve that label with the label property like that:
//The text frame is selected:
var myLabel = app.selection.label;
But since there is no pageItems.itemByLabel("myLabelString") method, this is useless here…
To retrieve a label you have to iterate through all text frames on the page to sort out the right text frame…
2. Or you inject a script label with the insertLabel("keyString","valueString") method and retrieve the inserted label with extractLabel("keyString") method. That means that you have to iterate through all text frames on the page to sort out the right one…
3. The "Name" method in the UI: you can rename every page item shown in the Layers Panel.
You can retrieve that name with the name property like that:
For the whole discussion (and some solutions) about this see:
Dear Uwe, Many thanks for your points.
I have 10 indd files and each file has one page and a table is only item present on page. So few files has table present in one table and few files has two text boxes because table has many rows so spiltted in two linked text boxes.
I somehow able to select both text boxes but while exporting them only one text box table get exported as png because of improper code.
var sourceFolder = new Folder ("/Users/admin4/Desktop/INS");
var myFiles = sourceFolder.getFiles();
var destFolder = new Folder ("/Users/admin4/Desktop/folder3");
for (i=0; i < myFiles.length; i++)
if (myFiles[i].name !=".DS_Store")
var sourceDoc = app.open(myFiles[i]);
var destFile = File(destFolder + "/" + myFiles[i].name + ".png");
app.selection.exportFile(ExportFormat.PNG_FORMAT, destFile, false);
// here i need to correct code.