Vex and key-value interface parameters

   4797   4   1
User Avatar
Member
13 posts
Joined: Feb. 2017
Offline
Hi,
Anyone know how(or even, if it's possible ) to read a key-value dictionary parameter using Vex? I such a parameter variable on the wrangles Parameter Interface but not sure what data type to declare it eg a string: string kvd[] = ch("../kvDict")? The latter seems to read it in but seems to contain special characters (carriage return) so parsing it might be difficult.

thanks,
Richard.

Edit by ndickson: fixed forum's automatic text conversion in VEX snippet.
Edited by neil_math_comp - March 4, 2018 12:06:54
User Avatar
Member
323 posts
Joined: Jan. 2015
Offline
Hi Richard,
what is it you want to do/achieve with this?
Do want to parse a text file? Do you want to manually input a number of values?
Do you have a .HIP file where we can see what you want to do? Please upload a simplified version of your issue as a hip file.
BTW: I think the answer to your first question is: yes.

Have a look at this:
http://www.sidefx.com/docs/houdini/nodes/sop/tableimport.html [www.sidefx.com]

kind regards

OLaf
User Avatar
Member
13 posts
Joined: Feb. 2017
Offline
Hi Olaf,
Thanks for your reply. Your suggestion to use a TableImport node would work, however there will be several dozen instances of this hda each one would require its own file… (not so good) or one big file (which I would have to parse (also not so good)).

What I am trying to do is set the orientation of a few points by inputing the Euler rotation data by hand (to automate this would be more painful). Since the number of points changes from about 4 to about 12 the key-value data structure seemed the better option. The key is the point number and the value is a comma separated list of vector components and an angle.

The data can be read in as one long string so in the end I wrote a short bit of Vex to split the string. If anything about the internal representation of the data string changes the code will break so its not the best of solutions. For the benefit of anyone else trying to use the key-value parameter I have included my code below (it will need to be edited according if the key data or value data are different to mine.

thanks again,
Richard.


“kvDict” is the name of key-value parameter.

string kvd=ch("../kvDict");
string kvpair[];
string svec[];
vector nm;
vector4 quat;
string socks[] = split(kvd,"\n");


for(int i=1; i<min(len(socks)-1,120); i++)
{

// split pairs at ":"
kvpair=split(socks[i],":");

// Strip whitespace and  string quotes
kvpair[0]=strip(kvpair[0]);
kvpair[0]=strip(kvpair[0],"\"");

// Strip whitespace and  string quotes
kvpair[1]=strip(kvpair[1]);
kvpair[1]=strip(rstrip(kvpair[1],","),"\"");

svec=split(kvpair[1],",");

nm = normalize(set(atof(svec[0]),atof(svec[1]),atof(svec[2])));

quat = quaternion(radians(atof(svec[3])),nm);
setpointattrib(0,"orient",atoi(kvpair[0]),quat,"set");

setpointattrib(0,"socket",atoi(kvpair[0]),"post","set");

}
User Avatar
Member
8538 posts
Joined: July 2007
Online
it's just a dictionary or JSON string, I'd not try to parse it in VEX, you can easily use python SOP to create attribs based on it as Python reads it as a dict type directly
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
13 posts
Joined: Feb. 2017
Offline
Thanks Tamte,
I agree a dictionary data structure is very natural to python, but then I have to get fluent with Python in Houdini - it's on my list - but was holding out in case there was a “simple” solution.

cheers,
Richard.
  • Quick Links