Jump to content

Accessing Global Variables From VEX wrangle nodes


PioRaffaeleFina

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

 

Link to comment
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'  ?

Link to comment
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
Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...