How to switch via expression

   10159   6   2
User Avatar
Member
50 posts
Joined: April 2017
Offline
Hi,

I want to switch two object with “switch node”,for example,there is a sphere object node,an object merge node and a switch node in the scene,if there is no object in the merge node,the switch input is 0,else is 1,how to achieve this goal?I tried to write a expression code(as in the screenshot),but doesn't work,could you help me?Thanks in advanced!

Attachments:
Capture.PNG (59.9 KB)

User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Greeting.
You can use npoints function to get number of points in your object merge if it would be zero then it goes with sphere.
Documentation page for npoints:
http://www.sidefx.com/docs/houdini/expressions/npoints [www.sidefx.com]

for your file do this in switch1:
if(npoints(“../object_merge1/”) != 0, 1, 0)
User Avatar
Member
50 posts
Joined: April 2017
Offline
Hi,Nima

Thanks very much! It is working nice!
User Avatar
Member
11 posts
Joined: Jan. 2006
Offline
or even

if(npoints(“../object_merge1/”), 0, 1)
User Avatar
Member
7 posts
Joined: Aug. 2015
Offline
Of course the you have to use " not “ or ”.
Cheers, D
User Avatar
Member
4491 posts
Joined: Feb. 2012
Offline
Hi,

You can also just do something like this:

npoints("../object_merge1/") > 0
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
642 posts
Joined: Aug. 2013
Offline
Hi

I just found this thread.

There is also a new node to 18.0 called switchif.

https://www.sidefx.com/docs/houdini/nodes/sop/switchif.html [www.sidefx.com]

Best

Mark
  • Quick Links