Jump to content

Dynamic Vex Variable Names?


Simchron

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

Link to comment
Share on other sites

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
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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...