Copy link to clipboard
Copied
How to resize a layer proportionally based on the width size inserted in the text box? Thank you!
var dialog = new Window("dialog","Resize Layers");
dialog.preferredSize.width = 200;
dialog.preferredSize.height = 80;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
var group1 = dialog.add("group");
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var statictext1 = group1.add("statictext");
statictext1.text = "New width";
var edittext1 = group1.add("edittext");
edittext1.preferredSize.width = 40;
edittext1.preferredSize.height = 25;
var statictext2 = group1.add("statictext");
statictext2.text = "centimeters";
var button1 = group1.add("button");
button1.text = "OK";
button1.preferredSize.width = 80;
button1.preferredSize.height = 25;
button1.justify = "center";
dialog.show();
To resize a layer see this snippet (works without your dialog)
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var aDoc = activeDocument;
var bds = aDoc.activeLayer.bounds;
var w = bds[2].value - bds[0].value;
var edittext_width = 50*1;
var f = edittext_width*100/w;
aDoc.activeLayer.resize(f, f, AnchorPosition.MIDDLECENTER);
app.preferences.rulerUnits = startRulerUnits;
It does what it should.
Can you complete it yourself?
Have fun
![]()
Copy link to clipboard
Copied
To resize a layer see this snippet (works without your dialog)
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var aDoc = activeDocument;
var bds = aDoc.activeLayer.bounds;
var w = bds[2].value - bds[0].value;
var edittext_width = 50*1;
var f = edittext_width*100/w;
aDoc.activeLayer.resize(f, f, AnchorPosition.MIDDLECENTER);
app.preferences.rulerUnits = startRulerUnits;
It does what it should.
Can you complete it yourself?
Have fun
![]()
Copy link to clipboard
Copied
This is fantastic! The result is amazing.![]()
Great support pixxxel schubser, you're always saving me here and in the Illustrator community. Thank you.
Here is the result:![]()
var dialog = new Window("dialog","Resize Layers");
dialog.preferredSize.width = 200;
dialog.preferredSize.height = 80;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
var group1 = dialog.add("group");
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var statictext1 = group1.add("statictext");
statictext1.text = "New width";
var edittext1 = group1.add("edittext");
edittext1.preferredSize.width = 40;
edittext1.preferredSize.height = 25;
var statictext2 = group1.add("statictext");
statictext2.text = "centimeters";
var button1 = group1.add("button");
button1.text = "OK";
button1.preferredSize.width = 80;
button1.preferredSize.height = 25;
button1.justify = "center";
button1.onClick = function(){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.CM;
var aDoc = activeDocument;
var bds = aDoc.activeLayer.bounds;
var w = bds[2].value - bds[0].value;
var edittext_width = edittext1.text*1;
var f = edittext_width*100/w;
aDoc.activeLayer.resize(f, f, AnchorPosition.MIDDLECENTER);
app.preferences.rulerUnits = startRulerUnits;
app.refresh();
}
dialog.show();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now