PDA

View Full Version : getAttr help (python)


gunner89
11-22-2010, 11:11 AM
Hey, ive only just started to use python and am having some trouble with getting the if statement syntax right. What i want this code to do is: if "pCube1" is visible, hide it. If it is hidden, show it. My code obviously doesnt work, can someone show me how to amend the if getAttr.pCube1.visible=true part? The toggleVisibility("pCube1") is what i want to type to run the function.

Thanks

p, li { white-space: pre-wrap; } import maya.cmds as cmds

if cmds.getAttr("pCube1", visibile=True)
def toggleVisibility(object):
cmds.hide(object)
elif
cmds.showHidden(object)
toggleVisibility("pCube1")

Jacobborsting
11-22-2010, 02:49 PM
def toggleVisibility(obj):
cmds.setAttr (obj+'.visibility', not cmds.getAttr (obj+'.visibility'))

toggleVisibility('pCube1')

gunner89
11-23-2010, 07:07 PM
thank you for your help, it proved to be a lot easier than the way i was trying to do it, thanks again.

CGTalk Moderation
11-23-2010, 07:07 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.