Skip to content

Instantly share code, notes, and snippets.

@manhha00
Created November 27, 2017 02:47
Show Gist options
  • Save manhha00/79d6759c99fe66d5d63d2676da392e98 to your computer and use it in GitHub Desktop.
Save manhha00/79d6759c99fe66d5d63d2676da392e98 to your computer and use it in GitHub Desktop.
python - Running script from maya button
import maya.cmds as cmds
class UI(object):
def __init__(self):
if cmds.window('myWindow', exists=True):
cmds.deleteUI("myWindow")
window = cmds.window('myWindow', title='MyWindow')
cmds.columnLayout()
cmds.button(l='myButton', c=self.btnCmd)
cmds.showWindow(window)
def btnCmd(self, *args):
print 'mybutton press',
you would just import the script and execute UI()
if you need to provide args use a lambda
cmds.button(l='myBtn', c=lambda *args: self.btnCmd(arg1, arg2))
also UIs are a lot easier in pymel
import pymel.core as pm
class UI(object):
def __init__(self):
if pm.window('myWindow', exists=True):
pm.deleteUI('myWindow')
with pm.window('myWindow', title='myWindow') as window:
with pm.columnLayout():
pm.button(l='myButton', c=lambda *args: self.btnCmd('test1', 5))
window.show()
def btnCmd(self, arg1, arg2):
print arg1
print arg2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment