Skip to content

Instantly share code, notes, and snippets.

@JFlynnXYZ
Last active February 5, 2022 10:12
Show Gist options
  • Save JFlynnXYZ/9913813 to your computer and use it in GitHub Desktop.
Save JFlynnXYZ/9913813 to your computer and use it in GitHub Desktop.
Maya GUI Gists
'''This piece of code creates three buttons along the bottom of a window
equally seperated and adjustable by the changing of the window size.
To change where they are positioned in the form layout, swap out the
values in the attachForm with the attachNone values. For example, if
I wanted to place the buttons along the top I would swap out the
attachForm values for each "bottom" value with the attachNone values
for "top".
'''
window = cmds.window()
form = cmds.formLayout(numberOfDivisions=100)
button1 = cmds.button(label='button1')
button2 = cmds.button(label='button2')
button3 = cmds.button(label='button3')
cmds.formLayout(form, edit=True,
attachForm=[(button1, "bottom", 5),
(button1, "left", 5),
(button2, "bottom", 5),
(button3, "bottom", 5),
(button3, "right", 5)],
attachControl=[(button2, 'left', 5, button1),
(button2, 'right', 5, button3)],
attachPosition=[(button1, "right", 5, 33),
(button3, "left", 5, 66)],
attachNone=[(button1, "top"),
(button2, "top"),
(button3, "top")])
cmds.showWindow()
import maya.cmds as cmds
# Note that for this example to work you must substitute
# "image" below with the full path name to a valid image.
#
window = cmds.window(widthHeight=(565,700))
mainForm = cmds.formLayout()
# Here I just set it to the height of the image and just added a background
# colour since the image I used was larger then the window and faded out to the
# right
pane=cmds.paneLayout(height=140, bgc=(0.247059, 0.278431, 0.305882))
imageLayout = cmds.formLayout()
banner = cmds.image(image='image')
cmds.formLayout(imageLayout, e=True,
attachForm=[(banner, 'left', 0),
(banner, 'right', 0),
(banner, 'top', 0),
(banner, 'bottom', 0)])
cmds.setParent(mainForm)
tabs = cmds.tabLayout(innerMarginWidth=5, innerMarginHeight=5, scr=True)
cmds.formLayout(mainForm, e=True,
attachForm=[(pane, 'left', 5),
(pane, 'top', 5),
(pane, 'right', 5),
(tabs, 'left', 5),
(tabs, 'right', 5),
(tabs, 'bottom', 5)],
attachControl=[(tabs, 'top', 0, pane)])
terrainTab = cmds.rowColumnLayout(numberOfColumns=2)
cmds.button()
cmds.button()
cmds.button()
cmds.setParent('..')
texturingTab = cmds.rowColumnLayout(numberOfColumns=2)
cmds.button()
cmds.button()
cmds.button()
cmds.setParent('..')
cmds.tabLayout(tabs, edit=True,
tabLabel=((terrainTab, 'Terrain'), (texturingTab, 'Texturing')),
scr=True, cr=True )
cmds.showWindow(window)
import maya.cmds as cmds
def reveal_more(state):
cmds.control(moreOptionsFrame, e=True, vis=state)
window = cmds.window(menuBar=True, title='dimWhen Example')
cmds.frameLayout(label='Example Frame', borderStyle='in', cll=True)
cmds.columnLayout(adj=True)
cmds.button(label='Button 1')
cmds.button(label='Button 2')
cmds.rowLayout(nc=2)
cmds.text(label='More Options')
cmds.checkBox(cc=reveal_more, label='')
cmds.setParent('..')
moreOptionsFrame = cmds.frameLayout(label='More Options', borderStyle='in', cll=True, vis=False)
cmds.columnLayout(adj=True)
cmds.button(label='Button 3')
cmds.button(label='Button 4')
cmds.showWindow( window )
Here is just a selection of GUI gists I've written which I have found useful when creating my own GUI's.
Hope you find them useful!
@eulersson
Copy link

Thanks a lot Jon!

@rigncode
Copy link

rigncode commented Jul 7, 2020

Thanks! There were helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment