Skip to main content
Inspiring
August 13, 2011
Answered

ObjectStyle with ParagraphStyle

  • August 13, 2011
  • 1 reply
  • 1623 views

Dear people,

Is there a way to find a ParagraphStyle and give it a ObjectStyle trough scripting.

So,

1. find ParagraphStyle "Paragraph01" in textframe,

2. give textframe ObjectStyle "ObjectStyle1"

Already thanks for the help!

Greatings from Holland!

This topic has been closed for replies.
Correct answer Jongware

(Please use the Javascript Syntax Highlighting from the tool bar to make your code more readable -- click the ">>" icon, then choose "Syntax highlighting", then "Java". (Yes I know, "Java is NOT Javascript", but Jive doesn't know and doesn't care.))

This is plain Wrong:

for (i=0; i<myFind.length; i++)

{ myText = app.findTextPreferences.appliedParagraphStyle=myParagraphStyle;

myText.contents=myFind.contents;

myText.appliedObjectStyle = myDoc.objectStyles.item(myObjectStyle);

}

Why are you setting the variable myText to point to a Paragraph style? Why are you changing the 'contents' of this Paragraph Style to the found text contents? Why are you attempting to set an Object Style to a Paragraph style? Neither of these three operations make any sense at all.

Throw these 3 lines away, and use something like this:

myFind.parentTextFrames[0].appliedObjectStyle = myDoc.objectStyles.item(myObjectStyle);

Untested but sure to edge closer to your intentions.

1 reply

John Hawkinson
Inspiring
August 14, 2011

Sure. You can loop over all TextFrames in the document, then loop over all their constitutent pargraphs and see if it matches your style, and if so apply the object style to the TextFrame.

Inspiring
August 14, 2011

Alright thanks,

Didn't know if it was possible, I will puzzle the script togheter.