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

Change style basedOn

Contributor ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

Hi experts,

How to change my paragraphs style basedOn?

my script as below, but not working

var doc = app.activeDocument; 

var paraStyles = doc.allParagraphStyles;

var basicParagraphStyle1 = doc.paragraphStyles("01 Body");

var basicParagraphStyle2 = doc.paragraphStyles("06 Notes");

var paraStyles = doc.allParagraphStyles;

        for(var n=0; n<paraStyles.length; n++)    

        {

            if(paraStyles.name.match(/03|04|05|06|07|08|09|10|11|12|13|14|15|16/g)) {

                paraStyles.basedOnStyle == basicParagraphStyle1;

            }

            else if(paraStyles.name.match(/17|18|19|20|21|22|23|24|25|26|27|28|29|30/g)) {

                paraStyles.basedOnStyle == basicParagraphStyle2;

            }

    }

Could someone please give me some opinions please.

Thanks

Regard

John

TOPICS
Scripting

Views

402

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 , Nov 29, 2018 Nov 29, 2018

Hi John,

You need to look at the object model for the name of the properties you are trying to set. A good place to start exploring objects and their methods/properties is

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

Other older version of the documentation can be found at in

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

Now with regards to you code in addition to the rectifications done by Sudha K in your code i have some more points to share, look at comments in the code below

...

Votes

Translate

Translate
Contributor ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

Hi,

     Please use the below code.

var doc = app.activeDocument;  
var paraStyles = doc.allParagraphStyles;
var basicParagraphStyle1 = doc.paragraphStyles.item("01 Body");
var basicParagraphStyle2 = doc.paragraphStyles.item("06 Notes");
var paraStyles = doc.allParagraphStyles;
for(var n=0; n<paraStyles.length; n++)
{
if(paraStyles.name.match(/03|04|05|06|07|08|09|10|11|12|13|14|15|16/g)) {
paraStyles.basedOn = basicParagraphStyle1;
else if(paraStyles.name.match(/17|18|19|20|21|22|23|24|25|26|27|28|29|30/g)) {
paraStyles.basedOn = basicParagraphStyle2;
}

     When assigning value to the variable should not use "==".  "==" should be used in condition case only.

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 ,
Nov 29, 2018 Nov 29, 2018

Copy link to clipboard

Copied

Hi John,

You need to look at the object model for the name of the properties you are trying to set. A good place to start exploring objects and their methods/properties is

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

Other older version of the documentation can be found at in

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

Now with regards to you code in addition to the rectifications done by Sudha K in your code i have some more points to share, look at comments in the code below

var doc = app.activeDocument;  

var paraStyles = doc.allParagraphStyles;

var basicParagraphStyle1 = doc.paragraphStyles.item("01 Body");

var basicParagraphStyle2 = doc.paragraphStyles.item("06 Notes");

//You need to test if the pstyles you got above are valid or not, what if these styles did not exist in the document

if(!basicParagraphStyle1.isValid)

{

    alert("Style 01 Body does not exist in the document")

    exit()

}

if(!basicParagraphStyle2.isValid)

{

    alert("Style 06 Body does not exist in the document")

    exit()

}

var paraStyles = doc.allParagraphStyles;      //You don't need this line, this is done in line no 2, remove this

for(var n=0; n<paraStyles.length; n++)    

{

    if(paraStyles.name.match(/03|04|05|06|07|08|09|10|11|12|13|14|15|16/g)) {

          paraStyles.basedOn = basicParagraphStyle1;    // Here you used == instead of =, in addition to the wrong property name

    }

    else if(paraStyles.name.match(/17|18|19|20|21|22|23|24|25|26|27|28|29|30/g)) {

          paraStyles.basedOn = basicParagraphStyle2;  // Here you used == instead of =, in addition to the wrong property name

    }

}

-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
Contributor ,
Nov 30, 2018 Nov 30, 2018

Copy link to clipboard

Copied

LATEST

thanks so much Manan

John

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