Copy link to clipboard
Copied
Hello – I'm trying to wrtite a script to adjust the vertical position of objects by a fixed proportion of their existing position. Here's what I have:
var docRef= activeDocument;
var selObjs = docRef.selection;
var objects = selObjs.length;
var adjustment = prompt("Adjustment factor?",0.95);
var i=0;
var currObj,currObjHeight;
// loop through all objects and adjust vert. position
for(var i=0;i<objects;i++){
currObj = selObjs[i];
currObjHeight = currObj.position[1];
currObj.position[1] = currObjHeight * adjustment;
}
...but sadly nothing happens (not even an error message). Could someone take a moment to explain where I'm going wrong? Many thanks for your help.
"position" should be assigned an array, rather than the elements assigned individually. So change your last line to
currObj.position = [currObj.position[0], currObjHeight * adjustment];
you can't assign position[1] or position[0] individually, you have to assign both x an y to position property
//currObj.position[1] = currObjHeight * adjustment;
currObj.position = [ currObj.position[0], currObjHeight * adjustment];
Copy link to clipboard
Copied
"position" should be assigned an array, rather than the elements assigned individually. So change your last line to
currObj.position = [currObj.position[0], currObjHeight * adjustment];
Copy link to clipboard
Copied
you can't assign position[1] or position[0] individually, you have to assign both x an y to position property
//currObj.position[1] = currObjHeight * adjustment;
currObj.position = [ currObj.position[0], currObjHeight * adjustment];
Copy link to clipboard
Copied
Many thanks to both femkeblanco and CarlosCanto for their correction to my feeble attempt at javascript – very grateful for your generous help. (I haven't been involved with scripting for 5 years, and to have been provided with two correct replies in the space of an hour shows what a remarkable resource this is.)