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

Align two objects, obj 2 aligned to top and center obj 1

Contributor ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Hello friends, I have the following code:

var doc = app.activeDocument;
var objeto = doc.selection[0];
var posicion = objeto.position;
var WidthInicial = objeto.width;
var WidthFinal = WidthInicial-14.4;
var ScaleFactor = (WidthFinal / WidthInicial)*100;
objeto.width = WidthFinal;
objeto.resize(100,ScaleFactor, true, true, true, true, null, undefined);
var imgGroup = doc.groupItems.add();
//var rectRef = imgGroup.pathItems.rectangle(posicion[1],posicion[0],objeto.width, objeto.height);
var rectRef = imgGroup.pathItems.rectangle(posicion[1],posicion[0],75,75);
alert(objeto.width + " " + rectRef.width);
//objeto.remove();
//alert("objeto removido");

 

which gets the width of a selected object, reduces it by 0.2in (14.4px) and also reduces height proportionally, then since it did not scaled to the top center pisition I was trying to create a new square with the new measures, but I can't center the new object (obj 2) to the previous selected object (obj 1).

 

Can anyone help me please. To make it short I am trying to create a script to reduce a quare/object proportionally in steps of 0.2in and keep it centered in the top center point.

TOPICS
Scripting , Tools

Views

131

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 1 Correct answer

Community Expert , Sep 26, 2022 Sep 26, 2022

Hi @AntonioPacheco, if I understand you correctly, please try this version:

var doc = app.activeDocument;
var objeto = doc.selection[0];
var dup = objeto.duplicate();
var WidthInicial = objeto.width;
var WidthFinal = WidthInicial - 14.4;
var ScaleFactor = (WidthFinal / WidthInicial) * 100;
dup.resize(ScaleFactor, ScaleFactor, true, true, true, true, null, Transformation.TOP);
doc.selection = [];
dup.selected = true;

If you run the script multiple times, it will have the effect you describe. But

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Hi @AntonioPacheco, if I understand you correctly, please try this version:

var doc = app.activeDocument;
var objeto = doc.selection[0];
var dup = objeto.duplicate();
var WidthInicial = objeto.width;
var WidthFinal = WidthInicial - 14.4;
var ScaleFactor = (WidthFinal / WidthInicial) * 100;
dup.resize(ScaleFactor, ScaleFactor, true, true, true, true, null, Transformation.TOP);
doc.selection = [];
dup.selected = true;

If you run the script multiple times, it will have the effect you describe. But I wasn't sure what the rectangle was for.

- Mark

Screen Shot 2022-09-27 at 08.31.45.png

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
Contributor ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

LATEST

let me try it, thanks @m1b 

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