Copy link to clipboard
Copied
Hi community,
i would like to find a solution for the next problem
I have a 400 pages book with a text set up in this way:
paragraph style "Subtitle 1" then
paragraph style "Body text"
paragraph style "Body text"
paragraph style "Body text"
paragraph style "Body text"
(the number of paragraphs "Body text" isn't a fix number
...
paragraph style "Subtitle 1" then
paragraph style "Body text"
paragraph style "Body text"
paragraph style "Body text"
paragraph style "Body text"
etc.
...
I would like to find, in selection text, all paragraps "Body text" between each "paragraph style "Subtitle 1" and apply paragraph styles in this way
"My new style 1"
than next style "My new style 2"
then next style "My new style 3"
than next style "My new style 2"
then next style "My new style 3"
....
until the next paragraph style "Subtitle 1"
and than repeat all until the and of selection
Is this possible with a script?
Thank you in advance
Marko
You can tweek it to suit your needs better:
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
...
Copy link to clipboard
Copied
You can tweek it to suit your needs better:
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;
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi everyone,
Is it possible to set this script 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