Jump to content
Simchron

Dynamic Vex Variable Names?

Recommended Posts

Hi there!

Is it possible to dynamically declare variables in a for loop with the index in the variable name?

Current problem:
I want to store primitives with similar normal angles into an array. The maximum number of arrays would be 4 (cardinal directions) but in most cases the normals head in only one direction.

Thanks in advance.

Cheers

Share this post


Link to post
Share on other sites
Posted (edited)

its possible with H14 and up ;)

using the http://www.sidefx.com/docs/houdini16.0/vex/functions/setprimattrib function
along with http://www.sidefx.com/docs/houdini16.0/vex/functions/sprintf

for example

float angleVal;
string attribName;

for(int i = 0; i < 4; i++)
{
	attribName = sprintf("angleDir_%d", i);
    angleVal = i; //do your math here                 
    setprimattrib(0, attribName, @primnum, angleVal);
}
                    

in H13 and lower, the attributes have to exist before the setprimattrib or setpointattrib etc are used, with H14 and up, it will generate it for you :)

or you can store them directly as an array attribute, but in some cases it may complain if the sizes of the array are not the same (at least in Python I think)

in vex that would look something like this:

float angleVals[], angleVal;
string attribName;

for(int i = 0; i < 4; i++)
{
    angleVal = i; //do your math here                 
    append(angleVals, angleVal);
}
                     
f[]@outAngles = angleVals;
                    
Edited by acey195
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi Twan,

thank you very much for taking the time and the detailed explanation.

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

×