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

Resize a layer

Engaged ,
May 31, 2019 May 31, 2019

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();

TOPICS
Actions and scripting

Views

475

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 , May 31, 2019 May 31, 2019

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

Votes

Translate

Translate
Adobe
Community Expert ,
May 31, 2019 May 31, 2019

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

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
Engaged ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

LATEST

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();

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