PioRaffaeleFina Posted March 23, 2016 Share Posted March 23, 2016 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 Quote Link to comment Share on other sites More sharing options...
Atom Posted March 23, 2016 Share Posted March 23, 2016 (edited) You can actually back tick access those $ variables in a wrangle. This works. float nf = `$NFRAMES`; printf ("%s\n", nf); Edited March 23, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
PioRaffaeleFina Posted March 23, 2016 Author Share Posted March 23, 2016 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' ? Quote Link to comment Share on other sites More sharing options...
haggi Posted March 23, 2016 Share Posted March 23, 2016 This could help: float nf = float(`$NFRAMES`); Quote Link to comment Share on other sites More sharing options...
PioRaffaeleFina Posted March 23, 2016 Author Share Posted March 23, 2016 This could help: float nf = float(`$NFRAMES`); still error, this time about invalid type in explicit casting :-) Quote Link to comment Share on other sites More sharing options...
bunker Posted March 23, 2016 Share Posted March 23, 2016 the simplest way is to add a spare parameter and reference it in vex Quote Link to comment Share on other sites More sharing options...
fathom Posted March 23, 2016 Share Posted March 23, 2016 what bunker said. use "ch()" or "chf()" to pull in your spare parm in vex. Quote Link to comment Share on other sites More sharing options...
haggi Posted March 24, 2016 Share Posted March 24, 2016 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. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted March 24, 2016 Share Posted March 24, 2016 (edited) 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 March 24, 2016 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
PioRaffaeleFina Posted April 15, 2016 Author Share Posted April 15, 2016 Thanks for all of your advices, very useful! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.