ange,它触发了onChangeSel,它获取新对象,然后执行updateTextField,该字段使用ui\u dic dictionnary更新每个textField。因此,不必为attr[0]编写其他Def。上面,python中列出了一个文本字符串
ange,它触发了onChangeSel,它获取新对象,然后执行updateTextField,该字段使用ui\u dic dictionnary更新每个textField。因此,不必为attr[0]编写其他Def。上面,python中列出了一个文本字符串,python,maya,Python,Maya,ange,它触发了onChangeSel,它获取新对象,然后执行updateTextField,该字段使用ui\u dic dictionnary更新每个textField。因此,不必为attr[0]编写其他Def。上面,python中列出了一个文本字符串。以及你为什么要分开translateX。因为您可以执行“for循环”来创建['translateX'、'translateY'、'translateZ'、'rotateX'] transX_value = cmds.textField( w=
ange,它触发了onChangeSel,它获取新对象,然后执行updateTextField,该字段使用ui\u dic dictionnary更新每个textField。因此,不必为attr[0]编写其他Def。上面,python中列出了一个文本字符串。以及你为什么要分开translateX。因为您可以执行“for循环”来创建['translateX'、'translateY'、'translateZ'、'rotateX']
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected[0]) )
def updateValues () :
for sel in selection :
sel_attr = cmds.getAttr("%s+.name" %selected[0])
cmds.setAttr( "%s+.name" , textField)
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected[0]) , ec = 'updateValue( "Key_Manager|translateX|transX" )' )
def updateValue (name) :
name = name.split('|')
name = name[-1]
attr = name.split('|')
attr = name[1]
cmds.setAttr ("%s + .attr" %selected, textField.tx)`
import maya.cmds as cmds
wName = "Key_Manager"
selected = cmds.ls(selection=True)
# Make a new window
#
if cmds.window(wName , exists = 1) : cmds.deleteUI(wName)
window = cmds.window( wName, s=0)
form = cmds.formLayout (wName +'Form')
# Translate
#
translateMenu = cmds.text ( l='TranslateX' , fn="boldLabelFont")
cmds.formLayout( form , e=1 , attachForm = [ (translateMenu , 'top' , 45) , (translateMenu, 'left' , 50 ) ] )
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected[0]) , ec = 'updateValue( "Key_Manager|translateX|transX" )' )
cmds.formLayout( form , e=1 , attachForm = [ (transX_value , 'top' , 68) , (transX_value , 'left' , 50 ) ] )
# Show Window
cmds.window( wName,e=1)
cmds.showWindow(window)
# Update Value
#
def updateValue (name) :
name = name.split('|')
name = name[-1]
attr = name.split('|')
attr = name[1]
cmds.setAttr ("%s + .attr" %selected, name+'_value'.text.getAttr('value'))
import maya.cmds as cmds
wName = "Key_Manager"
selected = cmds.ls(selection=True)
if cmds.window(wName , exists = 1) : cmds.deleteUI(wName)
window = cmds.window( wName, s=0)
form = cmds.formLayout (wName +'Form')
translateMenu = cmds.text ( l='TranslateX' , fn="boldLabelFont")
cmds.formLayout( form , e=1 , attachForm = [ (translateMenu , 'top' , 45) , (translateMenu, 'left' , 50 ) ] )
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected[0]) , ec = 'updateValue( "Key_Manager|translateX|transX" )' )
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected[0]))
cmds.textField(transX_value, edit=True, ec = 'updateValue("%s")'%transX_value)
cmds.formLayout( form , e=1 , attachForm = [ (transX_value , 'top' , 68) , (transX_value , 'left' , 50 ) ] )
cmds.window( wName,e=1)
cmds.showWindow(window)
def updateValue (name) :
name = name.split('|')
name = name[-1]
attr = name.split('|')
attr = name[1]
cmds.setAttr ("%s + .attr" %selected, name+'_value'.text.getAttr('value'))
def updateValue (name) :
value = cmds.textField(name, query=True, text=True)
cmds.setAttr ("%s + .attr" %selected, name+'_value'.text.getAttr('value'))
cmds.setAttr("%s.translateX"%selected[0]....
cmds.setAttr("%s.translateX"%selected[0], float(value))
import maya.cmds as cmds
from functools import partial
# Update Value
# I've changed the function and add the var attr to be more procedural
# and i've added *args, because command flags in maya add a default last argument True that
# is not useful
def updateValue (name, attr, *args) :
value = cmds.textField(name, query=True, text=True)
#I've added the attr to be more procedural
cmds.setAttr("%s.%s" %(selected[0], attr), float(value))
wName = "Key_Manager"
# Not enough protected varaible selected : should be inside a dic or a variable name more complicated
# as : Key_Manager_sel = cmds.ls(selection=True)
# see forward in the end on the update method
selected = cmds.ls(selection=True)
# Make a new window
#
if cmds.window(wName , exists = 1) : cmds.deleteUI(wName)
window = cmds.window( wName, s=0)
form = cmds.formLayout (wName +'Form')
# your attr should be not harcoded, see line 29, in order to be procedural
attr = 'translateX'
# Translate
# Create only one element one layout to place in your formLayout
wdgSetField = cmds.rowLayout(numberOfColumns=2)
# for ui nomenclature, i use lb_ for label or text (in Qt, it is cmds.text is a QLabel)
# attr[0].upper() is your 'T' and attr[1:] is : 'ranslateX'
lb_Tx = cmds.text ( l=attr[0].upper() + attr[1:] , fn="boldLabelFont", p=wdgSetField)
# same here i would use a prefix because it is not really your value tx
# as haggi krey told you, you have to attach the function in a second part in order to have the name of the textField
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.%s" %(selected[0], attr)), p=wdgSetField)
cmds.textField(transX_value, edit=True, ec = partial(updateValue, transX_value, attr))
# Just attach it to the form layout
cmds.formLayout( form , e=1 , attachForm = [ (wdgSetField , 'top' , 45) , (wdgSetField, 'left' , 50 ) ] )
# from line 17 to 28, should be a def because you will repeat this code for many attributes :
'''
def widget_attr(attr, pos=list):
"""
parameter:: attr:: <str> long name of an attr, ie : 'translateX'
parameter:: pos:: <list> [45, 50] take exactly two integer
"""
wdgSetField = cmds.rowLayout(numberOfColumns=2, p=form)
lb_attr = cmds.text ( l=attr[0].upper() + attr[1:] , fn="boldLabelFont", p=wdgSetField)
le_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.%s" %(selected[0], attr)), p=wdgSetField)
cmds.textField(le_value, edit=True, ec = partial(setValue, le_value, attr))
cmds.formLayout( form , e=1 , attachForm = [ (wdgSetField , 'top' , pos[0]) , (wdgSetField, 'left' , pos[1] ) ] )
# return the line edit for futur use, it is just here for knowledge (your can return a list of items too)
return [attr, le_value]
# Why using dictionnary ? it could be a list but if you want to update every value on selection change,
# you will have to store this textField somewhere
ui_dic = {}
ui_dic['tx_prm'] = widget_attr('translateX', [45, 50])
ui_dic['ty_prm'] = widget_attr('translateY', [90, 100])
ui_dic['rx_prm'] = widget_attr('rotateX', [140, 50])
def updateTextField(selected):
# Loop through the textField
for k in ui_dic.keys():
# in theory, i could just take 'tx_prm' and strip _prm to find the attr but :
attr = ui_dic[k][0]
le_Name = ui_dic[k][1]
value = cmds.getAttr("%s.%s" %(selected[0], attr))
cmds.textField(le_Name, e=True, text=str(value))
def setValue(name, attr, *args):
value = cmds.textField(name, query=True, text=True)
cmds.setAttr("%s.%s" %(selected[0], attr), float(value))
# For the script Job Part :
def onChangeSel():
selected = cmds.ls(selection=True)
updateTextField(selected)
# On selection change, update selection and textField
scriptJobID = cmds.scriptJob(e=["SelectionChanged", onChangeSel], protected=True)
# Script Job need to be deleted when the ui is closed or they will stack :
scriptJobWinClose()
def scriptJobWinClose():
# create another scriptJob that will run once when the ui will be closed and run the function :
cmds.scriptJob(runOnce=True, uid=[wName, closeEvent])
def closeEvent():
# We just kill the scriptJob here but you could do really anything you want on the window closing
cmds.scriptJob(kill=scriptJobID, force=True)
'''
# Show Window
cmds.window( wName,e=1)
cmds.showWindow(window)
import maya.cmds as cmds
from functools import partial
def updateTextField(selected):
# Loop through the textField
for k in ui_dic.keys():
# in theory, i could just take 'tx_prm' and strip _prm to find the attr but :
attr = ui_dic[k][0]
le_Name = ui_dic[k][1]
value = cmds.getAttr("%s.%s" %(selected[0], attr))
cmds.textField(le_Name, e=True, text=str(value))
def setValue(name, attr, *args):
value = cmds.textField(name, query=True, text=True)
cmds.setAttr("%s.%s" %(selected[0], attr), float(value))
wName = "Key_Manager"
# Not enough protected varaible selected : should be inside a dic or a variable name more complicated
# as : Key_Manager_sel = cmds.ls(selection=True)
# see forward in the end on the update method
selected = cmds.ls(selection=True)
# Make a new window
#
if cmds.window(wName , exists = 1) : cmds.deleteUI(wName)
window = cmds.window( wName, s=0)
form = cmds.formLayout (wName +'Form')
def widget_attr(attr, pos=list):
"""
parameter:: attr:: <str> long name of an attr, ie : 'translateX'
parameter:: pos:: <list> [45, 50] take exactly two integer
"""
wdgSetField = cmds.rowLayout(numberOfColumns=2, p=form)
lb_attr = cmds.text ( l=attr[0].upper() + attr[1:] , fn="boldLabelFont", p=wdgSetField)
le_value = cmds.textField( w=100 , h=22 , tx= 0, p=wdgSetField)
cmds.textField(le_value, edit=True, ec = partial(setValue, le_value, attr))
cmds.formLayout( form , e=1 , attachForm = [ (wdgSetField , 'top' , pos[0]) , (wdgSetField, 'left' , pos[1] ) ] )
# return the line edit for futur use, it is just here for knowledge (your can return a list of items too)
return [attr, le_value]
# Why using dictionnary ? it could be a list but if you want to update every value on selection change,
# you will have to store this textField somewhere
ui_dic = {}
ui_dic['tx_prm'] = widget_attr('translateX', [45, 50])
ui_dic['ty_prm'] = widget_attr('translateY', [90, 100])
ui_dic['tz_prm'] = widget_attr('translateZ', [150, 100])
ui_dic['rx_prm'] = widget_attr('rotateX', [200, 50])
# You can add any other textfied parameter like scaleX...etc
'''
# For the script Job Part :
def onChangeSel():
selected = cmds.ls(selection=True)
updateTextField(selected)
# On selection change, update selection and textField
scriptJobID = cmds.scriptJob(e=["SelectionChanged", onChangeSel], protected=True)
# Script Job need to be deleted when the ui is closed or they will stack :
scriptJobWinClose()
def scriptJobWinClose():
# create another scriptJob that will run once when the ui will be closed and run the function :
cmds.scriptJob(runOnce=True, uid=[wName, closeEvent])
def closeEvent():
# We just kill the scriptJob here but you could do really anything you want on the window closing
cmds.scriptJob(kill=scriptJobID, force=True)
'''
# Show Window
cmds.window( wName,e=1)
cmds.showWindow(window)
updateTextField(selected)