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

Change and clear ObjectStyle

New Here ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

I have two questions:

1)

How can I assign a particular object format (for example, "Format1") to a selected object frame?

Reading is like this:

MyObject = app.activeDocument.selection[0].appliedObjectStyle.name;

But how do I now assign a different format?

2)

An object is assigned a specific object format (e.g., "Format1").

How can I "remove" the objectstyle from the object (ie set it back to [empty])?

TOPICS
Scripting

Views

385

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
LEGEND ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Hi,

1)

var myObjectStyle = app.activeDocument.objectStyles.item("Format1");

app.selection[0].applyObjectStyle(myObjectStyle); 

2/

var myObjectStyle = app.activeDocument.objectStyles.item(0);

app.selection[0].applyObjectStyle(myObjectStyle); 

or

var myObjectStyle = app.activeDocument.objectStyles.item("$ID/[None]");

app.selection[0].applyObjectStyle(myObjectStyle);

(^/)

Votes

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
New Here ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Works fine - thank you.

Now one problem left:

The object format that I want to address is sorted in the object format palette in a subfolder. How do I have to adjust the code to use such a format?

Votes

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
LEGEND ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

var myObjectGroup = app.activeDocument.objectStyleGroups.item("Group");

var myObjectStyle = myObjectGroup.objectStyles.item("Format1");

app.selection[0].applyObjectStyle(myObjectStyle);

or

app.selection[0].applyObjectStyle(app.activeDocument.objectStyleGroups.item("Group").objectStyles.item("Format1"));

(^/)

Votes

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
LEGEND ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

It's possible to count the object styles too! 

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[0]);

Capture d’écran 2017-02-22 à 15.05.44.png

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[1]);

Capture d’écran 2017-02-22 à 15.05.53.png

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[2]);

Capture d’écran 2017-02-22 à 15.06.03.png

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[4]);

Capture d’écran 2017-02-22 à 15.06.12.png

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[5]);

Capture d’écran 2017-02-22 à 15.06.23.png

app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[3]);

Capture d’écran 2017-02-22 à 15.22.07.png

[3] apparently catches an "ghost" object style called "[Standard Grid]"!

(^/)

Votes

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
New Here ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

LATEST

It works 🙂

Thanks for your help.

Votes

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
People's Champ ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

You would need to drill down through the object styles groups. Say the style "myStyle" is in a sub folder called "Group2" which is in a subfolder called "Group1", then you would do this:

myObjectStyle = app.activeDocument.objectStyleGroups.itemByName("Group1").objectStyleGroups.itemByName("Group2").objectStyles.itemByName("myStyle")

Ariel

(Obi-wan uses the Force, so he types faster than me...)

Votes

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
LEGEND ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Aha! Yeap! … Great The Force In My Family Is! 

Ariel, a comment: Does "itemByName" equal "item"?

(^/)

Votes

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
People's Champ ,
Feb 22, 2017 Feb 22, 2017

Copy link to clipboard

Copied

Good question. I can't remember. In some versions it was, in some it wasn't. To be on the safe side I always use itemByName...

Votes

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