5 Replies Latest reply on Sep 14, 2016 12:15 PM by pixxxel schubser

    View document dimensions

    Level 1

      I would like to view the document size in use

      I assembled a small script to do this but I can not understand what is wrong.

      where is the error?

       

      This script

       

              var dlg = new Window('dialog','document size');

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

                  dlg.gp1.orientation = 'row'

                  dlg.gp1.sTxt = dlg.gp1.add('statictext', undefined, 'original image size: ' + widthDoc + ' pixels x ' + heightDoc + ' pixels')

                 

      var AD = app.activeDocument

      var widthDoc = AD.width.value

      var heightDoc = AD.height.value

      var portrait = (widthDoc <= heightDoc);

       

       

       

       

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

                  dlg.btnGp.ok = dlg.btnGp.add('button',undefined,'ok');

                  dlg.btnGp.cancel = dlg.btnGp.add('button',undefined,'cancel');

                  dlg.btnGp.ok.onClick = function(){

                          dlg.close()

                          }

                  dlg.btnGp.cancel.onClick = function(){      

                      dlg.close()

                      }

       

       

              dlg.show()

        • 1. Re: View document dimensions
          Pedro Cortez Marques Level 3

          Hi

           

          The code is correct, but the variables must preceed it.

           

          Just put this on the beggining:

           

          var AD = app.activeDocument
          var widthDoc = AD.width.value
          var heightDoc = AD.height.value
          var portrait = (widthDoc <= heightDoc);
          
          1 person found this helpful
          • 2. Re: View document dimensions
            Chuck Uebele Adobe Community Professional & MVP

            Do you need the value after the width & height? That's just for pulling the values from a UI. The OP need to get those values from the document.

             

            Edit: I just tried it with "value." It works but is unnecessary.

            • 3. Re: View document dimensions
              pixxxel schubser MVP & Adobe Community Professional

              Pedro Cortez Marques schrieb:

               

              Hi

              The code is correct …

               

               

              … but only if the ruler units are in 'pixels'.

              Otherwise better use something like this:

              var AD = activeDocument;
              //var widthDoc = AD.width.value;
              //var heightDoc = AD.height.value;
              //var portrait = (widthDoc <= heightDoc);
              
              var dlg = new Window('dialog','document size');
              dlg.gp1 = dlg.add('group');
              dlg.gp1.orientation = 'row';
              //dlg.gp1.sTxt = dlg.gp1.add('statictext', undefined, 'original image size: ' + widthDoc + ' pixels x ' + heightDoc + ' pixels');
              dlg.gp1.sTxt = dlg.gp1.add('statictext', undefined, 'original image size: ' + new UnitValue(AD.width.as('px'),'px') + " x "+ new UnitValue(AD.width.as('px'),'px') + " y");
              
              dlg.btnGp = dlg.add('group');
              dlg.btnGp.ok = dlg.btnGp.add('button',undefined,'ok');
              dlg.btnGp.cancel = dlg.btnGp.add('button',undefined,'cancel');
              
              dlg.btnGp.ok.onClick = function() {
              dlg.close();
              }
              
              dlg.btnGp.cancel.onClick = function() {
              dlg.close();
              }
              
              dlg.show();
              

               

              Have fun

               

              1 person found this helpful
              • 4. Re: View document dimensions
                Level 1

                Thanks for your help

                It works great.

                 

                • 5. Re: View document dimensions
                  pixxxel schubser MVP & Adobe Community Professional

                  Glad I could help.

                   

                  One note: there is a little „copy&paste-mistake“ in my line #10, should be

                  dlg.gp1.sTxt = dlg.gp1.add('statictext', undefined, 'original image size: ' + new UnitValue(AD.width.as('px'),'px') + " x "+ new UnitValue(AD.height.as('px'),'px') + " y");
                  

                   

                  for the correct height.