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

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

401

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

Guide , Jun 10, 2021 Jun 10, 2021

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

Votes

Translate

Translate
Community Expert , 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];

  

Votes

Translate

Translate
Adobe
Guide ,
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];

Votes

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
Community Expert ,
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];

  

Votes

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

Votes

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