Skip to main content
Participant
January 7, 2024
Answered

Script to Find object style and apply percentage to image

  • January 7, 2024
  • 2 replies
  • 789 views

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 !

This topic has been closed for replies.
Correct answer Anantha Prabu G
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")

2 replies

Anantha Prabu G
Legend
January 8, 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,PrabuDesign smarter, faster, and bolder with InDesign scripting.
PéoAuthor
Participant
January 9, 2024

Yes it worked !

Thank you very much for your time.

Community Expert
January 7, 2024