Copy link to clipboard
Copied
Hi everyone,
I want to find-change (multi line of options) only on master
idea inspire by this line, but I am not going to find-change digit
How can I find-change only in the master pages?
thanks
Teetan
Repeating a script multiple times is surely not a good solution. I would do it in the following way.
Try to understand what is going on here and see the differences between these lines and the last script!
...if ( app.documents.length > 0 ) {
if ( app.scriptPreferences.version >= 6 ) {
app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Search in masterpages" );
}
else {
main();
}
} else {
alert ( "No documents open!" );
}
fun
Copy link to clipboard
Copied
Hi,
Use same way as for digits is used: define a target and call it like: target.changeGrep()
If your target is a collection of every stories on masterSpreads ==> you are proccessing find...change on masters in fact.
i.e.
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
mTarget.changeGrep();
You have to set all desired preferences and options of course.
Jarek
Copy link to clipboard
Copied
Hi
Jarek
but what if I want change a long list of text or grep?
Regard
Teetan
Copy link to clipboard
Copied
Hi, Jarek
I change it into this:
app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" ); |
function main(){
catchOption = app.findChangeGrepOptions.includeMasterPages;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "USA";
var
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(),
mTarget.changeGrep();
mConFound = [],
len = mFound.length;
if (len && mFound[0].constructor.name == "Array")
while (len-->0) | |
mConFound = mConFound.concat(mFound[len]); |
len = mConFound.length;
while (len-->0) {
mConFound[len].contents = "Obama"; |
}
app.findChangeGrepOptions.includeMasterPages = catchOption;
}
but not work
Teetan
Copy link to clipboard
Copied
Hi,
What about this:
app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" );
function main(){
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "USA";
app.changeGrepPreferences.changeTo = "Obama";
var
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(),
catchOption = app.findChangeGrepOptions.includeMasterPages;
app.findChangeGrepOptions.includeMasterPages = true;
mTarget.changeGrep();
app.findChangeGrepOptions.includeMasterPages = catchOption;
}
Jarek
Copy link to clipboard
Copied
Hi, Jarek
Can you tell the solution, please!
where I can put ot change this:
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
mTarget.changeGrep();
Teetan
Copy link to clipboard
Copied
Hi,
So the one from post no 4 is not a solution?
Jarek
Copy link to clipboard
Copied
Hi Jarek
I am so blunt
Can it be more specific?
Teetan
Copy link to clipboard
Copied
Hm,
code from a post no 4 is ready to run.
It finds each occurence of "USA" (can you see the line to edit?) on master pages of any opened document and change it to "Obama" (can you see the line to edit?).
Jarek
Copy link to clipboard
Copied
Unless the text frame or the layer it is sitting in is locked.
Or otherwise unavailable:
Like nested inside a group, a MSO, some other object, anchored to a text frame…
Uwe
Copy link to clipboard
Copied
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
Use same way as for digits is used: define a target and call it like: target.changeGrep()
If your target is a collection of every stories on masterSpreads ==> you are proccessing find...change on masters in fact.
i.e.
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
mTarget.changeGrep();
You have to set all desired preferences and options of course.
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
How can I do that?
Copy link to clipboard
Copied
Hi,
Jeark
We here made a misundersdanding:
//--------------------------------------------------------------------------------------------------
app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" );
function main(){
app.findGrepPreferences = changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "USA";
app.changeGrepPreferences.changeTo = "Obama";
app.findGrepPreferences.findWhat = "rocket";
app.changeGrepPreferences.changeTo = "sky";
app.findGrepPreferences.findWhat = "New York"; // only work on this line
app.changeGrepPreferences.changeTo = "Losangeles";
var
mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(),
catchOption = app.findChangeGrepOptions.includeMasterPages;
app.findChangeGrepOptions.includeMasterPages = true;
mTarget.changeGrep();
app.findChangeGrepOptions.includeMasterPages = catchOption;
}
//--------------------------------------------------------------------------------------------------
it will not work on a list
//==========================================================
Hi
Jarek
but what if I want change a long list of text or grep?
Regard
Teetan
//==========================================================
so it will only can change one thing right?
thank you for your help, thank you so much
Teetan
Copy link to clipboard
Copied
Hi,
Agree, it is a misunderstanding at sure.
Jarek
Copy link to clipboard
Copied
Teetan, don’t use code without understand what those lines does 😉 Remember: A script can only do, what you can do in the interface.
In the interface you would fill in findTo and changeTo. After that, you would click on the button change(). Nothing else with scripting.
So if you insert mTarget.changeGrep(); multiple times, you will get your desired result. Of course, this can be written shortener with a for-loop.
Copy link to clipboard
Copied
thank you jarek,
and sorry
thank you all guys
I will repeat the script again and again
Teetan
Copy link to clipboard
Copied
Repeating a script multiple times is surely not a good solution. I would do it in the following way.
Try to understand what is going on here and see the differences between these lines and the last script!
if ( app.documents.length > 0 ) {
if ( app.scriptPreferences.version >= 6 ) {
app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Search in masterpages" );
}
else {
main();
}
} else {
alert ( "No documents open!" );
}
function main() {
// Your settings
// ---
var searchList = [
[ "USA" , "Obama" ],
[ "rocket" , "sky" ],
[ "New York" , "Los Angeles" ]
];
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeMasterPages = true;
var target = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
for ( var j = 0; j < searchList.length; j++ ) {
var curSearch = searchList
; app.findGrepPreferences.findWhat = curSearch[0];
app.changeGrepPreferences.changeTo= curSearch[1];
target.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
} // main
– Kai
Copy link to clipboard
Copied
Hi,
As Kai said, to understand a code is a basic step you should do.
I would modify Kai's code in case of mTarget declaration point ==> I mean I would redeclare it inside each for...loop's run (at the end of loop).
Just in case we are working with changing contents here.
Jarek
Copy link to clipboard
Copied
Hi
and thank you all guys, for your help
appreciate
Teetan
Copy link to clipboard
Copied
quite amazing!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now