...and any suggestions on how to paste code without the mess up above would be good too!
The problem here is that JS silently looks up things if it cannot apply your current command. In the case of setting a paragraph style, you can feed it a string, but that actually gets checked against the current list of paragraph styles, and it's the style itself that gets used.
This ought to work:
myGroup = app.activeDocument.paragraphStyleGroups.item("PRO"); myDirectLinkToAStyle = myGroup.paragraphStyles.item("PRO - Product Heading :+color); .. stuff here .. myStory.paragraphs[ii].appliedParagraphStyle = myDirectLinkToAStyle;
Untested, untried, etc. You know the drill.
(I always type a post in full before daring to click any of the horrendous Jive formatting buttons. I find it inexplicably difficult to edit code with that weird and unpredictably-behaving Code Formatting thingamajig. Before not-that-long-ago, I simply switched to HTML mode and injected my edits straight into the correct place, but -- oh sadness! -- New and Improved Jive seems to bracket each and every single character with some "function (bladiblah) (release(whatever))" crap code.
Since the Adobe programmers seem to have grown a liking to Flash, WRITE A FLASH EDITOR for the forums! Or simply buy one -- I've seen a-plenty online Flash editors with lotsa nice features. Either way, get rid of this Jive bull.)
Sorry, I didn't title this thread correctly. Now sorted, and linked to via a new thread. If only I could edit the title but alas no
Thanks heaps. I had to adapt the script slightly as I couldn't pass the style name in the way you suggested, I needed to construct a string and pass that instead:
myParaGroup = app.activeDocument.paragraphStyleGroups.item("Pro");
myNewStyleString = "PRO - Product Heading " + myColour;
myDirectLinkToAStyle = myParaGroup.paragraphStyles.item(myNewStyleString);
myStory.paragraphs[ii].appliedParagraphStyle = myDirectLinkToAStyle;
Anyway, thanks again, you have made my client very happy!