Some example code to quickly create a sample UI window in Maya.
Open your python editor and slap in the below code. Save the file to your Maya scripts directory (on a mac that’ll be in /User/Library/Preferences?Autodesk/maya/2018/scripts). For this example, lets save the file as ‘mayaWindow.py’
# Import the Maya commands library from maya import cmds # Create a window using the cmds.window command # give it a title, icon and dimensions window = cmds.window( title="Long Name", iconName='Short Name', widthHeight=(200, 55) ) # As we add contents to the window, align them vertically cmds.columnLayout( adjustableColumn=True ) # A button that does nothing cmds.button( label='Do Nothing' ) # Close button with a command to delete the UI cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') ) # Set its parent to the Maya window (denoted by '..') cmds.setParent( '..' ) # Show the window that we created (window) cmds.showWindow( window )
Open Maya and in the script editor type the following:
import mayaWindow as mw reload(mw)
Because we aren’t using any functions or classes the script will run and a totally useless window will appear, but is a great place the start.