PDA

View Full Version : Passing arguments/getting values from fields


PozestStar
12-08-2012, 12:06 AM
I feel so silly asking this question. I'm sure it has a simple answer, but I really don't know what it is.

Here's a bareboned example of what I'm trying to do.

Enter the values, press the button, create a cube. The problem is, I can't create a cube with the updated information in my fields. I'd like to avoid doing "mc.intField("n", query = True, value = True)" in the makeCube section if I can, but I'm not sure how else I can get the updated values in my fields.

Thanks.


import maya.cmds as mc

def exampleWin():
try: mc.deleteUI("exampleWin")
except: pass

win = mc.window("exampleWin", title = "Help me!")
layout = mc.rowLayout(nc = 4)
nameField = mc.textField("n", text = "bobTheCube")
widthField = mc.intField("w")
heightField = mc.intField("h")
name = mc.textField("n", query = True, text = True)
width = mc.intField("w", query = True, value = True)
height = mc.intField("h", query = True, value = True)
doButton = mc.button(label = "Create Cube!", command = lambda x:makeCube(name, width, height) )

mc.showWindow(win)

def makeCube(name, width, height, *args):
mc.polyCube(name = name, width = width, height = height)

NaughtyNathan
12-08-2012, 11:06 AM
This is one of the things that the vanilla cmds ui stuff is really not that good for. However, if you want to use this approach the simplest answer is to just make a second function that prepares your data and calls the relevent function. In fact this is exactly how a lot of internal MEL commands work...
add something like:
def prepMakeCube(*args):
name = mc.textField("n", query = True, text = True)
width = mc.intField("w", query = True, value = True)
height = mc.intField("h", query = True, value = True)
makeCube(name,width,height)
then just change your doButton to:
doButton = mc.button(label = "Create Cube!", command = prepMakeCube )

PozestStar
12-08-2012, 03:23 PM
Thanks so much for this. It was really driving me crazy.

CGTalk Moderation
12-08-2012, 03:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.