Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2015 11:46
Show Gist options
  • Save thomashope/df37c60a7ead9fde8955 to your computer and use it in GitHub Desktop.
Save thomashope/df37c60a7ead9fde8955 to your computer and use it in GitHub Desktop.
import maya.cmds as cmds
# define the functions before passing them as function objects to the buttons
# functions should take *args because UI elements pass some number of arguments depending on
# what type of element they are and their current state, or something like that...
# see ->
def say_hello(*args):
number = 123
# numbers have to be converted to strings explicitly with the str() function
print("Testing testing, "+str(number)+"..."+"\nHello!")
def count_joints(*args):
# the ls command return a list of all objects in the scene
# filtered by the passed parameters
joints ="joint")
# len gets the length of the list
joint_count = str(len(joints))
print(joint_count + " joints found")
def reset_joints(*args):
print("TODO: zero out the transform on all the joints")
# width and height of the window
def WIDTH():
return 200
def HEIGHT():
return 500
# create the window, specify the width and height in pixels
cmds.window(widthHeight=(WIDTH(), HEIGHT()),
title="it's a window",
# set the layout of the window that was just created
clayout = cmds.columnLayout(adjustableColumn=True, rowSpacing=8)
# a simple text label
cmds.text(label="These may not work", align="center")
# add some UI elements to the window
cmds.button(label="hello button", command=say_hello)
cmds.button(label="count the joints", command=count_joints)
cmds.button(label="reset the joints", command=reset_joints)
cmds.checkBox(label="save the world")
# make a new layout which is a child of the previous layout
columnWidth2=(WIDTH()/2, WIDTH()/2),
columnAttach=[(1, 'both', 0), (2, 'both', 0)])
cmds.button(label="buy bitcoin")
# revert back to the previously specified layout
columnWidth=(1, WIDTH()/2),
columnAttach=[(1, 'both', 0), (2, 'both', 0)])
cmds.button(label="sell bitcoin", enable=False)
# pass the layout back to cmds.columnLayout to change properties
cmds.columnLayout( clayout, adjustableColumn=True, rowSpacing=2)
cmds.text(label="left", align="left")
cmds.text(label="center", align="center")
cmds.text(label="right", align="right")
cmds.text(label="it's a slider")
# text can be linked
cmds.text(label="Made by Tom")
cmds.text(label="", hyperlink=True)
# you have to do this to see the window that was created
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment