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])?
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);
(^/)
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?
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"));
(^/)
Copy link to clipboard
Copied
It's possible to count the object styles too!
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[0]);
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[1]);
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[2]);
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[4]);
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[5]);
app.selection[0].applyObjectStyle(app.activeDocument.allObjectStyles[3]);
[3] apparently catches an "ghost" object style called "[Standard Grid]"!
(^/)
Copy link to clipboard
Copied
It works 🙂
Thanks for your help.
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...)
Copy link to clipboard
Copied
Aha! Yeap! … Great The Force In My Family Is!
Ariel, a comment: Does "itemByName" equal "item"?
(^/)
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...