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.
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
...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
Copy link to clipboard
Copied
let me try it, thanks @m1b