-
1. Re: Help: apply different para styles to several consecutive paragraphs via script
winterm Oct 12, 2011 4:27 PM (in response to winterm)oh, I knew it's basic, but I didn't even guess it's sooo basic...
thank you for not answering guys, I found out it...
happy scripting
-
2. Re: Help: apply different para styles to several consecutive paragraphs via script
Brian.T.Tanner Oct 13, 2011 8:52 AM (in response to winterm)Please post your solution so that others can benefit from it!
-
3. Re: Help: apply different para styles to several consecutive paragraphs via script
winterm Oct 13, 2011 12:16 PM (in response to Brian.T.Tanner)oh well, here it is...
var mySel = app.selection[0]; var myStory = mySel.parentStory; var myPStyle1 = "paragraph 1"; var myPStyle2 = "paragraph 2"; var myPStyle3 = "paragraph 3"; //you can add as much styles as you need here... myStory.paragraphs[0].appliedParagraphStyle = myPStyle1; myStory.paragraphs[1].appliedParagraphStyle = myPStyle2; myStory.paragraphs[2].appliedParagraphStyle = myPStyle3; //...and here, just specify sequence
it's simple, primitive, and not flexible. Has a lot of limitations: works on separate story only (not text frame!), formats given number of paragraphs from the beginning of the story, no matter where you click (I didn't hassle with insertionPoints). It ignores 'next Style' option in paragraph style - it can be set, can be not - no difference.
But it fits my specific needs in project I'm currently working on...
If someone of newbies (like me) has the time and eager to experiment and add some useful 'features' here - you're highly welcome
-
4. Re: Help: apply different para styles to several consecutive paragraphs via script
[Jongware] Oct 13, 2011 2:23 PM (in response to winterm)Sorry about being late to the party, I usually pick up stuff like this right away.
How about this one?
1. No separate scripts needed, it uses a tiny dialog where you can choose what style set to use. If I'm correct, you can press a number key on Windows to immediately select one of the items.
2. It works down from the paragraph your cursor is in. It has nothing to do with text frames, though -- consecutive paragraphs inside a story always ignore any text frames.
3. Extensible: you can easily change the names of the styles in the top array, and the number of style groups in the list.
var styleLists = [ [ "A", "B", "C", "D", "E", "F", "G", "H" ], [ "A", "B", "D", "E", "G", "H" ], [ "A", "C", "D", "F", "G", "H" ], [ "A", "D", "G", "H" ] ]; var radiobutts = []; styleDialog = app.dialogs.add ({name:"Set Multiple Styles",canCancel:true}); with (styleDialog) { with (dialogColumns.add()) { with (radiobuttonGroups.add()) { for (i=0; i<styleLists.length; i++) { // Build radio button string str = "&"+String (i+1)+". "; for (j=0; j<styleLists[i].length; j++) { if (j) str += "-"; str += styleLists[i][j]; } radiobutts.push (radiobuttonControls.add({staticLabel:str, checkedState:false}) ); } } } } radiobutts[0].checkedState = true; if (styleDialog.show()) { for (i=0; i<radiobutts.length; i++) { if (radiobutts[i].checkedState == true) break; } if (i < radiobutts.length) { par = app.selection[0].paragraphs[0]; for (j=0; j<styleLists[i].length; j++) { par.appliedParagraphStyle = styleLists[i][j]; par = par.parentStory.paragraphs.nextItem(par); } } } -
5. Re: Help: apply different para styles to several consecutive paragraphs via script
winterm Oct 13, 2011 2:49 PM (in response to [Jongware])Wow, hats off, here came the Master! Thank You for your precious time, Jongware. Didn't test Your solution yet (burning project), but I do believe it's 'final', as always. I'll study it on weekend... it must be very interesting.


