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

Object style script

Explorer ,
Apr 18, 2021 Apr 18, 2021

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

See below. 

app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;
Translate
Community Expert ,
Apr 18, 2021 Apr 18, 2021

See below. 

app.findObjectPreferences.appliedObjectStyles = app.selection[0].appliedObjectStyle.name;
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
Explorer ,
Apr 19, 2021 Apr 19, 2021

Thank you a ton!!

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

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

Try the following

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

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

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

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

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

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

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

Best
Mohammad Hasanin
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