pass arguments to function called in textField "-enterCommand"?

pass arguments to function called in textField "-enterCommand"?

Anonymous
Not applicable
721 Views
3 Replies
Message 1 of 4

pass arguments to function called in textField "-enterCommand"?

Anonymous
Not applicable

I have an array of text fields, and when the user changes the values I need to call a function.  How do I let the function know which of the text fields was changed?  Does the 'enterCommand' argument take arguments itself?  I tried doing this:  -entercommand "textFieldChanged($i)" ,  where $i is the number of the text field.  But I get an error.  How do you pass arguments to the functions triggered by -enterCommand?

 

Thanks!

 

0 Likes
722 Views
3 Replies
Replies (3)
Message 2 of 4

jmreinhart
Advisor
Advisor
def textField_command(passed_value):
    print passed_value

window = cmds.window()
cmds.rowColumnLayout( numberOfColumns=1)
#
cmds.text( label='Name' )
name = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(name)
cmds.textField(name, e = True, ec = ec_val)
#
cmds.text( label='Address' )
address = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(address)
cmds.textField(address, e = True, ec = ec_val)
#
cmds.text( label='Phone Number' )
phoneNumber = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(phoneNumber)
cmds.textField(phoneNumber, e = True, ec = ec_val)
#
cmds.text( label='Email' )
email = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(email)
cmds.textField(email, e = True, ec = ec_val)
#
cmds.showWindow()

Here is an example

0 Likes
Message 3 of 4

jonsX942W
Enthusiast
Enthusiast

I wanted to learn this as well so I took a stab at it. Try this 

import maya.cmds as cmds

#printedInput = (textField_command(fieldTexts))
#print printedInput

nameInput=""
addressInput=""
phoneInput=""
emailInput=""


def defaultButtonPush(fieldTexts):
    print fieldTexts
    controls = cmds.lsUI( controls=True, long=True)
    print controls
    #this finds the "MyWindows" 
    myWindowCtls = [ctl for ctl in controls if ctl.find('MyWindow') == 0]
    print myWindowCtls
    #This finds all of the items with "textfield" in the name
    myTextCtls = [ctl for ctl in myWindowCtls if ctl.find('textField') != -1]
    print myTextCtls
    UserInput = [ (cmds.textField(text, query = True, text=True)) for text in myTextCtls]
    #print "name is" + nameInput
    print UserInput
    print 'Button 1 was pushed.'
    nameInput=UserInput[1]
    print nameInput
    addressInput=UserInput[2]
    print addressInput
    phoneInput=UserInput[3]
    print phoneInput
    emailInput=UserInput[0]
    print emailInput




window = cmds.window("MyWindow")
cmds.rowColumnLayout( numberOfColumns=1)
#
cmds.text( label='Name' )
name = cmds.textField(aie = True,)
ec_val = 'textField_command("{}")'.format(name)
cmds.textField(name, e = True, ec = ec_val)


#
cmds.text( label='Address' )
address = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(address)
cmds.textField(address, e = True, ec = ec_val)
#
cmds.text( label='Phone Number' )
phoneNumber = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(phoneNumber)
cmds.textField(phoneNumber, e = True, ec = ec_val)
#
cmds.text( label='Email' )
email = cmds.textField(aie = True)
ec_val = 'textField_command("{}")'.format(email)
cmds.textField(email, e = True, ec = ec_val)
#

cmds.button( label='Enter', c = defaultButtonPush )

cmds.showWindow()






    


#textField_command(passed_value)

0 Likes
Message 4 of 4

jonsX942W
Enthusiast
Enthusiast

Did this fix your Issue? if so can accept solution?

0 Likes