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
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
...
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 | ||
paraStyles | ||
} | ||
else if(paraStyles | ||
paraStyles | ||
} | ||
} |
When assigning value to the variable should not use "==". "==" should be used in condition case only.
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
Copy link to clipboard
Copied
thanks so much Manan
John