Switch if prim exists
2841 7 0-
- lloydwood
- Member
- 107 posts
- Joined: 11月 2007
- Offline
I'm trying to to get a switch in lops to change based on whether a prim exists or not. The aim is to automatically create a beauty rendervar and product if one has not be defined. I can't work out how to set the switch lop up to achieve this though. Basically if "/Render/Products/beauty" exists, 0, else, 1.
-
- Hamilton Meathouse
- Member
- 203 posts
- Joined: 11月 2013
- Offline
This is a messy way, but I put a Python lop above the switch with this code in it. Sadly I have to right-click the node and Re-cook to get it to update.
node = hou.pwd() stage = node.editableStage() path = '/Render/Products/Vars/Beauty' blah = stage.GetPrimAtPath(path) print blah if blah: hou.parm('/stage/switch1/input').set(0) else: hou.parm('/stage/switch1/input').set(1)
-
- lloydwood
- Member
- 107 posts
- Joined: 11月 2007
- Offline
-
- Hamilton Meathouse
- Member
- 203 posts
- Joined: 11月 2013
- Offline
-
- mtucker
- スタッフ
- 4527 posts
- Joined: 7月 2005
- Offline
I'm not quite sure why the straightforward approach wouldn't work... Can't you just set the "Switch Index" to an expression that looks at `pwd().input(0).stage()` to check for the prim, and returns 0 or 1 depending on whether the prim exists or not?
But I'll also point out that you can skip the Switch LOP entirely, and instead use an "activation parameter" on the LOP nodes that you want to operate conditionally. RMB on a LOP node, and under Parameters or LOP Actions, depending on the Houdini version, will be a menu item to "create activation parameter". When this parameter is 0, the LOP node acts like it is bypassed. So you can set this to a python expression that checks for the existence of the prim.
But I'll also point out that you can skip the Switch LOP entirely, and instead use an "activation parameter" on the LOP nodes that you want to operate conditionally. RMB on a LOP node, and under Parameters or LOP Actions, depending on the Houdini version, will be a menu item to "create activation parameter". When this parameter is 0, the LOP node acts like it is bypassed. So you can set this to a python expression that checks for the existence of the prim.
-
- lloydwood
- Member
- 107 posts
- Joined: 11月 2007
- Offline
-
- mtucker
- スタッフ
- 4527 posts
- Joined: 7月 2005
- Offline
I can't say with complete certainty, but the activation parameter feature is quite old (though not well known). In 19.0.526 it shows up under "Parameters and Channels" -> "Create Activation Parameter". Future versions of Houdini just moved it under "LOP Actions" to make it a little easier to discover.
-
- Hamilton Meathouse
- Member
- 203 posts
- Joined: 11月 2013
- Offline
-
- Quick Links