Object style script

Explorer ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

Hello! Does anyone know how to change the code below from "Object Style 1" to the currently selected object style that's selected? So that I don't need to input the style name, but click on the object and it'll find the other objects that have the same object style applied.

 

var combineMe = new Array;
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = "Object Style 1"
found_list = app.activeDocument.findObject();
for (a=0; a<found_list.length; a++) {
if (found_list[a] instanceof TextFrame) {
combineMe.push(found_list[a]);
}
}
 
Any help would be appreciated. Thank you!
TOPICS
How to , Scripting

Views

255

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 , Apr 18, 2021 Apr 18, 2021

See below. 

app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;

Likes

Translate

Translate
Adobe Community Professional ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

See below. 

app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;

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 ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Thank you a ton!!

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
Enthusiast ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Hi,

this trick not work for Object Style inside Group? I tried to modfiy it and make some reseach but no success, something like that came to my imagination (not work) :

var myOSGStyle = app.selection[0].parent.constructor.name == "ObjectStyleGroup"
app.findObjectPreferences.appliedObjectStyles = myOSGStyle.appliedObjectStyle.name;

 So this is not work, but maybe you have another experince with this problem, and thanks in advance

Best
M.Hasanain

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 ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Try the following

app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle

-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
Enthusiast ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Thanks a lot @Manan Joshi , that was pretty easy!, javascript some times is so strange!

Best
M.Hasanain

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 ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

Hi @M.Hasanain,

It's not strange, you need to be a bit more thoughtful while reading the API definition. appliedObjecStyle can take argument in the form of a string or object I suppose. So if the name is giving you pains which makes sense due to it being inside a group then you can use the style object and that should work, if you have a valid object it does not matter where it resides in the panel. Just a bit of informed guess I would say.

-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
Enthusiast ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

LATEST

Thanks @Manan Joshi  for the clarifications, I learned new skills today

Best
M.Hasanain

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