Help with script to apply object style

Explorer ,
Mar 11, 2022 Mar 11, 2022

Copy link to clipboard

Copied

Hello:
I'm trying to appy an object style to a faux ad. The style places the ad were is should be positioned on the page. 
But I keep getting an error when I run the script, so I'm sure I have some sytax issues, but I don't know how to correct the issue. I would appreicate any help anyone can offer.
Here is what I have so far.
Thanks

var mySelection = app.selection[0];

app.selection[0]appliedObjectStyle(app.activeDocument.objectStyles("FR Top Ad"),true);

app.menuActions.itemByName('Bring to Front').invoke();


var myObj = app.selection[0];
myObj.rotationAngle = -5;

TOPICS
Scripting

Views

173

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Mar 14, 2022 Mar 14, 2022
app.selection[0].applyObjectStyle( app.activeDocument.objectStyleGroups.itemByName("Advertising").objectStyles.itemByName("FR Top Ad") );

Likes

Translate

Translate
Adobe Community Professional ,
Mar 11, 2022 Mar 11, 2022

Copy link to clipboard

Copied

You're missing a period between selection[0] and appliedObjectStyle. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

In addition to what @brianp311 metioned  I also notice that the name of the method is wrong on that line, it should be applyObjectStyle

See the documentation

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208274__d1e209925

So the line should be

app.selection[0].applyObjectStyle(app.activeDocument.objectStyles("FR Top Ad"),true);

-Manan 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

Thanks, Manan and brianp311.

I changed the line, but I'm still getting an error message (screen shot below).

I've tried moving the line around, thinking perhaps I have it out of order. But that doesn't work either.

I think I'm missing something else, but I can't figure it out.
I appreciate you taking the time to help me out.
Larry

larryp22136904_0-1647124380169.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

Maybe try ...object styles.itemByName("FR Top Ad",true);

 

Weird one. No weird line break before the function call. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

Hi Larry,

instead of objectStyles("name") do objectStyles.itemByName("name").

Sample code:

app.selection[0].applyObjectStyle( app.activeDocument.objectStyles.itemByName("FR Top Ad") );

 

FWIW: I see the same error "Object is not a function" if I do:

app.selection[0].applyObjectStyle( app.activeDocument.objectStyles("FR Top Ad") );

 

The second argument is optional. Its default value is true. So you can drop it.

 

Thanks,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

Thanks, Uwe:

That worked. Fantastic.
I couldn't figure out what I had wrong in the text.
one other question.
This object style is in a folder inside the Object Style folder.
Is there a way to make the script "look" inside another folder. It's called Advertising, if that helps any.
Thanks again for your help.
Larry

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

app.selection[0].applyObjectStyle( app.activeDocument.objectStyleGroups.itemByName("Advertising").objectStyles.itemByName("FR Top Ad") );

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2022 Mar 14, 2022

Copy link to clipboard

Copied

LATEST

Thanks Brian:
That worked great.....
Fabulous.....I appreicate everyone's help on this. 
I was trying different configuations and getting nowhere.
I appricate everyone taking the time to help me out.
Many thanks.

Larry

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines