Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Script to adjust vertical position of objects

Explorer ,
Jun 10, 2021 Jun 10, 2021

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.

TOPICS
Scripting

Views

205

Likes

Translate

Translate

Report

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

Advocate , Jun 10, 2021 Jun 10, 2021
"position" should be assigned an array, rather than the elements assigned individually.  So change your last line tocurrObj.position = [currObj.position[0], currObjHeight * adjustment];

Likes

Translate

Translate
Adobe Community Professional , Jun 10, 2021 Jun 10, 2021
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];   

Likes

Translate

Translate
Advocate ,
Jun 10, 2021 Jun 10, 2021

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];

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

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];

  

Likes

Translate

Translate

Report

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 ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

LATEST

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.)

Likes

Translate

Translate

Report

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