Copy link to clipboard
Copied
Hi @Rbin, 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
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 = ["
...
Copy link to clipboard
Copied
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 😄
Copy link to clipboard
Copied
Hello @jazz-y man you are a genius! I confess I didn't expect the solution so quickly. Thanks.
Copy link to clipboard
Copied
It looks like correct version of first part: Display proportional value in the text box
Copy link to clipboard
Copied
It looks like correct version of first part: Display proportional value in the text box
By @Kukurykus
That's right!