Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can find-change grep only on Masters

Explorer ,
Jul 27, 2014 Jul 27, 2014

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

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 29, 2014 Jul 29, 2014

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

...
Translate
Mentor ,
Jul 27, 2014 Jul 27, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 27, 2014 Jul 27, 2014

Hi

Jarek

but what if I want change a long list of text or grep?

Regard

Teetan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 27, 2014 Jul 27, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 27, 2014 Jul 27, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2014 Jul 28, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 28, 2014 Jul 28, 2014

Hi,

So the one from post no 4 is not a solution?

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2014 Jul 28, 2014

Hi Jarek

I am so blunt

Can it be more specific?

Teetan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 28, 2014 Jul 28, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2014 Jul 28, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2014 Jul 28, 2014

//------------------------------------------------------------------------------------------------------------------------------------------------------------------

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2014 Jul 28, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 28, 2014 Jul 28, 2014

Hi,

Agree, it is a misunderstanding at sure.

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 28, 2014 Jul 28, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2014 Jul 28, 2014

thank you jarek,

and sorry

thank you all guys

I will repeat the script again and again

Teetan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 29, 2014 Jul 29, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 29, 2014 Jul 29, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2014 Jul 29, 2014

Hi

and thank you all guys, for your help

appreciate

Teetan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2014 Jul 29, 2014
LATEST

quite amazing!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines