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.
1 Correct answer
See below.
app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;
Copy link to clipboard
Copied
See below.
app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;
Copy link to clipboard
Copied
Thank you a ton!!
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
Mohammad Hasanin
Copy link to clipboard
Copied
Try the following
app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle
-Manan
Copy link to clipboard
Copied
Thanks a lot @Manan Joshi , that was pretty easy!, javascript some times is so strange!
Mohammad Hasanin
Copy link to clipboard
Copied
Hi @M.Hasanin,
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
Copy link to clipboard
Copied
Thanks @Manan Joshi for the clarifications, I learned new skills today
Mohammad Hasanin

