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

Display the width of the current document

Contributor ,
Sep 19, 2017 Sep 19, 2017

Hello guys! How do I display the width size of the current document inside a text box in a dialog box? The unit of measurement will be in centimeters. (cm)

TOPICS
Actions and scripting
1.4K
Translate
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 , Sep 19, 2017 Sep 19, 2017

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

dlg = new Window('dialog','Final Width Size');

dlg.gp = dlg.add('group');

dlg.gp.stxt = dlg.gp.add('statictext',undefined,'Width Size');

dlg.gp.etxt = dlg.gp.add('edittext',undefined,parseFloat (doc.width));

dlg.gp.meas = dlg.gp.add('statictext',undefined,'cm');

dlg.btn = dlg.add('button',undefined,'Close');

dlg.btn.onClick = function (){

    dlg.close();

    }

dlg.show();

Translate
Adobe
Community Expert ,
Sep 19, 2017 Sep 19, 2017

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

alert(doc.width)

Translate
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
Contributor ,
Sep 19, 2017 Sep 19, 2017

Hi Chuck Uebele Great job, 50% positive .... 100% will be if this value is displayed in a text box equal to the picture illustration below. It would be possible? Thank you for your help.

Screenshot_1.jpg

Translate
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
Community Expert ,
Sep 19, 2017 Sep 19, 2017

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

dlg = new Window('dialog','Final Width Size');

dlg.gp = dlg.add('group');

dlg.gp.stxt = dlg.gp.add('statictext',undefined,'Width Size');

dlg.gp.etxt = dlg.gp.add('edittext',undefined,parseFloat (doc.width));

dlg.gp.meas = dlg.gp.add('statictext',undefined,'cm');

dlg.btn = dlg.add('button',undefined,'Close');

dlg.btn.onClick = function (){

    dlg.close();

    }

dlg.show();

Translate
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
Contributor ,
Sep 19, 2017 Sep 19, 2017

Very good! Beautiful work. Thank you very much Chuck Uebele

Translate
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
Contributor ,
Sep 20, 2017 Sep 20, 2017

Chuck Uebele, just curious and for the sake of studying and learning, how do I execute this function through a button eg "doc width"? Thanks again

Translate
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
Community Expert ,
Sep 20, 2017 Sep 20, 2017

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

dlg = new Window('dialog','Final Width Size');

dlg.gp = dlg.add('group');

dlg.gp.stxt = dlg.gp.add('statictext',undefined,'Width Size');

dlg.gp.etxt = dlg.gp.add('edittext',undefined,'');

dlg.gp.etxt.size = [90,12]

dlg.gp.meas = dlg.gp.add('statictext',undefined,'cm');

dlg.getSize = dlg.add('button',undefined,'Get Doc Width');

dlg.btn = dlg.add('button',undefined,'Close');

dlg.getSize.onClick = function(){

    dlg.gp.etxt.text =parseFloat(doc.width);

    }

dlg.btn.onClick = function (){

    dlg.close();

    }

dlg.show();

Translate
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
Contributor ,
Sep 20, 2017 Sep 20, 2017

Hi Chuck Uebele thanks for the quick support! There is an error pointing to line 16, with you worked out?Screenshot_1.jpg

Translate
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
Community Expert ,
Sep 20, 2017 Sep 20, 2017

Do you have a file open?

Translate
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
Community Expert ,
Sep 20, 2017 Sep 20, 2017

Fixed it. Forgot to capitalize the "F" in parseFloat.

Translate
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
Contributor ,
Sep 20, 2017 Sep 20, 2017
LATEST

Now it worked perfect! thank you very much for sharing your knowledge friend Chuck Uebele A big hug for you

Translate
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