MEL How-To #86

Back · Previous · Next Maya

How do I force a window to open to a specific size or location?

The ‘-width’, ‘-height’, ‘-topEdge’ and ‘-leftEdge’ parameters used with a "window" command are used only when the window is opened for the first time. After that Maya uses the last-used dimensions stored in your user preferences.

All is not lost, however. You can work around this in one of two ways:

  1. Disallow resizing of the window by using the "-sizeable false" flag. Of course, this affects only size (‘-width’ and ‘-height’ parameters), and not position.
    window -sizeable false -width 100 -height 100 myWindow;
    columnLayout;
    
      // Add controls here
    
      setParent ..;
    
    showWindow myWindow;
    
  2. Tweak the window back to its desired dimensions after it is created.
    window myWindow;
    columnLayout;
    
      // Add controls here
    
      setParent ..;
    
    // Enforce dimensions
    window -e -width 100 -height 100 myWindow;
    
    showWindow myWindow;
    

Disclaimer: You should only force these parameters when it is crucial to do so, or when it markedly improves workflow. Circumventing user preferences is prone to annoy the users of your tools.

11 May 2003