PDA

View Full Version : textFieldButtonGrp question.


onetera
03-02-2009, 06:19 AM
If you run the below script ,select an object, press "register" button then new text field will be made.

I want the selected object name is represented on the existed text field.

Where should I fix it?




import maya.cmds as cmds

def jb_ui():
if cmds.window('JointBuilder',exists=1):cmds.deleteUI('JointBuilder')
window=cmds.window('JointBuilder', title=":::: Joint Builder ::::",wh=[300,100])
cmds.columnLayout( columnAttach=('left', 1), rowSpacing=3)
cmds.textFieldButtonGrp('1stJoint', label='1st Joint',buttonLabel='register',bc=reg_1st)
cmds.button('DoBuild',label='Build',w=150,h=30)
cmds.showWindow(window)

def reg_1st(*arg):
sel_ls = cmds.ls(selection=True)
cmds.textFieldGrp('1stJoint',tx=sel_ls[0])

jb_ui()

bendingiscool
03-02-2009, 03:32 PM
Not sure exactly what your trying to achieve, could you explain further please and then can help ya.

Cheers, Chris

onetera
03-03-2009, 07:15 AM
I want to print the selected object name on the existed text field when I press "register" button.

But now, the new text field is made when I press "register" button. And the selected object name is printed on the new text field.

I want to fix the code to print the selected object name on the existed text field.

How can I get it?

greatPumpkin
03-03-2009, 08:42 PM
If I understand what you are trying to do correctly you need to give your textfield a name on creation, and then when you call it again you need to use the edit=True flag to edit an existing textfield rather than create a new one

Keilun
03-03-2009, 10:51 PM
You want this:

import maya.cmds as cmds

def jb_ui():
if cmds.window('JointBuilder',exists=1):cmds.deleteUI ('JointBuilder')
window=cmds.window('JointBuilder', title=":::: Joint Builder ::::",wh=[300,100])
cmds.columnLayout( columnAttach=('left', 1), rowSpacing=3)
cmds.textFieldButtonGrp('firstJoint', label='1st Joint',buttonLabel='register',bc=reg_1st)
cmds.button('DoBuild',label='Build',w=150,h=30)
cmds.showWindow(window)

def reg_1st(*arg):
sel_ls = cmds.ls(selection=True)
cmds.textFieldButtonGrp('firstJoint',e=True,tx=sel_ls[0])

jb_ui()

The changes:

1. Object names cannot begin with a number. It must be a letter. It doesn't matter if you put quotes around it. Maya's command system just will reject it as a syntax error. I changed the textFieldButtonGroup name to: 'firstJoint'

2. In reg_1st(), you were originally calling textField rather than textFieldButtonGrp again.

3. In reg_1st(), you need to add the edit modifier: e=True to tell Maya that you're editing an existing textFieldButtonGrp named 'firstJoint', otherwise it tries to create a new textFieldButtonGrp with that name.

onetera
03-04-2009, 01:11 AM
That is a really what I want.

I`ve never known that "Object names cannot begin with a number".

And I`m really sorry all of you who gave me an answer, I should have used textFieldButtonGrp in the reg_1st() instead of textFieldGrp.


Thank you so much!!

CGTalk Moderation
03-04-2009, 01:11 AM
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.