Skip to main content
Thiago Ribeiro Nogueira
Participating Frequently
October 28, 2020
Answered

Search for a inline object and a apply a paragraph style

  • October 28, 2020
  • 2 replies
  • 623 views

Hi!

I need to find all inline elements with a object style applied on it go to the paragraph where they are placed and apply a different paragraph style. See the images for examples.

 

Here the object style applied:

 

I want to find them, go to their paragraph:

 

And apply other paragraph style (one with spaces before and after):

 

Is this possible with a script? I'm sending the indesign files too!
Please help me.

This topic has been closed for replies.
Correct answer Manan Joshi

Hi @Thiago Ribeiro Nogueira,

Try the following code

app.findObjectPreferences.appliedObjectStyles = "box"
var r = app.activeDocument.findObject()
for(var i = 0; i < r.length; i++)
{
	if(r[i].parent.constructor.name == "Character")
		r[i].parent.appliedParagraphStyle = "space"
}
app.findObjectPreferences.appliedObjectStyles = null

-Manan

2 replies

vladan saveljic
Inspiring
October 29, 2020

Instead the box you could do a paragraph style as in my example below. Than you can easily find all these paragraphs and apply different paragraph styles.


Thiago Ribeiro Nogueira
Participating Frequently
October 29, 2020

Hi vladan!

My file is only a example file. I really want to apply paragraph style to these inline objects, because this will make easy a export HTML thing that I'm work in. But thank you for your answer!

Manan JoshiCommunity ExpertCorrect answer
Community Expert
October 29, 2020

Hi @Thiago Ribeiro Nogueira,

Try the following code

app.findObjectPreferences.appliedObjectStyles = "box"
var r = app.activeDocument.findObject()
for(var i = 0; i < r.length; i++)
{
	if(r[i].parent.constructor.name == "Character")
		r[i].parent.appliedParagraphStyle = "space"
}
app.findObjectPreferences.appliedObjectStyles = null

-Manan

-Manan
Thiago Ribeiro Nogueira
Participating Frequently
October 29, 2020

Thank you! It works!

Nice to know about that parent.constructor thing!