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

FindChangeByList—local formatting to a character style

Community Expert ,
Oct 18, 2018 Oct 18, 2018

Copy link to clipboard

Copied

I'm back.

I'm making progress—thanks winterm​ and [Jongware]​—but am stuck again. This time I am trying to target local formatting from a Word doc (italics and small caps) and change it to my existing Italic (and eventually SmallCaps) character style(s).

Seems like it might be something like this, but that's not working. No error message, just ignored. Any thoughts?

grep {findWhat:".",fontStyle:"Italic"} {changeTo:"$0",appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Notes: I have the style called Italic (not in a folder) and the text I'm looking for is Italic (not Oblique or some other variation):

Screenshot 2018-10-18 17.25.27.png

TIA,

~Barb

TOPICS
Scripting

Views

4.6K

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 , Oct 19, 2018 Oct 19, 2018

Hi Barb,

Works for me, one pointer please replace the space with tab after grep and also after }. I noticed that copying and pasting from the forum replaces tab with another character and hence the code does not work. See the instructions in the FindChangeList.txt file for details, i am pasting the relevant line below

findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

Let me know if it works.

-Manan

Votes

Translate

Translate
Community Expert ,
Oct 18, 2018 Oct 18, 2018

Copy link to clipboard

Copied

I have a bunch of these to work through. Is there a resource somewhere with examples of the various options? For my next one I'll need to find a tab, replace with an en space and assign a para style that is contained within a folder. I have the first part working but have no idea how to reference a style contained within a folder.

~Barb

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 ,
Oct 18, 2018 Oct 18, 2018

Copy link to clipboard

Copied

Regarding using style present in the folders with FindChangeByList.jsx, the issue is that styles within folder can't be accessed directly using its name as done by this script code

So we will have to send something more that just the style name to the FindChangeByList.jsx in order for the code to get the correct style. If we take the original sample and suppose that the character style was within a folder, then the string argument for the script would be something as below

grep {fontStyle:"Italic"} {appliedCharacterStyle:app.doScript('function getStyle(){var cs = app.activeDocument.allCharacterStyles;for(var i = 0; i < cs.length; i++){if( cs[i].name == "Italic" ) return cs[i]}}getStyle()', ScriptLanguage.javascript)} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

For finding the paragraphstyles within folders use the following string

grep {fontStyle:"Italic"} {appliedParagraphStyle:app.doScript('function getStyle(){var ps = app.activeDocument.allParagraphStyles;for(var i = 0; i < ps.length; i++){if( ps[i].name == "Italic" ) return ps[i]}}getStyle()', ScriptLanguage.javascript)} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

P.S. :- In the above string change the name of the paragraphStyle or characterstyle to be found in the line cs[i].name == "Name of CStyle you want to search" and similarly ps[i].name == "Name of PStyle you want to search"

 

Hope this helps, this is my take to the solution, would like to know if someone has any other less complex way of achieving this.

 

-Manan

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 ,
Oct 18, 2018 Oct 18, 2018

Copy link to clipboard

Copied

Hi Barb,

You could use the following string

grep {fontStyle:"Italic"} {appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

-Manan

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Hi Manan Joshi:

First of all, thank you for helping.

However, it's still not working. After running the script with just your line, the character style still isn't getting applied.

Screenshot 2018-10-19 06.53.22.png

  And separately, are the words "findWhat:" and "changeTo:" optional when simply doing a format find/change?

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Hi Barb,

Works for me, one pointer please replace the space with tab after grep and also after }. I noticed that copying and pasting from the forum replaces tab with another character and hence the code does not work. See the instructions in the FindChangeList.txt file for details, i am pasting the relevant line below

findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

Let me know if it works.

-Manan

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Yes, that was it, and again, this is documented in the file at the top. I feel like such a numbskull.

On to the paragraph style application with the tab/en dash switch... I'll be back with an update.

THANK YOU, Manan Joshi!

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Hi Manan:

I think I have worked through one of each of the types of strings I need and can probably take it from here. I do have one last (hopefully) easy question on the same topic

Just like the find local italics and replace with my character style called Italic, I'll need to locate and update small caps and superscript text. Using the string you provided above, how do I reference the fontStyle for each? Is this correct? (Because of course neither one is working, and I did remember the tabs.)

{fontStyle:"Smallcaps"}

{fontStyle:"Superscript"}

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Hi Barb,

These are not fontStyles, you can try the following

{position : Position.SUPERSCRIPT}

{capitalization : Capitalization.SMALL_CAPS}

Let me know if it does not work, have not tested it fully.

-Manan

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Yes, and yes! So how do you know all this? Is there a good online reference I can review? I can't seem to make any leaps in logic on my own.

Now working on removing small caps applied to digits.

