feed user input value back to an attribute

39 views
Skip to first unread message

Jason Huang

unread,
Mar 11, 2014, 9:04:34 AM3/11/14
to python_in...@googlegroups.com
Hi everyone,

I am new to the forum. Please bear with me if my question sounds too vague.

Trying to create a simple spreadsheet-like interface to list the value of selected attribute and be able to update/feed the user input value back to the attribute shown in Attribute Editor.

Here is the mock up code.

import maya.cmds as cmds

cmds
.window(title = "test window", w=400, h=600, mxb=False, mnb=False)
mainLayout
= cmds.columnLayout(w=400, h=600)
cmds
.tabLayout(imw=5, imh=5)
vrayMtlList
= cmds.ls(type = "VRayMtl")
cmds
.columnLayout("Material matte ID", w=400, h=600)

for vrayMtl in vrayMtlList:
   
if cmds.objExists(vrayMtl + ".vrayMaterialId"):
               
        currentMatteID
= cmds.getAttr(vrayMtl + ".vrayMaterialId")
       
        matteIdValue
= cmds.intFieldGrp(numberOfFields = 1, label=vrayMtl + "_matteID", value1 = currentMatteID)
       
cmds
.showWindow()

I was able to get a simple GUI with integer fields show up with current VRay material multimatte ID displayed.
I want the Attribute Editor multimatte be updated when users type in new multimatte ID and press the "Enter" or hit a "Button", but could not figure out how.
I have tried to define a function to be called in the intFieldGrp or see if I missed a flag that can achieve this easily.

Any input would be much appreciated.

Thanks!



Doktor Weeny

unread,
Mar 11, 2014, 10:39:38 PM3/11/14
to python_in...@googlegroups.com
Hi,
Use "changeCommand" flag to attach a function to
intFieldGrp.

If you have some arguments to pass, you have to use partial from functools :

from functools import partial

def myFunction(myArg01, myArg02, *args):
   
print myArg01, myArg02

arg01
= "first value"
arg02
= "anything"

cmds
.intFieldGrp(numberOfFields = 1, label=vrayMtl + "_matteID", value1 = currentMatteID, changeCommand = partial(myFunction, arg01, arg02) )



I hope it help.

Alexis

Mark Serena

unread,
Mar 12, 2014, 2:38:36 AM3/12/14
to python_in...@googlegroups.com
also check out connectControl, it will create a two way connection between your ui and ae

artificialr...@gmail.com

unread,
Mar 16, 2014, 8:19:54 AM3/16/14
to python_in...@googlegroups.com
Thank you all guys! I was able to achieve the functionally I wanted with the functools. Will give the connectControl a try at some point.

Cheers,
JH

Reply all
Reply to author
Forward
0 new messages