I was looking about indesign scripts and I have not found anything about this topic, which I think is important. So here it is my question:
- How to find a text frame in Indesign CS6 with javascript?
- I can query by text-frames containing a particular paragraph style?
- I can set some kind of name on my text-frame (which is in the master page) to get it in javascript?
I was looking about indesign scripts and I have not found anything about this topic, which I think is important. So here it is my question:
- How to find a text frame in Indesign CS6 with javascript?
- I can query by text-frames containing a particular paragraph style?
- I can set some kind of name on my text-frame (which is in the master page) to get it in javascript?
2 Answers
Reset to default 3Ok, after some research I've found that you can set a label to an object by opening the "Script label", selecting the object you want and the write the label-name into the "Script label" panel. You don't have to click ok or nothing, it will automatically save the label for that object.
After you do that, you can check the ".label" property on objects and when you will find the object with that label, you found it. Multiple objects can have the same label.
Below is an example with a helper function "selectWhere":
var document = app.documents.item(0); // active document
var allTextFrames = toArray(document.textFrames);
var textFrames = selectWhere("chapterLetter", "label", allTextFrames);
function selectWhere(value, key, array){
var i = array.length; var t; var filtered = [];
while(i--){
t = array[i];
if(t && t[key] == value){
filtered.push(t);
}
}
return filtered;
}
function toArray(objects){
var i = objects.length; var array = [];
while(i--){
array.push(objects[i]);
}
return array;
}
1)The answer to your first question is:- solved in this thread
2)Now you get array of textframes.So you can query to get the paragraph style on the text frames
var paraStyle1 = app.activeDocument.paragraphStyles.itemByName("styleA");
var paraStyle2 = app.activeDocument.paragraphStyles.itemByName("styleB");
if (paraStyle1.isValid && paraStyle2.isValid)
3) Through paraStyle1.name
you can get the name of the style.See parastyle1 is the paragraph style object so get the style object and find by this property.