Исправленный рабочий код:
import maya.cmds as cmds
def UI():
# check to see if our window exists
if cmds.window("matchUI", exists = True):
cmds.deleteUI("matchUI")
# create our window
window = cmds.window("matchUI", title = "Space Match", w = 256, h = 300, mnb = False, mxb = False, sizeable = False)
# create a main layout
mainLayout = cmds.columnLayout(w = 256, h = 300)
# create the buttons
cmds.separator(h = 15)
cmds.button(label = "Get transforms", w = 256, h = 50, command = getTransforms)
cmds.button(label = "Match", w = 256, h = 50, command = printCommand)
# show window
cmds.showWindow(window)
def getTransforms(*args):
global bpiv_loc_rotations
global apiv_loc_rotations
global hpiv_loc_rotations
bpiv_loc_rotations = cmds.xform('balloonsPiv_loc', ws = True, q = True, ro = True)
apiv_loc_rotations = cmds.xform('anchorPiv_loc', ws = True, q = True, ro = True)
hpiv_loc_rotations = cmds.xform('hutPiv_loc', ws = True, q = True, ro = True)
def printCommand(*args):
print bpiv_loc_rotations
print apiv_loc_rotations
print hpiv_loc_rotations
С другой стороны, использование классов также полностью решает проблему,
даже размер кода почти не увеличился - всего на 3 строки длинее:
import maya.cmds as cmds
class TransformsData:
def __init__(self):
self.rotations = [None, None, None]
bpiv_loc = TransformsData()
apiv_loc = TransformsData()
hpiv_loc = TransformsData()
def UI():
# check to see if our window exists
if cmds.window("matchUI", exists = True):
cmds.deleteUI("matchUI")
# create our window
window = cmds.window("matchUI", title = "Space Match", w = 256, h = 300, mnb = False, mxb = False, sizeable = False)
# create a main layout
mainLayout = cmds.columnLayout(w = 256, h = 300)
# create the buttons
cmds.separator(h = 15)
cmds.button(label = "Get transforms", w = 256, h = 50, command = getTransforms)
cmds.button(label = "Match", w = 256, h = 50, command = printCommand)
# show window
cmds.showWindow(window)
def getTransforms(*args):
bpiv_loc.rotations = cmds.xform('balloonsPiv_loc', ws = True, q = True, ro = True)
apiv_loc.rotations = cmds.xform('anchorPiv_loc', ws = True, q = True, ro = True)
hpiv_loc.rotations = cmds.xform('hutPiv_loc', ws = True, q = True, ro = True)
def printCommand(*args):
print bpiv_loc.rotations
print apiv_loc.rotations
print hpiv_loc.rotations