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;
1 Correct answer
app.selection[0].applyObjectStyle( app.activeDocument.objectStyleGroups.itemByName("Advertising").objectStyles.itemByName("FR Top Ad") );
Copy link to clipboard
Copied
You're missing a period between selection[0] and appliedObjectStyle.
Copy link to clipboard
Copied
In addition to what @brian_p_dts 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
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
Copy link to clipboard
Copied
Maybe try ...object styles.itemByName("FR Top Ad",true);
Weird one. No weird line break before the function call.
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 )
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
Copy link to clipboard
Copied
app.selection[0].applyObjectStyle( app.activeDocument.objectStyleGroups.itemByName("Advertising").objectStyles.itemByName("FR Top Ad") );
Copy link to clipboard
Copied
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

