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

Find/Change by list script substitute fontStyle by character style

Community Beginner ,
Mar 05, 2019 Mar 05, 2019

I'm trying to use the built-in find-change script by list to find fontStyle:"Italic" applied to any text and apply a character style to the found results. I've tried the 'RecordFindChange' script and tried to edit the search query in line with the examples, but to no avail.

I've also tried to find the reference that explains all possible find and change properties, but no success yet.

The query that I thought should work is below, but my CC 2017 returns the error number 25, expected: :

text    {fontStyle:"Italic"}    {appliedCharacterStyle:"Italic EN"}    {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}    comment

Thanks in advance for any help you can offer!

Titus

TOPICS
Scripting
2.5K
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

Community Expert , Mar 06, 2019 Mar 06, 2019

Hi Titus,

 

If you want to make it work with character styles nested inside groups then you can look at one of the other threads in which i solved this issue for paragraphStyles.

FindChangeByList—apply a paragraph tag that resides in a folder

 

In the post marked correct change paragraphstyle to character style and it should work for you, like below

appliedCharacterStyle:app.doScript('function getStyle(){var cs = app.activeDocument.allCharacterStyles;for(var i = 0; i < cs.length; i++){if( cs[i].

...
Translate
Community Expert ,
Mar 05, 2019 Mar 05, 2019

use the following

text {fontStyle:"Italic"} {appliedCharacterStyle:"Italic EN"} {includefootnotes:true, includemasterpages:true, includehiddenlayers:true, wholeword:false}

notice the space you have between include footnotes and others is not needed this is what causes the error

-Manan

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 Beginner ,
Mar 05, 2019 Mar 05, 2019

Thank you for the quick reply!

Unfortunately it doesn't quite solve it yet, but returns a new error: number 30477, Invalid parameter.

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 ,
Mar 05, 2019 Mar 05, 2019

Works for me. Make sure to replace the space to tabs as instructed in the FindChangeList.txt regarding the string format, forum copy paste messes it. Have a look below at things working for me using this same string

Find:Change.gif

-Manan

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 Beginner ,
Mar 05, 2019 Mar 05, 2019

Manan, thanks for following up. I tested it as you did with a new simple test document, where it worked fine for me too. The reason I couldn't get it to work in the first place was that the style was organised within a folder, and apparently the script does not find it this way.

Many thanks for your help!

Titus

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 ,
Mar 06, 2019 Mar 06, 2019

Hi Titus,

 

If you want to make it work with character styles nested inside groups then you can look at one of the other threads in which i solved this issue for paragraphStyles.

FindChangeByList—apply a paragraph tag that resides in a folder

 

In the post marked correct change paragraphstyle to character style and it should work for you, like below

appliedCharacterStyle:app.doScript('function getStyle(){var cs = app.activeDocument.allCharacterStyles;for(var i = 0; i < cs.length; i++){if( cs[i].name == "Italic EN" ) return cs[i]}}getStyle()', ScriptLanguage.javascript)}

 

Edit:Fixed the code issue which occured due to forum migration

-Manan

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 Beginner ,
Mar 06, 2019 Mar 06, 2019

Fabulous, many thanks Manan!

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 Beginner ,
Mar 06, 2019 Mar 06, 2019

Just following up on this with a slight modification. From what I can gather, the same script does not work for GREP queries and replacements, is that correct?

I've tried to figure it out myself using this:

https://www.indesignjs.de/extendscriptAPI/indesign10/#ChangeGrepPreference.html

But I can't see any differences between GREP and Text preferences.

I've tried these queries:

grep    {findWhat:"\(\d+:\d+\)"}    {appliedCharacterStyle:app.doScript('function getStyle(){var cs = app.activeDocument.allCharacterStyles;for(var i = 0; i < cs.length; i++){if( cs.name == "Quranic verse reference EN" ) return cs}}getStyle()', ScriptLanguage.javascript)}    {includefootnotes:true, includemasterpages:true, includehiddenlayers:true, wholeword:false}

grep    {findWhat:"^\d+\.\t"}    {appliedParagraphStyle:app.doScript('function getStyle(){var ps = app.activeDocument.allParagraphStyles;for(var i = 0; i < ps.length; i++){if( ps.name == "P1 no indent EN" ) return ps}}getStyle()', ScriptLanguage.javascript)}    {includefootnotes:true, includemasterpages:true, includehiddenlayers:true, wholeword:false}

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 ,
Mar 06, 2019 Mar 06, 2019

The first one did work for me, the issue is that you need to double escape your string, try with the following

\\(\\d+:\\d+\\)

-Manan

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 Beginner ,
Mar 06, 2019 Mar 06, 2019

Double escape! Thank you so much, I'm learning...

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 ,
Mar 06, 2019 Mar 06, 2019
LATEST

I was literally just about to post a question and saw this thread. The solution was to double escape! Thank you so much!

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