0

i'm beginning python scripting, and i'm having issues :

import maya.cmds as cmds

win = 'win'
if cmds.window(win, exists = True):
    cmds.deleteUI(win)

win = cmds.window(win, t = 'My First Almost-Functional Script')
cmds.showWindow(win)
cmds.columnLayout(adj = True)

cmds.separator(h = 25)

nameCtrl = cmds.textFieldGrp(l = 'Name :', editable = True) 
cmds.separator(h = 25 )
cmds.intSliderGrp( min=0, max=50, step=1, f =True )
cmds.separator(h = 25 )
cmds.button ('Test', l = 'Go! ', c = 'Check()')

Test = 'Test'

def Check():
    value = cmds.intSliderGrp('Test', q=True, v=True)
    if value==0 :
        cmds.error( "A null value has been chosen, nothing will happen." )
    else :
        cmds.headsUpMessage('Something is supposed to Happen')

i don't understand why it returns me an error saying that in line 22, object 'Test' isnt found... can anyone help me?

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
Atohm
  • 3
  • 1
  • I think you can't use "Test" as a variable name because it's already used by Python – Kulbuto Jan 08 '20 at 15:02
  • i tried replacing "Test" with "AnyRandomString", it show the same error message – Atohm Jan 08 '20 at 15:05
  • `Test` is not a reserved word; you can overwrite the value of an existing variable at any time. What is the *exact* error: line 22 doesn't refer to any Python name `Test`. It's not clear (to me, anyway) how `cms.intSliderGrp` interprets the *string* argument `'Test'`. – chepner Jan 08 '20 at 15:05
  • the exact error meesage is : " # Error: RuntimeError: file line 22: Object 'AnyRandomString' not found. # " – Atohm Jan 08 '20 at 15:07
  • What if you did not specify an argument to `intSliderGrp` at all? Leave in place only the keyword arguments. – Dima Chubarov Jan 08 '20 at 15:10
  • 1
    What did you change ? "Test = 'AnyRandomString'" or "AnyRandomString= 'Test'" ? – Kulbuto Jan 08 '20 at 15:11
  • "Test = 'AnyRandomString'" – Atohm Jan 08 '20 at 15:18

1 Answers1

1

You have this error because maya doesn't find the slider with the name 'Test'.

Try this:

import maya.cmds as cmds

win = 'win'
if cmds.window(win, exists = True):
    cmds.deleteUI(win)

win = cmds.window(win, t = 'My First Almost-Functional Script')
cmds.showWindow(win)
cmds.columnLayout(adj = True)

cmds.separator(h = 25)

nameCtrl = cmds.textFieldGrp(l = 'Name :', editable = True) 
cmds.separator(h = 25 )
slider = cmds.intSliderGrp( min=0, max=50, step=1, f =True )
cmds.separator(h = 25 )
cmds.button ('Test', l = 'Go! ', c = 'Check()')

def Check():
    value = cmds.intSliderGrp(slider, q=True, v=True)
    if value==0 :
        cmds.error( "A null value has been chosen, nothing will happen." )
    else :
        cmds.headsUpMessage('Something is supposed to Happen')

In fact, in your window, you create some layout. And your slider is in a layout. So, you need to get the full path of your slider in the UI and give it to the element which query the value.

I hope it will help you.

AlexLaur
  • 335
  • 4
  • 13