Answered
Update the script that find paragraph style and change with another style + next styles
Hi everyone,
Is it possible to set this script (by @luis_guimaraes) so that every time it encounters the "Title" style it starts over with the "Text1" style and then the Next styles?
For example:
"Title" -"Text1" - "Text2" - "Text3"" - "Text2" - "Text3" ....... "Title" - "Text1" - "Text2" - "Text3"" - "Text2" - "Text3" ...
Thank you in advance
app.doScript(Main, language=ScriptLanguage.JAVASCRIPT, withArguments=[],
undoMode=UndoModes.ENTIRE_SCRIPT, undoName='Testing');
function Main(){
//reference to each style
const titleStyle = app.activeDocument.paragraphStyles.itemByName('Title')
const textStyle1 = app.activeDocument.paragraphStyles.itemByName('Text1')
const textStyle2 = app.activeDocument.paragraphStyles.itemByName('Text2')
const textStyle3 = app.activeDocument.paragraphStyles.itemByName('Text3')
//selected paragraphs (including first title)
var paras = app.selection[0].paragraphs;
var prevstyle = paras[0].appliedParagraphStyle;
for (i=1; i<paras.length; i++){
var para = paras[i];
var curstyle = para.appliedParagraphStyle;
//ignore titles
if (curstyle==titleStyle){
continue;
}
//apply new style
if (prevstyle==titleStyle){
para.applyParagraphStyle(textStyle1);
}
else if (prevstyle==textStyle1){
para.applyParagraphStyle(textStyle2);
}
else if (prevstyle==textStyle2){
para.applyParagraphStyle(textStyle3);
}
else if (prevstyle==textStyle3){
para.applyParagraphStyle(textStyle2);
}
//update prev
prevstyle = para.appliedParagraphStyle;
}
}
