String to Vector

   5987   20   1
User Avatar
Member
766 posts
Joined: April 2014
Offline
How do you get an expression evaluated as a string to a vector; I don't think it's possible ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Probably smarter ways to do this but here's a solution:
string strvec = "20.001, 50.2 , 50.54"; 
string stringvector[] = split( strvec, ",");
float x = atof( strip( stringvector[0] ) );
float y = atof( strip( stringvector[1] ) );
float z = atof( strip( stringvector[2] ) );
v@mynewvector = set(x,y,z);

-b
Edited by bonsak - Feb. 23, 2017 12:10:39
http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
I assume the equivalent in VOP's would be the split VOP for the second line ? What would be the equivalent with regards to the atof() function ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Split and Strip are the same. Not sure if there is a String to Float (atof) in VOP's. You could always use a snippet VOP though.

-b
Edited by bonsak - Feb. 23, 2017 20:58:16
http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
How would one get the string vector from a split VOP; if the split VOP is getting it's string, as I mentioned from a string expression and put that into a snippet VOP, as in the case with your all VEX code ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Just pass in the attributes you want to work with in the Snippet and it will automatically create outputs for you. Inside the Snippet you access these attributes without using the “@”:

-b
Edited by bonsak - Feb. 24, 2017 04:24:30

Attachments:
snippet.hiplc (69.6 KB)

http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
Since I'm splitting an expression string using the split vop from a parameter vop, correct me if this is wrong but to use atof() in a snippet vop I would use the stringdef parameter from the string expression of the paramater vop as such ?

float x = atof(seperators(stringdef[0]));
Edited by _Christopher_ - Feb. 24, 2017 18:45:34
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Not sure i understand. Where does the “seperators()” function come from?

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
bonsak
Not sure i understand. Where does the “seperators()” function come from?

-b

Since you used the strip() function, and I'm using the split vop, I thought I had to replace the strip() function you used in your code with the parameter of the strip vop.
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
You probably want to strip the split strings for white space characters anyway.
Here is a version in vops (almost). Still can't find a way to cast a string to float in vops other than in a snippet:

Attachments:
string_to_vector_vops_almost.hiplc (70.7 KB)

http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
In the split vop if the string expression consists of back ticks and quotes with only one forward slash; Is it safe to assume that I should use the quotes separator and only the quotes seperator considering the expression string consists of (4) quotes Therefore if you break up (4) quotes you would get three vectors; followed by the getElement vop node then the strip vop ?

Where are you getting the strippedstring attribute in the snippet vop ?

It appears inconceivable that a string can be a vector; curious on how that is understood by Houdini.
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
How is your “string vector” formated?

The “strippedstring” name is produced by the Strip VOP. If you hoover over the output you'll see. The Snippet node automatically numbers identical input names, resulting in “stripedstring, strippedstring_2, strippedstring_3” as variables in the Snippet VOP.
Well strings can be turned in to vectors just fine if you just isolate the character describing your values and then cast these character(s) to an other data type that in turn can be used to compose a vector. There's obviously room for errors in this scenario but it works as long as you are reasonably consistent with your input string.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
How is your “string vector” formatted?
Hoping I'm understanding your definition of “string vector”; which in my case is encapsulated in back ticks ?

Why I ask, is it safe to assume or proceed with splitting the string based on the quotes, in this case there are four; within the range of the back ticks which encapsulated the entire expression ? For example on this faux expression;

`chs(input(“.”),“output”)`

input < vector 1
(“.”) < vector 2
“output” <vector 3

The above case splitting the string at the first quotes, followed by the second quotes, therefore making a vector ? And so the separator parameter in the split vop would be set to quotes; that is if the above explanation is correct ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
The “” quotes it's just a way of telling H that the contents between the “” are a string. You should not have to take them into consideration when splitting your incoming (string)vector. It's the character between your 3 vector components that are used for splitting. So if your (string)vector looks like this: “10.1, 20.2 , 30.3” you have to tell the Split function what character is used to separate the string “pieces” you are interested in. So telling Split to use “,” on the string “10.1, 20.2 , 30.3” you end up with three strings:
“10.1”, “20.2” and “30.3”
Not entirely sure how you are organizing your parameter inputs in relation to the VOP so it's a little hard to tell how it's best to set this up. Do you have a file you could upload showing your setup?

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
I should have known better then to explain the use of quotes for splitting up a string.

At the moment the branch in a network vop is as follows;

Paramater > Split > snippet
(If more information is needed as in a screen capture ?)

Any guide lines as to how to split an expression string so it can be converted to a vector ? When looking at the expression string one could randomly place commas but it doesn't seem right ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Here is the same file but with the string coming into VOPs via a parameter exposed on the outside.
The string value is referenced from another parameter and evaluated before its being “sent into” VOPs.

-b

Attachments:
string_to_vector_vops_almost_2.hiplc (71.8 KB)

http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
The parameter is exposed outside of the attribute vop two things;

What if I'm not referencing another parameter, strictly a string expression. I don't understand how the split vop will know or where I should tell it; where to split the string expression so the result is a vector ?

Second, how did you create the String Stuff tab within the attribute vop ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Could you give me an example of an expression you would use?

With the VOP node selected, click on the little cog wheel in the upper right corner of your parameters pane and select “Edit Parameter Interface”. There you can select “Folder” and drag it into your “Existing Parameters” to organize your other custom parameters if you want. In this case i dragged the “Pipe into…” + “Another Parameter” into that folder.
When you make a Parameter node inside a VOP it is automatically added to “Existing Parameters”

-b

Attachments:
houdini_2017-02-27_11-30-21.png (144.9 KB)

http://www.racecar.no [www.racecar.no]
User Avatar
Member
766 posts
Joined: April 2014
Offline
This is the expression I want to use and split from a string to a vector;

`chs(opinputpath(".",0) + "/splitloc")`

Sorry, I don't know how you got the “Pipe Into VOPS” nested Parameter ? I searched and searched within the “Edit Parameter Interface” couldn't find such a parameter ?
【T】【C】【S】
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
If you just enter:
`opinputpath(".",0) + "/splitloc"`
it will only result in this string when done in the file i've uploaded:
/obj/Geo/grid1/splitloc
. Opinputpath only returns the path. There is no vector information in that. You need to specify from what point/vertex/primitive you are getting you vector from. To get the position of point 0 of the geo connected to input 1, you would do something like this:
`point(0, 0, "P", 0) + "," + point(0, 0, "P", 1) + "," + point(0, 0, "P", 2)`
.point expression function [sidefx.com]
The “Pipe Into VOPS” parameter is just a string parameter except it is defined inside the VOPS node “string_to_vector”. Take a look at the “parm1” node.

-b
Edited by bonsak - Feb. 27, 2017 13:19:02
http://www.racecar.no [www.racecar.no]
  • Quick Links