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

Display proportional value in the text box part II

Engaged ,
Mar 29, 2022 Mar 29, 2022

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.

20220329_161514.gif

 

 

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 

 

TOPICS
Actions and scripting

Views

170

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

Guide , Mar 29, 2022 Mar 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 = ["
...

Votes

Translate

Translate
Adobe
Guide ,
Mar 29, 2022 Mar 29, 2022

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 😄

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 ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

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

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
LEGEND ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

It looks like correct version of first part: Display proportional value in the text box

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 ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

LATEST
quote

It looks like correct version of first part: Display proportional value in the text box


By @Kukurykus

That's right!

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