grep     {findWhat:"\\d+", appliedCharacterStyle:"Small Caps"}     {appliedCharacterStyle:"None"}     {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Which of course, does not work.

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Its a bit involved, its basically scripting InDesign and you will need to browse the Object model to get the options. I will try to explain it as best as i can trying not to confuse you.

So for find options in Grep you can look for options at

Adobe InDesign CS6 (8.0) Object Model JS: FindGrepPreference

Similarly for change options in Grep you can look for options at

Adobe InDesign CS6 (8.0) Object Model JS: ChangeGrepPreference

For every option you will also see the type of values that it takes and if it is a special value you can get the relevant values by clicking on the hyperlink, like i gave you the values for position and capitalization options

Similarly for text find options look at

Adobe InDesign CS6 (8.0) Object Model JS: FindTextPreference

And for text change options it is

Adobe InDesign CS6 (8.0) Object Model JS: ChangeTextPreference

I hope this did not create confusion and did add some value to your understanding. If you want to search for glyphs and objects  similar objects exist for them as well. So in a nutshell the FindChangeByList.jsx does nothing but takes the values for these options and executes it.

And now i would like you to try and solve the current problem you have, by using the newly found tricks that are mentioned above. Let me know how it goes.

-Manan

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Again, thank you so much. I'm on to laying out a document now but will cycle back to this and let you know if I can solve this final piece on my own.

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Of course I couldn't wait.

Ok, so I can now succesfully change my digits from one character style to another (in this example, Small Caps to Superscript):

grep     {findWhat:"(\\d+)", appliedCharacterStyle:"Small Caps"}     {changeTo:"$1",appliedCharacterStyle:"Superscript"}            {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

This means the first part of the string is correct, right? But changing it from Small Caps to None continues to elude me.

grep     {findWhat:"(\\d+)", appliedCharacterStyle:"Small Caps"}     {changeTo:"$1",appliedCharacterStyle:""}            {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

~Barb

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 ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

Use the value "[No paragraph style]" for applying no paragraph style and the value "[No character style]" for applying None as character style.

-Manan

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 ,
Oct 20, 2018 Oct 20, 2018

Copy link to clipboard

Copied

Hi Manan:

That was it, and between your answers and [Jongware]'s reference, I was able to complete my list.

I've used inDesign daily since it was released, and while I knew about FindChangeByList, I never took the time to figure out how to use it. Instead, I would run a lengthy series of saved sequential Find/Change queries. I came back from Adobe MAX inspired to update my templates and streamline my workflow.

With your help, the layout for one of my longer documents is nothing less than magical and I've learned so much.

Again, thank you!

~Barb

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 ,
Oct 20, 2018 Oct 20, 2018

Copy link to clipboard

Copied

Hi Barb,

just to complete the list of DOM documentation references:

For InDesign CC 2019 Gregor Fellenz compiled this one:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

Others also by Gregor can be found here:

https://www.indesignjs.de/extendscriptAPI/

Cheers,
Uwe

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 ,
Oct 20, 2018 Oct 20, 2018

Copy link to clipboard

Copied

Thanks, Uwe!

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
Explorer ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

I was looking for some documentation on the correct structure of the grep string within the .txt file used by FindChangeByList to target character styles and paragrahstyles and I end up in this thread. Seems to me Manan has it all sorted out .

Perhaps BarbBinder​ you can enlighten me as well on this...

How can I target a used character style and change that to another? So not targeting a specific string, but specific styles...

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

You can look at my comments above for full description, however its very simple. For example if you need to change the character style named "Original" to "Italic" in your document you need to use the following string

grep {appliedCharacterStyle:"Original"} {appliedCharacterStyle:"Italic"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

The first string inside the {} after grep identifies the properties to be searched and the next one identifies the properties to be applied once the search matches. You can look at the full list of properties you can use by referring the following links

Find properties for Grep (the ones you would use to search as explained above)

Adobe InDesign CS6 (8.0) Object Model JS: FindGrepPreference

Replace properties for Grep

Adobe InDesign CS6 (8.0) Object Model JS: ChangeGrepPreference

The other thing that i explained in the above posts was the case of using the character styles and paragraph styles which are present in folders. Since such styles can't be accessed directly by their names in the script, we would need to pass in some JS code in the find/change string and that is what i have done

Hope this helps you to understand and get your task done

-Manan

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
Explorer ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Hi Manan, thanks for chiming in. Unfortunately when I use the mentioned code it is not working; the already applied style is not changed to the new one. This is what I have put in the FindChangeList.txt:

grep  {appliedCharacterStyle:"Italic"} {appliedCharacterStyle:"[No character style]"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

I used tabs between the } { characters.

When I combine a find and replace with the applied style like Barb did, like this line of code:

grep  {findWhat:"\\s~_\\s", appliedCharacterStyle:"Italic"} {changeTo:"~_", appliedCharacterStyle:"[No character style]"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

I get an Javascript error stating "Expected: } (...) Source: app.doScript(myString, ScriptLanguage.javascript);

- but I did not change that piece of code.

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

I was able to successfully use your first string and the change did happen, mind that you need to separate each field with a tab so there has to be a tab between grep and { as well. The string should be something like the following

grep<tab>{appliedCharacterStyle:"Italic"}<tab>{appliedCharacterStyle:"[No character style]"}<tab>{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}

Also with regards to the second string i did not get any error.

-Manan

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 ,
Jun 17, 2019 Jun 17, 2019

Copy link to clipboard

Copied

Hi Peter,

is any of your character styles used with the list in a character style group?

Regards,
Uwe

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
Explorer ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

Hi Uwe,

no, the character styles are not in a group - but when they were the code should be somewhat more complicated, right?

Manan Joshi​ for me the code in the .txt file is not working... I don't know why. I have ID 14.0.2. I created a blank doc and created two character styles: "italic" and "bold". Then I used your .txt example to strip these styles. But to no avail... I wrote a script to strip styles and that's working so I use that instead, although I really do find it frustrating not being able to strip styles using the already provided script by Adobe...

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 ,
Jun 18, 2019 Jun 18, 2019

Copy link to clipboard

Copied

Hi peteremil,

Its difficult to identify issue this way, if possible share the InDesign document with the findchange.txt file and we can see what the issue is.

-Manan

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
Explorer ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

You are totally right Manan Joshi​, I'll see how I can upload my files. This is the first time for me so I'll have to get myself acquainted with the forum ins & outs

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