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

Don't search inside tables or skip tables

New Here ,
May 11, 2022 May 11, 2022

Copy link to clipboard

Copied

Hi, I'm new to scripts.
Performing searches I can apply styles to specific words, so far so good, but the problem is that my document has many tables where that searched word is also present, is there a way to apply the style only in the document and not in the tables? Maybe using script?
I would appreciate your help. And sorry for my writing, I don't speak English well.

 

I am attaching a picture so you can better understand what I want.

TOPICS
Scripting

Views

141

Translate

Translate

Report

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

Community Expert , May 11, 2022 May 11, 2022

Hi Jesuale,

the basic algorithm could be this:

[1] Run a GREP Find action and store the found texts to an array.

[2] Loop that array of results and check the parent of the found text snippets.

If the parent is a cell, do nothing and continue to the next found item.

If the parent is not a cell do a change to that found text.

 

Look up this discussion we recently had:

 

[JS] Problem with change grep with look behind/ahead and /K
Kasyan Servetsky, Mar 16, 2022

https://community.adobe.com/t5/indesign-discussions/js-problem-with-change-grep-with-look-behind-ahead-and-k/m-p/12818708#M469736

...

Votes

Translate

Translate
Community Expert ,
May 11, 2022 May 11, 2022

Copy link to clipboard

Copied

Hi Jesuale,

the basic algorithm could be this:

[1] Run a GREP Find action and store the found texts to an array.

[2] Loop that array of results and check the parent of the found text snippets.

If the parent is a cell, do nothing and continue to the next found item.

If the parent is not a cell do a change to that found text.

 

Look up this discussion we recently had:

 

[JS] Problem with change grep with look behind/ahead and /K
Kasyan Servetsky, Mar 16, 2022

https://community.adobe.com/t5/indesign-discussions/js-problem-with-change-grep-with-look-behind-ahe...

 

In a nutshell the code below should work for you with GREP Find/Change. Not intensively tested, though. That's your job. To make that work do the following:

[1] Do your settings in InDesign's GREP Find/Change normal user interface.

[2] Then as a second step run this ExtendScript (JavaScript) code:

 

 

/*
Posted by Uwe Laubender at the InDesign User Forum:
https://community.adobe.com/t5/indesign-discussions/don-t-search-inside-tables-or-skip-tables/m-p/12937086#M476815
*/

( function()
{

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

app.doScript
(
	ignoreTables, 
	ScriptLanguage.JAVASCRIPT, 
	[],
	UndoModes.ENTIRE_SCRIPT, 
	"Find/Replace GREP; Leave out Tables | SCRIPT"
);

function ignoreTables()
{
	var txt, changed,
	doc = app.activeDocument,
	found = doc.findGrep(false);
	
	for (var i = 0; i < found.length; i++)
	{
		// IGNORE TEXT IN TABLE CELLS:
		if( found[i].parent.constructor.name == "Cell" ){ continue };
		
		// TEXT OUTSIDE TABLE CELLS:
		
		txt = found[i];
		app.findGrepPreferences.findWhat = txt.contents;
		changed = txt.changeGrep();
	};

};

}() )

 

 

If the result is not to your liking you can undo the whole thing with one single undo that is reading:

"Find/Replace GREP; Leave out Tables | SCRIPT"

 

Thanks Kasyan Servetsky for providing the core part of the code.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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 ,
May 11, 2022 May 11, 2022

Copy link to clipboard

Copied

Note: EDITED my post above, because I did some comments to the code.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
New Here ,
May 11, 2022 May 11, 2022

Copy link to clipboard

Copied

LATEST

Thank you very much Laubender the code worked perfectly, I appreciate it very much, I will review the link you gave me to learn much more.

 

Greetings from Bolivia
Jesus Aguilar

Votes

Translate

Translate

Report

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