Skip to main content
Shulipa Bernad
Inspiring
March 29, 2022
Answered

Display proportional value in the text box part II

  • March 29, 2022
  • 1 reply
  • 367 views

Hi @17307824, how are you? This time, how to get the correct proportional value of height or width  when modifying the values of the text box since the dialog box informs the initial values of width and height of the active layer, but layers with different sizes.

 

 

var tmp = preferences.rulerUnits; 
app.preferences.rulerUnits=Units.CM;
LB = activeDocument.activeLayer.bounds; 
L = (LB[2].value.toFixed(1))-(LB[0].value.toFixed(1)); 
A = (LB[3].value.toFixed(1))-(LB[1].value.toFixed(1));  

dlg = new Window("dialog"); dlg.text = "Dialog";
dlg.orientation = "row"; dlg.alignChildren = ["center","center"];
dlg.spacing = 10; dlg.margins = 16;

et1 = dlg.add('edittext {properties: {name: "et1"}}');
et1.text = L;

st1 = dlg.add("statictext", undefined, undefined, {name: "st1"});
st1.text = "x";

et2 = dlg.add('edittext {properties: {name: "et2"}}');
et2.text = A;

st2 = dlg.add("statictext", undefined, undefined, {name: "st2"});
st2.text = "cm ";

et1.onChanging = function(){ et2.text = Number(et1.text)*1.5};
et2.onChanging = function(){ et1.text = Number(et2.text)/1.5};

dlg.show();

preferences.rulerUnits= tmp 

 

This topic has been closed for replies.
Correct answer jazz-y

I don't know what the initial condition of the problem was (why @r-bin  used a fixed coefficient of 1.5), but if I understood correctly, then this code will work as you need:

 

var tmp = preferences.rulerUnits; 
app.preferences.rulerUnits=Units.CM;
LB = activeDocument.activeLayer.bounds; 
L = (LB[2].value.toFixed(1))-(LB[0].value.toFixed(1)); 
A = (LB[3].value.toFixed(1))-(LB[1].value.toFixed(1));  

dlg = new Window("dialog"); dlg.text = "Dialog";
dlg.orientation = "row"; dlg.alignChildren = ["center","center"];
dlg.spacing = 10; dlg.margins = 16;

et1 = dlg.add('edittext {properties: {name: "et1"}}');
et1.text = L;

st1 = dlg.add("statictext", undefined, undefined, {name: "st1"});
st1.text = "x";

et2 = dlg.add('edittext {properties: {name: "et2"}}');
et2.text = A;

st2 = dlg.add("statictext", undefined, undefined, {name: "st2"});
st2.text = "cm ";

et1.onChanging = function(){ et2.text = Number(et1.text)/L*A};
et2.onChanging = function(){ et1.text = Number(et2.text)/A*L};

dlg.show();

preferences.rulerUnits= tmp 

 

P.S. I hope if we mention @r-bin often enough, he will come 😄

1 reply

jazz-yCorrect answer
Legend
March 29, 2022

I don't know what the initial condition of the problem was (why @r-bin  used a fixed coefficient of 1.5), but if I understood correctly, then this code will work as you need:

 

var tmp = preferences.rulerUnits; 
app.preferences.rulerUnits=Units.CM;
LB = activeDocument.activeLayer.bounds; 
L = (LB[2].value.toFixed(1))-(LB[0].value.toFixed(1)); 
A = (LB[3].value.toFixed(1))-(LB[1].value.toFixed(1));  

dlg = new Window("dialog"); dlg.text = "Dialog";
dlg.orientation = "row"; dlg.alignChildren = ["center","center"];
dlg.spacing = 10; dlg.margins = 16;

et1 = dlg.add('edittext {properties: {name: "et1"}}');
et1.text = L;

st1 = dlg.add("statictext", undefined, undefined, {name: "st1"});
st1.text = "x";

et2 = dlg.add('edittext {properties: {name: "et2"}}');
et2.text = A;

st2 = dlg.add("statictext", undefined, undefined, {name: "st2"});
st2.text = "cm ";

et1.onChanging = function(){ et2.text = Number(et1.text)/L*A};
et2.onChanging = function(){ et1.text = Number(et2.text)/A*L};

dlg.show();

preferences.rulerUnits= tmp 

 

P.S. I hope if we mention @r-bin often enough, he will come 😄

Shulipa Bernad
Inspiring
March 29, 2022

Hello @jazz-y  man you are a genius! I confess I didn't expect the solution so quickly. Thanks.