String to Vector
6016 20 1- _Christopher_
- Member
- 767 posts
- Joined: April 2014
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
Probably smarter ways to do this but here's a solution:
-b
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
- _Christopher_
- Member
- 767 posts
- Joined: April 2014
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- _Christopher_
- Member
- 767 posts
- Joined: April 2014
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- _Christopher_
- Member
- 767 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】
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- _Christopher_
- Member
- 767 posts
- Joined: April 2014
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- _Christopher_
- Member
- 767 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.
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】
- bonsak
- 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
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
- _Christopher_
- Member
- 767 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】
- bonsak
- 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
“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
- _Christopher_
- Member
- 767 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 ?
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】
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- _Christopher_
- Member
- 767 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 ?
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】
- bonsak
- 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
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
- _Christopher_
- Member
- 767 posts
- Joined: April 2014
- Offline
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
If you just enter: it will only result in this string when done in the file i've uploaded: . 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 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
`opinputpath(".",0) + "/splitloc"`
/obj/Geo/grid1/splitloc
`point(0, 0, "P", 0) + "," + point(0, 0, "P", 1) + "," + point(0, 0, "P", 2)`
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
-
- Quick Links