Skip to main content
Participant
September 11, 2014
Answered

Replacing based on style

  • September 11, 2014
  • 1 reply
  • 414 views

Hello,

I have a series of documents in which a number of stylesheets are based on "Basic Paragraph". I want to change them all to be based on No Paragraph Style. The script below targets the correct folder (Fonts, within General), but there is something wrong with my syntax in the loop (line 15).

Thanks in advance for any help with this.

Tim

var myDoc = app.activeDocument;

var theseStyles = myDoc.paragraphStyleGroups.itemByName ("General");

var targetStyles = theseStyles.paragraphStyleGroups.itemByName("Fonts");

var numberStyles = targetStyles.allParagraphStyles.length;

alert(numberStyles);

for  (var i = 0; i<numberStyles; i++){

   

    var currentStyle = targetStyles.allParagraphStyles;

    if (currentStyle.basedOn = "Basic Paragraph"){

        currentStyle.basedOn = "No Paragraph Style";

     }

}

This topic has been closed for replies.
Correct answer Chinnadk

       if (currentStyle.basedOn = "Basic Paragraph"){ 

        currentStyle.basedOn = "No Paragraph Style";

Change these two lines like below

    if (currentStyle.basedOn = myDoc.paragraphStyles.item("[Basic Paragraph]")){ 

        currentStyle.basedOn =  myDoc.paragraphStyles.item("[No Paragraph Style]"); 

1 reply

Chinnadk
ChinnadkCorrect answer
Legend
September 11, 2014

       if (currentStyle.basedOn = "Basic Paragraph"){ 

        currentStyle.basedOn = "No Paragraph Style";

Change these two lines like below

    if (currentStyle.basedOn = myDoc.paragraphStyles.item("[Basic Paragraph]")){ 

        currentStyle.basedOn =  myDoc.paragraphStyles.item("[No Paragraph Style]"); 

Participant
September 11, 2014

Thanks Chinnadk - that works now. But am i right in thinking that you have replicated my original mistake, and the first line should read:

if (currentStyle.basedOn == myDoc.paragraphStyles.item("[Basic Paragraph]")){


ie. two equals signs to test truth, rather than one to assign value.