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

Character style "[None]" is not working in my script. pls correct my script

Participant ,
Mar 19, 2014 Mar 19, 2014

Copy link to clipboard

Copied

Actually I want to apply the character style “[None]” for Head B, so I write the script as like below but its show the error. please help for this

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.appliedParagraphStyle = "Head B";

app.findTextPreferences.appliedCharacterStyle= "";

app.changeTextPreferences.appliedParagraphStyle = "";

app.changeTextPreferences.appliedCharacterStyle= "[None]";

app.activeDocument.changeText ();

TOPICS
Scripting

Views

1.7K

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 , Mar 21, 2014 Mar 21, 2014

@Mi_D – another variant, a briefer one, would be:

app.changeTextPreferences.appliedCharacterStyle = app.characterStyles[0];

Since you cannot move that character style around in the Character Style Panel and you cannot remove it, you can always use the first one in the collection to target "[None]".

Note:


Nearly the same goes for the paragraphStyle collection.

But here you have to be very careful!

Never confuse paragraphStyles[0] with paragraphStyles[1], be it called from the app or a specific document

...

Votes

Translate

Translate
Contributor ,
Mar 20, 2014 Mar 20, 2014

Copy link to clipboard

Copied

hi hasvi

change the app.changeTextPreferences.appliedCharacterStyle= "[None]"; to below line and try

app.changeTextPreferences.appliedCharacterStyle= app.activeDocument.characterStyles.item("[None]");

Mi_D

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 ,
Mar 21, 2014 Mar 21, 2014

Copy link to clipboard

Copied

@Mi_D – another variant, a briefer one, would be:

app.changeTextPreferences.appliedCharacterStyle = app.characterStyles[0];

Since you cannot move that character style around in the Character Style Panel and you cannot remove it, you can always use the first one in the collection to target "[None]".

Note:


Nearly the same goes for the paragraphStyle collection.

But here you have to be very careful!

Never confuse paragraphStyles[0] with paragraphStyles[1], be it called from the app or a specific document.

paragraphStyles[0] is something like a contradiction, or better its name is something like a contradiction.

It's not the basic paragraph style you can look up in the Paragraph Styles Panel.

paragraphStyles[0] is apparently part of the collection of paragraph styles, but it is the NO paragraph style. Never ever change values of one of its properties! Never! Its name is localized. In my German version of InDesign its "[Kein Absatzformat]" (No Paragraph Style).

paragraphStyles[1] instead is the basic paragraph style.

Its name is localized and has changed in the history of InDesign versions. In my German versions of InDesign:

CS3 and CS4: [Einfacher Absatz] (Basic Paragraph)

CS5 and above: [Einf. Abs.] *

So be careful calling it by name.

Setting a swatch using its index would be dangerous!

Swatches are freely moveable in the Swatches Panel. You cannot count on the fact that "[None]" is the first one in the collection.

* Changing the name of the [Basic Paragraph] in the German localized version of InDesign from CS4 to CS5 was a really weird decision by Adobe.

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
Guest
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hello @Laubender,
Although this discussion is old, I would like to ask:
How would you assign Based On: [No Paragraph Style] to an existing paragraph style, via scripting?

Using paragraphStyles[0] returns an error. Same observation for '' and null.

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 ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

hi @Deleted User , In case @Laubender  doesn‘t respond you can get [No Paragraph Style] by name. This would change all to [No Paragraph Style] :

 

var ps = app.activeDocument.allParagraphStyles;
var np = app.activeDocument.paragraphStyles.itemByName("[No Paragraph Style]")
for (var i = 1; i < ps.length; i++){
   ps[i].basedOn = np
}; 

 

 

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
Guest
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Thank you @rob day . That works well.
I will continue to look for an "internationalizable" solution, because in this case, if the system language is modified, it no longer matches.

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 ,
Feb 24, 2024 Feb 24, 2024

Copy link to clipboard

Copied

Maybe this?

 

var ns = app.activeDocument.paragraphStyles.itemByID(app.activeDocument.paragraphStyles[0].id)
$.writeln(ns.name) 
//returns [No Paragraph Style]

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 ,
Feb 24, 2024 Feb 24, 2024

Copy link to clipboard

Copied

quote

Hello @Laubender,
Although this discussion is old, I would like to ask:
How would you assign Based On: [No Paragraph Style] to an existing paragraph style, via scripting?

Using paragraphStyles[0] returns an error. Same observation for '' and null.


By @Deleted User

 

Can you show your code?

 

app.activeDocument.paragraphStyles[3].basedOn = app.activeDocument.paragraphStyles[0];

 

As long as 3rd element is a ParaStyle, not a ParaStyleGroup.

 

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
Guest
Feb 24, 2024 Feb 24, 2024

Copy link to clipboard

Copied

LATEST

@Rob @robert Indeed, it works. My error obviously came from my loop, in which I declared i = 0. The style [0] was included by mistake. Thank you both.

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

Thanks Laubender.

That worked for me in my FindChangeByList.txt file perfectly. You should get credit for the shortened version.

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