Jump to content
PioRaffaeleFina

Accessing Global Variables From VEX wrangle nodes

Recommended Posts

 
Hi all! I'm pretty noob with houdini so maybe this will be a silly question :-)
 
As the title says, I can't find a "direct" way to access to global variables in point/attribute wrangle nodes( maybe it's not possible?).
In my case I would access to $NFRAMES global variable to pass as parameter in fit() function to normalize frames count, but obvioulsy as reference guide say:
 

 

 

Accessing globals

Unlike in HScript expressions, you cannot use global variables such as $F.

In a VOP, you can wire variables such as Time and Frame from the Globals node to use them in a VEX snippet.

You can use the following implicit variables:

@Time

Float time ($T)

@Frame

Float frame ($FF)

@SimTime

Float simulation time ($ST), only present in DOP contexts.

@SimFrame

Float simulation frame ($SF), only present in DOP contexts.

@TimeInc

Float time step (1/$FPS)

 

 

Now I found a workaround: 
I create an attribute(with attributeCreate node) with $NFRAMES as value and then I can access in the wrangle code snippet. It works but I don't like this method because: for now I have just a bunch of points and the memory footprint is relatively low but what if I crank up the value for thousands of points? if I'm not wrong, integer values are handled as C small int so 4bytes*100.000 points will increase the memory footprint( I know that are just of bunch of KB but I'm "obsessed" with time/space performance). 
 
There are some "clean" way of get global variables?
 
Thanks in advance

 

Share this post


Link to post
Share on other sites

You can actually back tick access those $ variables in a wrangle.

 

This works.

 

float nf = `$NFRAMES`;
printf ("%s\n", nf);
Edited by Atom

Share this post


Link to post
Share on other sites

You can actually back tick access those $ variables in a wrangle.

 

This works.

 

float nf = `$NFRAMES`;
printf ("%s\n", nf);

 

Thanks for the reply, but doesn't work in this way for me.

'$NFRAMES' is a string while nf is float, infact the compiler return error: "invalid assignment".There is some kind of implicit cast for you(I'm on H15 apprentice)?  

btw I used atoi() to convert the string to an int and it works, so no problem. 

 

ps. can you explain me why I can get global variables with '$VARNAME'  ?

Share this post


Link to post
Share on other sites

the simplest way is to add a spare parameter and reference it in vex

Share this post


Link to post
Share on other sites

what bunker said.  use "ch()" or "chf()" to pull in your spare parm in vex.

Share this post


Link to post
Share on other sites

 still error, this time about invalid type in explicit casting :-)

Hmmm, that's interesting. No error here. I copy and paste the line in my pointwrangle node and it works fine.

Share this post


Link to post
Share on other sites

why I can get global variables with '$VARNAME'  ?

It is on parameter evaluation level, not the actual VEX syntax. Code fields are string parameters, like groups, file paths, names. You can use expressions there. It will be evaluated at the first frame before sending to the compiler.

 

You can generate VEX code in Python. Add an expression by RMB/Expression/Toggle expression or by adding a keyframe.

def generate_code(phrase):
    return 'printf("%s");' %phrase

return generate_code('fgs fds')
 

Pasted in the code field will evaluate to:

printf("fgs fds");
Edited by f1480187
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×