Conditional statement in callback with python

   4303   2   2
User Avatar
Member
1145 posts
Joined: July 2005
Offline
Okay, I don't know how to script with python but figured I'd better try.

I have a simple rig with a switch sop that is controlling which LOD of geometry I wish to display.
The switch has a range of 0-2, with the default at 1. The 0 setting shows no geometry, just bones. However I've turned off the visibility of some of the bones, when I'm displaying the geometry.
What I'd like to do is set a callback script so that when I change the switch to 0 all the bone display flags are turned on.

So I'm thinking it will be something like,

if switch < 1, setDisplayFlag on “bones”, 0

I don't know the correct syntax.

Who can help me?
“gravity is not a force, it is a boundary layer”
“everything is coincident”
“Love; the state of suspended anticipation.”
User Avatar
Member
1390 posts
Joined: July 2005
Offline
but you want to put this callback script in HDA definition, right?
If so, this should be put to PythonModule script section of HDA:

def switchDisplay(self):

def childrenFlags(self, val, type='bone'):
for child in self.children():
if child.type().name() == type:
child.setDisplayFlag(val)


if self.parm('switch').eval() == 0: childrenFlags(self, 0, ‘bone’)
else: childrenFlags(self, 1, ‘bone’)


Then in callback field of your parameter called ‘switch’ (like integer):

hou.pwd().hdaModule().switchDisplay(hou.pwd())

This switches display flags Off and On for all bones in subnetwork.

I think something has changed in callback area in 9.1 but I'm not sure what.

hope this help,
sy.

EDIT:
fixed type().name() method
User Avatar
Member
1145 posts
Joined: July 2005
Offline
Hey, that works like a charm. Thanks Sy.

I reversed the display values since I want the bones visible on 0.

I need to modify the code to act on node names rather than type.
“gravity is not a force, it is a boundary layer”
“everything is coincident”
“Love; the state of suspended anticipation.”
  • Quick Links