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

Script to Find object style and apply percentage to image

Community Beginner ,
Jan 06, 2024 Jan 06, 2024

I've tried to build a script that find all the items in a document with a specific object style and apply a percentage to their content (image).

 

But I've run into many problems… (i'm not a very good scripter, I've tried the help of ChatGPT and it's really not perfect(!!). It almost do what I want… but it's inelegant and doesn't really work.

 

The main problem seems to be creating a prompt at the beginning asking for :

1 - The percentage we want applied to images
2- The object style targeted (with a dropdown menu of the styles of the document)

3- The reference point by which the scale will be done (this could also be done using the current selected reference point in the control panel… but I dont find how)

 

I've join a document showing the intended result. The targeted images are in anchored groups and their frames has "Objects to scale" as object style. At the bottom of the page is the desired result, all the images are at the same percentage (10%) and transformed by the bottom center.

 

Anyone input on this would be greatly appreciated (and maybe a great tool for many others!) Thanks !

TOPICS
Scripting
620
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 2 Correct answers

Engaged , Jan 08, 2024 Jan 08, 2024
var myDoc = app.documents[0];

app.findObjectPreferences = app.changeObjectPreferences = null;

app.findObjectPreferences.appliedObjectStyles = "ABC";

var found = app.findObject();

for (var i = 0; i < found.length; i++)

{
   found[i].graphics[0].horizontalScale = 60;

   found[i].graphics[0].verticalScale = 60;

   found[i].fit(FitOptions.FRAME_TO_CONTENT);

}
Translate
Engaged , Jan 15, 2024 Jan 15, 2024
var flag=0;  

findmyobject();  

function findmyobject()  

{  

var w = new Window ("dialog", "Find Object Styles");  

w.p1= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     

w.p1.add('statictext',undefined,"Select the find Object Styles");
  
w.p1.g = w.p1.add('group');    

w.p1.g.orientation = 'column'  

w.p1.g.alignChildren = "center"; 

var Find_Ostyles=app.documents[0].objectStyles.everyItem().name; 

var preset_list = w.p1.g.add ("dropdownlist", undefined, Find_Ostyles
...
Translate
Community Expert ,
Jan 07, 2024 Jan 07, 2024
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
Engaged ,
Jan 08, 2024 Jan 08, 2024
var myDoc = app.documents[0];

app.findObjectPreferences = app.changeObjectPreferences = null;

app.findObjectPreferences.appliedObjectStyles = "ABC";

var found = app.findObject();

for (var i = 0; i < found.length; i++)

{
   found[i].graphics[0].horizontalScale = 60;

   found[i].graphics[0].verticalScale = 60;

   found[i].fit(FitOptions.FRAME_TO_CONTENT);

}
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 Beginner ,
Jan 08, 2024 Jan 08, 2024

Yes it worked !

Thank you very much for your time.

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
Engaged ,
Jan 09, 2024 Jan 09, 2024
var flag=0;  

findmyobject();  

function findmyobject()  

{  

var w = new Window ("dialog", "Find Object Styles");  

w.p1= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     

w.p1.add('statictext',undefined,"Select the find Object Styles");   

w.p1.g = w.p1.add('group');    

w.p1.g.orientation = 'column'  

w.p1.g.alignChildren = "center";  

var Find_Ostyles=app.documents[0].objectStyles.everyItem().name;  

var preset_list = w.p1.g.add ("dropdownlist", undefined, Find_Ostyles); 

w.orientation = "column";  

w.add ("button", undefined, "OK");  

w.add ("button", undefined, "Cancel");  

var myResult = w.show()   

if(myResult == 1)
{  

    if((preset_list.selection==null)){return;}    

        mychanges();  
 }  

   else if (myResult== 2){  

      exit(0);  

    } 

function mychanges(){  

var myFind_OStyle=preset_list.selection.text;

var myDoc = app.documents[0];

app.findObjectPreferences = app.changeObjectPreferences = null;

app.findObjectPreferences.appliedObjectStyles = myFind_OStyle;

var found = app.findObject();

for (var i = 0; i < found.length; i++)

{
   found[i].graphics[0].horizontalScale = 60;

   found[i].graphics[0].verticalScale = 60;

   found[i].fit(FitOptions.FRAME_TO_CONTENT);

 flag=1; 

}
}
}

alert("Process Completed")
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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
Engaged ,
Jan 15, 2024 Jan 15, 2024
var flag=0;  

findmyobject();  

function findmyobject()  

{  

var w = new Window ("dialog", "Find Object Styles");  

w.p1= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     

w.p1.add('statictext',undefined,"Select the find Object Styles");
  
w.p1.g = w.p1.add('group');    

w.p1.g.orientation = 'column'  

w.p1.g.alignChildren = "center"; 

var Find_Ostyles=app.documents[0].objectStyles.everyItem().name; 

var preset_list = w.p1.g.add ("dropdownlist", undefined, Find_Ostyles);

w.p1= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     

w.p1.add('statictext',undefined,"Select the Percentage");   

w.p1.g = w.p1.add('group');    

w.p1.g.orientation = 'column'  

w.p1.g.alignChildren = "center";  

var preset_percentage = w.p1.g.add ("dropdownlist", undefined, [10,20,30,40,50,60,70,80,90,100]);
 
w.orientation = "column";  

w.add ("button", undefined, "OK");  

w.add ("button", undefined, "Cancel");  

var myResult = w.show()   

if(myResult == 1)
{  

    if((preset_list.selection==null)){return;} 

	mychanges();

}
     
if(myResult == 2)

{
    
if((preset_percentage==null)){return;}    

        mychanges();  
 }  

   else if (myResult== 3){  

      exit(0);  

    } 

function mychanges(){  

var myFind_OStyle =preset_list.selection.text;

var mySelect_Percentage = Number(preset_percentage.selection.text);

var myDoc = app.documents[0];

app.findObjectPreferences = app.changeObjectPreferences = null;

app.findObjectPreferences.appliedObjectStyles = myFind_OStyle;

var found = app.findObject();

for (var i = 0; i < found.length; i++)

{
   found[i].graphics[0].horizontalScale = mySelect_Percentage;

   found[i].graphics[0].verticalScale = mySelect_Percentage;

   found[i].fit(FitOptions.FRAME_TO_CONTENT);

 flag=1; 

}
}
}

alert("Process Completed")
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 Beginner ,
Jan 15, 2024 Jan 15, 2024
LATEST

Thanks, it works and looks good !

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