Copy link to clipboard
Copied
My subject line would appear to be a no-brainer because document-wide settings can be applied from the canned version of the Find-Change script. But I want users to have only 3 discriminating controls to use the find/change on text files: text insertion, text frame selection, and grouped text frame selection.
I find myself hacking away, bouncing off the walls at the object model choices and trying to piece this last element in. Here is what I have at the top, where you will see I am using insertion, text frame, but then I tried to add groups.everyItem and I can't make it work. My son usually gets me through this, but I don't have him at the moment. 🙂
main();
function main(){
// enable user interaction (display of dialogs, etc.)
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if (app.documents.length <= 0) {
alert("No documents are open. Please open a document.");
return;
}
var fileName = "findChangeList.txt";
if (app.selection.length <= 0) {
// nothing was selected, so simply search the document.
alert("Nothing was selected. This script runs on selected text frames of one or more. Please use the Selection Tool.");
return;
}
var idx = app.selection.length-1;
while (idx >= 0) {
switch (app.selection[idx].constructor.name) {
case "InsertionPoint":
myFindChangeByList(app.selection[idx].parentStory, fileName);
break;
case "TextFrame":
myFindChangeByList(app.selection[idx], fileName);
break;
case "groups.everyItem()":
myFindChangeByList(app.selection[idx].parentStory, fileName);
break;
default:
alert("You must use the Selection Tool and choose one or more text frames.");
return;
break;
}
idx--;
}
}
function myFindChangeByList(myObject, fileName){
var myFindChangeFile = myFindFile(fileName);
if (!myFindChangeFile) {
alert("Unable to find " + fileName);
return;
}
myFindChangeFile = File(myFindChangeFile);
var fd = myFindChangeFile.open("r", undefined, undefined);
if (!fd) {
alert("Unable to open " + fileName);
return;
}
var myLine = myFindChangeFile.readln();
while (!myFindChangeFile.eof) {
if ((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0,5)=="glyph")||(myLine.substring(0,5)=="style")) {
var myFindType = myLine;
var myFindPreferences = myFindChangeFile.readln();
if (myFindChangeFile.eof) {
break;
}
var myChangePreferences = myFindChangeFile.readln();
if (myFindChangeFile.eof) {
break;
}
switch (myFindType) {
case "text":
myFindText(myObject, myFindPreferences, myChangePreferences);
break;
case "grep":
myFindGrep(myObject, myFindPreferences, myChangePreferences);
break;
case "glyph":
myFindGlyph(myObject, myFindPreferences, myChangePreferences);
break;
case "style":
myFindStyle(myObject, myFindPreferences, myChangePreferences);
break;
}
}
myLine = myFindChangeFile.readln();
}
myFindChangeFile.close();
}
If i understand your requirement correctly then you want to run your code over a group in your selection as well. If it so then change the case you have added with groups.everyItem() to the following
case "Group":
for(var i = 0; i < app.selection[idx].textFrames.length; i++)
myFindChangeByList(app.selection[idx].textFrames[i].parentStory, fileName);
break;
So idea is that the selection would be a single group object not the groups collection so the class name will be Group instead of gr
...Copy link to clipboard
Copied
If i understand your requirement correctly then you want to run your code over a group in your selection as well. If it so then change the case you have added with groups.everyItem() to the following
case "Group":
for(var i = 0; i < app.selection[idx].textFrames.length; i++)
myFindChangeByList(app.selection[idx].textFrames[i].parentStory, fileName);
break;
So idea is that the selection would be a single group object not the groups collection so the class name will be Group instead of groups.everyItem(). After that we run a loop for all the textFrames that is present in this group and call the method on these frames one by one
-Manan
Copy link to clipboard
Copied
Manan,
I learn something every time from your posts. Thank you so much for explaining this. Works beautifully !!
🙂