Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Help with script to apply object style

Participant ,
Mar 11, 2022 Mar 11, 2022

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
1.0K
Translate
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

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

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

Translate
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
Community Expert ,
Mar 12, 2022 Mar 12, 2022

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 

Translate
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
Participant ,
Mar 12, 2022 Mar 12, 2022

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.pngexpand image

 

Translate
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
Community Expert ,
Mar 12, 2022 Mar 12, 2022

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

 

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

Translate
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
Community Expert ,
Mar 12, 2022 Mar 12, 2022

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 )

Translate
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
Participant ,
Mar 14, 2022 Mar 14, 2022

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

Translate
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
Community Expert ,
Mar 14, 2022 Mar 14, 2022
app.selection[0].applyObjectStyle( app.activeDocument.objectStyleGroups.itemByName("Advertising").objectStyles.itemByName("FR Top Ad") );
Translate
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
Participant ,
Mar 14, 2022 Mar 14, 2022
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

Translate
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