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 ();
@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
...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
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
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.
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
};
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.
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]
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.
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.
Copy link to clipboard
Copied
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.