how to use switch inputs in expressions

   6511   3   0
User Avatar
Member
2 posts
Joined: Dec. 2013
Offline
Hi, I'm trying to set a size stamp variable in a copy SOP which is dependant on the input of a switch. I've tried

set -g size = 0.0;

if(chs(“../switch_road_type/input”) == 0)
{
size=point(“../scatter_on_blocks”,$PT,“ptarea”,1)
}
else
{
size=point(“../scatter_on_islands”,$PT,“ptarea”,1)
}

return size;

however it gives the error Unable to evaluate expression (Sytax error (…/name_of_copy_sop/val1)).

Any help would be greatly appreciated.

Thanks
User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
Firstly you need to encapsulate the whole expression block in {}:

{
size = 0;
if (ch(“../switch1/input”) == 0)
size = 1;
else
size = 0;
return size;
}

Declare the variable as:

size = 0;

You can also directly return by using multiple return statements. It will early return.

Also use ch, not chs, as it's not a string.

A more Houdini-like approach IMO would be to use a Null and reference this in the stamp variable without using additional logic. This way no matter which input is used, you can read the same attribute from the Null node.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
2 posts
Joined: Dec. 2013
Offline
Thanks for your reply. I've tried your suggestion using

{
size = 0;
if (ch(“../switch_road_type/input”) == 0)
size = point(“../scatter_on_blocks”,$PT,“ptarea”,1);
else
size=point(“../scatter_on_islands”,$PT,“ptarea”,1);
return size=point(“../scatter_on_islands”,$PT,“ptarea”,1);
}

but it sill gives a syntax error: Unable to evaluate expression (Syntax error - extra tokens detected in expression (../name_of_copy_sop/val1). Do you know why this might be?


Forgive me if i'm missing something obvious too, but with the Null node method, surely i'll have the same problem that depending on which input is selected, it will need to contain different values?

Thanks
User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
When you use return, don't assign to the value in the same line. So do this:

{
size = 0;
if (ch(“../switch_road_type/input”) == 0)
size = point(“../scatter_on_blocks”,$PT,“ptarea”,1);
else
size=point(“../scatter_on_islands”,$PT,“ptarea”,1);
return size;
}

That should work.

With the Null method, you wouldn't have to but I assume you are generating the same attribute you are looking for in both branches. Something like this:



Though there are a lot of unknowns that can make this not as reasonable, such as whether you are not storing the result in the same attributes, or you need completely different logic to generate values based on the input number, etc.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
  • Quick Links