20 Replies Latest reply on Oct 30, 2017 8:21 PM by JJMack

    Positioning panel

    Level 1

      Good morning

      I would like to place this on the top right panel

      but the panel is always at the center

      how can I do to fix this?

       

      var win = new Window("palette", "PANEL");

      win.cancel2Ok = win.add('panel', [10,495,300,540], "");

      win.closeButton = win.cancel2Ok.add("button",  [10,10,280,35], "CLOSE");

      win.onDeactivate = function(){

         win.update();

         };

       

      var closeWin = false;

       

      win.closeButton.onClick = function(){

         closeWin = true;

         win.close();

          };

       

      win.onClose = function(){

         closeWin = true;

          };

       

       

      win.show();

       

      while(closeWin == false){

         app.refresh();

          };

        • 1. Re: Positioning panel
          fotoscan Level 1

          var win = new Window("palette", "PANEL");

           

          this must be:

           

          var win = new Window("palette", "PANEL", [ x, y, wd, ht ] );

          where x, y, wd, and ht is the position of the new created window.

           

          Hope this helps.

          • 2. Re: Positioning panel
            JJMack Most Valuable Participant

            Adobe broke that feature in its rewrite of ScriptUI. All windows are centered. Problem was reported. One reported palette windows location worked I do not find that to be right. win.frameloaction does not work for me. nor does .framebounds

             

            frameLocation Point A Point object for the location of the top left corner of the Window’s frame. The same as [frameBounds.x, frameBounds.y]. Set this value to move the window frame to the specified location on the screen. The frameBounds value changes accordingly.

            • 3. Re: Positioning panel
              cbuliarca Level 3

              You could reposition the window in the .onShow event:

               

              var win = new Window("palette", "PANEL");
              win.cancel2Ok = win.add('panel', [10,495,300,540], "");
              win.closeButton = win.cancel2Ok.add("button",  [10,10,280,35], "CLOSE");
              win.onDeactivate = function(){
                 win.update();
                 };
              
              var closeWin = false;
              
              win.closeButton.onClick = function(){
                 closeWin = true;
                 win.close();
                  };
              
              win.onClose = function(){
                 closeWin = true;
                  };
              
              
              win.onShow = function(){
                var ww = win.bounds.width;
                var hh = win.bounds.height;
                win.bounds.x  = 10;
                win.bounds.y  = 495;
                win.bounds.width  = ww;
                win.bounds.height  = hh;
              } 
              
              win.show();
              
              while(closeWin == false){
                 app.refresh();
                  };
              
              1 person found this helpful
              • 4. Re: Positioning panel
                JJMack Most Valuable Participant

                Thank you Your window.onshow function seems to work.

                • 5. Re: Positioning panel
                  Level 1

                  Thank you

                  Just what I wanted.

                  • 6. Re: Positioning panel
                    Level 1

                    C.Buliarca

                    I would like to ask a stupid question

                    I use three monitors, one 27, one 21, one 17-inch

                    how can you go to have the panel always in the same place?

                     

                     

                    I would like the panel is positioned according to the screen resolution

                    you think that you can 'do?

                    • 7. Re: Positioning panel
                      JJMack Most Valuable Participant

                      To me on my Windows 10 system the X and y positions seem to be relative to the top left corner of Windows main display. X to the right and y down.  You may be able to address your other windows displays relative to that. I have never tried.

                       

                      How Windows handles displays seem different between windows 7 and windows 10.

                       

                      I just tried  making x -300 I was able to have the dialog open on my left display and making x 2000 I was able to have the dialog open on my Right display.  My main Windows  display is the in the middle of my three displays..

                       

                      Capture.jpg

                      • 8. Re: Positioning panel
                        cbuliarca Level 3

                        I suppose you want to have the dialog placed on the same monitor with your Photoshop window.  There is a problem with that in Photoshop CC because the dialog by default center's only on the primary monitor. In Photoshop Cs6 the dialog follows Photoshop, but not in CC. If this behavior will be corrected by Adobe.. then yes you could just get the monitor's resolution  with this command $.screens, and then offset your dialog by some percents to always place it in the same place, but for now in CC you can't do that.

                        • 9. Re: Positioning panel
                          JJMack Most Valuable Participant

                          cbuliarca wrote:

                           

                          I suppose you want to have the dialog placed on the same monitor with your Photoshop window. There is a problem with that in Photoshop CC because the dialog by default center's only on the primary monitor. In Photoshop Cs6 the dialog follows Photoshop, but not in CC. If this behavior will be corrected by Adobe.. then yes you could just get the monitor's resolution with this command $.screens, and then offset your dialog by some percents to always place it in the same place, but for now in CC you can't do that.

                          You did not read this thread the problem was solved with the .onshow event as soon as one uses  .show the window is positioned by the .onshow event.  so the window can be position on any display. At least on a my windows machine.  Photoshop knows all the display one is using it shows that information in Photoshop system info.  I do not know though if a Photoshop script can get the info easily. alert(app.systemInformation); shows  can but parsing it will take a routine..

                          • 10. Re: Positioning panel
                            Level 1

                            I use the machine mac mountain lion photoshop cc 2014.

                            • 11. Re: Positioning panel
                              JJMack Most Valuable Participant

                              I do not think it matters which Photoshop CC version or OS version your using Windows or Mac. Try this Photoshop JavaScript TestDialog script. Will not work with Photoshop versions prior to CC. What surprised me was how dynamic it can be.   At times I will attach my Windows Surface Pro 3 high-resolution  display or my Android Samsung Galaxy Tab s 8.4 high-resolution display to my Windows Workstation via a wireless network connection as a third Windows Display.   While Photoshop is up and running.  Photoshop sees the attaching and detaching of the display and changes its System Info accordingly. If I attach it and run the test dialog the dialog will be on my right display when I close the dialog. If I detach the display and run the  test dialog it will be on my left display. If I run the test dialog in Photoshop on my surface pro 3 the dialog will be on the only display the surface pro 3 display.  Note: My left display's left offset is negative. All my displays display a different number of pixels.

                               

                              Adobe Photoshop Version: 2015.1.2 20160113.r.355 2016/01/13:23:59:59 CL 1059143  x64

                              Operating System: Windows 10 64-bit

                              Version: 10 or greater

                              System architecture: Intel CPU Family:6, Model:13, Stepping:7 with MMX, SSE Integer, SSE FP, SSE2, SSE3, SSE4.1, SSE4.2, AVX, HyperThreading

                              Physical processor count: 12

                              Logical processor count: 24

                              Processor speed: 1995 MHz

                              Built-in memory: 40886 MB

                              Free memory: 34549 MB

                              Memory available to Photoshop: 37033 MB

                              Memory used by Photoshop: 85 %

                              Modifier Palette: Enabled.

                              Design Space: Disabled.

                              Artboards: Enabled.

                              3D Multitone Printing: Disabled.

                              Highbeam: Enabled.

                              Image tile size: 1028K

                              Image cache levels: 6

                              Font Preview: Medium

                              TextComposer: Latin

                              Display: 1

                              Display Bounds: top=0, left=0, bottom=1080, right=1920

                              Display: 2

                              Display Bounds: top=0, left=-1360, bottom=768, right=0

                              Display: 3

                              Display Bounds: top=0, left=1920, bottom=1550, right=4480

                              OpenGL Drawing: Enabled.

                               

                              // Get Photoshop's Displays List
                              PSdisplaysOffset = app.systemInformation.indexOf("Display:") + "Display: 1 ".length ; // strip number and new line
                              PSdisplaysLength = app.systemInformation.indexOf("OpenGL") -PSdisplaysOffset;
                              PSdisplaysInfo =  app.systemInformation.substr(PSdisplaysOffset, PSdisplaysLength);
                              
                              var PSdisplay = [];        // Photoshop Displays Bounds Strings
                              var PSdisplayTop = [];     // Displays Top Numeric Bounds 
                              var PSdisplayLeft = [];    // Displays Left Numeric Bounds 
                              var PSdisplayBottom = [];  // Displays Bottom Numeric Bounds
                              var PSdisplayRight = [];   // Displays Right Numeric Bounds
                              
                              // Gets Photoshop's Displays bound string this will only support less than 10 Displays
                              for(var i = 0; PSdisplaysInfo.indexOf("Display:") != -1; i++) {
                                PSdisplay[i] = PSdisplaysInfo.substr(0, PSdisplaysInfo.indexOf("Display:") );
                                restLength = PSdisplaysInfo.length - ( PSdisplaysInfo.indexOf("Display:") + "Display: 1 ".length);
                                PSdisplaysInfo = PSdisplaysInfo.substr( PSdisplaysInfo.indexOf("Display:") + "Display: 1 ".length, restLength );
                                }
                              PSdisplay[i] = PSdisplaysInfo; 
                              
                              // Parse Strings to intergers
                              for (var i = 0; i < PSdisplay.length; i++) {
                                topOffset    = PSdisplay[i].indexOf("top=") + "top=".length;
                                leftOffset   = PSdisplay[i].indexOf(", left=") + ", left=".length;
                                bottomOffset = PSdisplay[i].indexOf(", bottom=") + ", bottom=".length;
                                rightOffset  = PSdisplay[i].indexOf(", right=") + ", right=".length;
                              
                                PSdisplayTop[i] = parseInt(PSdisplay[i].substr( topOffset, leftOffset -", left=".length - topOffset));
                                PSdisplayLeft[i] = parseInt(PSdisplay[i].substr( leftOffset, bottomOffset - ", bottom=".length - leftOffset));
                                PSdisplayBottom[i] = parseInt(PSdisplay[i].substr( bottomOffset, rightOffset - ", right=".length - bottomOffset));
                                PSdisplayRight[i] = parseInt(PSdisplay[i].substr( rightOffset, PSdisplay[i].length - rightOffset));
                              }
                              
                              var dlg = new Window ( "dialog", "Test Dialog" ),
                                  bOK = dlg.add ( "button", undefined, "OK" );
                              
                              bOK.onClick = function () {
                                  dlg.close ();
                                  
                                  // DELETE WINDOW
                                  dlg = null;
                                  delete dlg;
                                  
                                  // FORCE GARBAGE COLLECTION
                                  $.gc ();
                              };
                              
                              dlg.onShow = function(){  
                                var ww = dlg.bounds.width;  
                                var hh = dlg.bounds.height;  
                                dlgDisplay = PSdisplay.length-1;           // Photoshop Last Display 
                                dlgTop = PSdisplayTop[dlgDisplay] + 100 ;  // Relative to Top of display
                                dlgLeft =  PSdisplayLeft[dlgDisplay] +78 ; // Relative to Left side of display
                                dlg.bounds.x  = dlgLeft;  
                                dlg.bounds.y  = dlgTop;  
                                dlg.bounds.width  = ww;  
                                dlg.bounds.height  = hh;  
                              }   
                              dlg.show ();
                              
                              1 person found this helpful
                              • 12. Re: Positioning panel
                                JJMack Most Valuable Participant

                                By the way I do not know JavaScript I only hack at it.  I did not know about $.screens.   Using $.screens the script positioning the script dialog using the window .onshow event  works in Photoshop CC and prior versions of Photoshop and is much simpler.  Thank You for opening my eyes to $.screens.

                                 

                                var dlg = new Window ( "dialog", "Test Dialog" ),
                                    bOK = dlg.add ( "button", undefined, "OK" );
                                
                                bOK.onClick = function () {
                                    dlg.close ();
                                    
                                    // DELETE WINDOW
                                    dlg = null;
                                    delete dlg;
                                    
                                    // FORCE GARBAGE COLLECTION
                                    $.gc ();
                                };
                                
                                dlg.onShow = function(){  
                                  var ww = dlg.bounds.width;  
                                  var hh = dlg.bounds.height;  
                                  dlgDisplay = $.screens.length-1;            // Photoshop Last Display 
                                  dlgTop = $.screens[dlgDisplay].top + 100 ;  // Relative to Top of display
                                  dlgLeft =  $.screens[dlgDisplay].left +78 ; // Relative Left side of display
                                  dlg.bounds.x  = dlgLeft;  
                                  dlg.bounds.y  = dlgTop;  
                                  dlg.bounds.width  = ww;  
                                  dlg.bounds.height  = hh;  
                                }   
                                dlg.show ();
                                
                                • 13. Re: Positioning panel
                                  cbuliarca Level 3

                                  Cool script JJMack, thank you for taking time to help us. What I thought tssee@imgof.com asked for was a dialog that will keep it's position in relation to Photoshop main window, for example if Photoshop where opened on the second monitor, the script would open the dialog on that monitor, and also with the offset calculated for that monitor's resolution. My ideea was to set the dialog in center first and then in the .onShow event, get the bounds of the dialog, anf find out on wich monitor it will open, then calculate the offset for that monitor based on it's resolution. But this aproach will work only in versions prior to PhotoshopCC, because in CC the window.center() function, will just put the dialog on the first monitor.

                                  1 person found this helpful
                                  • 14. Re: Positioning panel
                                    JJMack Most Valuable Participant

                                    When I read about Adobe's  $.screens the object has an indicator in the display objects that indicate which display is Photoshop's primary display. Of course you can drag and change that. 

                                    • 15. Re: Positioning panel
                                      Grimbaldus Level 1

                                      This doesn't appear to work for PS CC 2017 under Win10.  The dialog box appears in the same position on the same monitor whatever numbers are chosen for top/left positions and $.screen contents.

                                      • 16. Re: Positioning panel
                                        JJMack Most Valuable Participant

                                        I have not played with CC 2018 yet.  Adobe added a preference in it that may effect this area of scripting. I wrote MAY I do not know for sure.

                                        Capture.jpg

                                        • 17. Re: Positioning panel
                                          Grimbaldus Level 1

                                          I assume '2018' is a typo for 2017.  I wasn't aware of that Preference, thank you; I'll check it out and revert.

                                          • 18. Re: Positioning panel
                                            Grimbaldus Level 1

                                            No such preference shown in CC 2017 or 2018 just downloaded.

                                             

                                            Only available under Win 10 and on devices paired with a stylus (screenshot is from my MBP).

                                             

                                            Screen Shot 2017-10-30 at 16.52.03 copy.jpg

                                            • 19. Re: Positioning panel
                                              Grimbaldus Level 1

                                              Option only available under Win 10 and on devices paired with a stylus.

                                              • 20. Re: Positioning panel
                                                JJMack Most Valuable Participant

                                                CC 2018 was no typo it is the latest version of Photoshop.  I have not player with it yet.  I use CC 2014.  I have CS6, CC 2014 and CC 2018 installed.  I found CC 2015, CC 2015.5 and CC 2017 unacceptable.  I had to reinstall windows so I did not re-install CS2, CS3, CC, CC 2015, CC 2015.5 and CC 2017.  I find the CC 2018 still has problems I do not want.  So I use CC 2014....

                                                 

                                                CC 2018 is version 19 of Photoshop

                                                Capture.jpg

                                                I just tested the script I posted in this thread on  CC 2018 the Dialog was position on my second displays on windows 10.  The screen is left of my main display display 1 which has the Windows 10 task bar. I do not display Windows task bar on all displays.  You can see the Dialog outline in RED near the top left it the display.

                                                Capture.jpg