Maya Python Script Works From Console, Doesnt Work From File
import maya.cmds as cmds #Function def printTxtField(fieldID): print cmds.textField(fieldID, query=True, text=True) #define ID string for Window winID = 'myWindow' if cmds.w
Solution 1:
I prefer not to use text-based commands. Instead, you can assign callbacks. One option to try is using lambda (since you want to pass your own argument):
cmds.button(label='Click me', command=lambda x:printTxtField(whatUSay))
Solution 2:
Lambda should work but if you want something more clear, use partial :
import maya.cmds as cmds
from functools import partial
#Function# Don't forgot the *args because maya is putting one default last arg in -c flagsdefprintTxtField(fieldID, *args):
print cmds.textField(fieldID, query=True, text=True)
#define ID string for Window
winID = 'myWindow'if cmds.window(winID, exists=True):
cmds.deleteUI(winID)
cmds.window(winID)
cmds.columnLayout()
whatUSay = cmds.textField()
# syntax :: partial(function, argument1, argument2, ...etc)
cmds.button(label='Click me', command=partial(printTxtField, whatUSay))
cmds.showWindow()
Post a Comment for "Maya Python Script Works From Console, Doesnt Work From File"