Hi all,
I am running into a limitation of the if() command because it will only return a float type, where it would useful to be able to return a string type at at times.
e.g., I want to do this:
`if( $F==1, “*”, “” )`
..so can I propose the addtion of a function called ifs() - a string return type if() function?
`ifs( $F==1, “*”, “” )`
Luckily, because I need only one character in this case, I can do this…
`substr(“ *”, $F==1, 1)`
But I've run into this situation a LOT. Does anyone have any other methods for conditionally selecting strings inside of expressions? The above method falls over with variable length strings.
Thanks,
Jason
ifs() ?
17851 23 3- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- stevenong
- Member
- 1631 posts
- Joined: July 2005
- Offline
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
- xiondebra
- Member
- 543 posts
- Joined: July 2005
- Offline
- edward
- Member
- 7725 posts
- Joined: July 2005
- Offline
- xiondebra
- Member
- 543 posts
- Joined: July 2005
- Offline
- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
I think my brain has frozen, but how do you think we can use evals() to do it?
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- Antoine Durr
- Member
- 321 posts
- Joined: July 2005
- Offline
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
Antoine Durr
How about a simple expression function <snip>
Yep; that's a nice solution Antoine
Still…
It'd be nice to have it as a builtin function instead of having to parse and interpret that every time., no?
I'd let the RFE stand, and… oh, what the heck; how about extending it to the other nasty types?
vector ifv(bool,vector,vector)
matrix ifm(bool,matrix,matrix)
and so on… 8)
Good one Antoine!
- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
Ah yes, didn't think of that myself
For some reason, the expression editor completely bypasses me.
Thanks for the solution, Antoine.. I'd still like to see it be built-in as well though.
(Also a regsub would be nice, anyone?..)
For some reason, the expression editor completely bypasses me.
Thanks for the solution, Antoine.. I'd still like to see it be built-in as well though.
(Also a regsub would be nice, anyone?..)
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- edward
- Member
- 7725 posts
- Joined: July 2005
- Offline
- Antoine Durr
- Member
- 321 posts
- Joined: July 2005
- Offline
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
Antoine Durr
What's regsub()? What parameters would it have?
It's a hypothetical function that would perform pattern substitutions based on regular expression matching -> regsub.
It's a big part of most scripting languages; and a very handy thing indeed 8)
Regular expressions are pretty dense little things… not simple at all…
The Boost [boost.org] library has a full regex implementation (by John Maddock), so….
Anybody with access to the HDK and a few weeks to kill?
Cheers!
- Antoine Durr
- Member
- 321 posts
- Joined: July 2005
- Offline
Mario MarengoAntoine Durr
What's regsub()? What parameters would it have?
It's a hypothetical function that would perform pattern substitutions based on regular expression matching -> regsub.
It's a big part of most scripting languages; and a very handy thing indeed 8)
Regular expressions are pretty dense little things… not simple at all…
Cheers!
Well, how about:
string regsub(string source; string from; string to
{
string perlstr = “”;
perlstr = “echo ” + source + “ | perl -pe s/” + from + “/” + to + “/g”;
return system(perlstr);
}
hscript> echo `regsub(“hello”, “ll”, “foobar”)`
hefoobaro
– Antoine
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
Antoine Durr
Well, how about:
string regsub(string source; string from; string to
{
string perlstr = “”;
perlstr = “echo ” + source + “ | perl -pe s/” + from + “/” + to + “/g”;
return system(perlstr);
}
Yes. That's a nice example, Antoine.
Or you could use awk -> gsub(), or TCL -> regsub(), or … even grep will do in a pinch.
As I mentioned; you'll find it in most (all?) scripting languages, just pick the cross-platform poison of your choice.
But I think he was asking (hoping? ) for a built-in version… though I could be wrong.
It would be quite a bit “snappier” than a system call.
Cheers!
- xiondebra
- Member
- 543 posts
- Joined: July 2005
- Offline
- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
Hi again,
Thanks for the snippet on using PERL for the substitution. Just FYI, I changed it a teeny bit to allow spaces in the parameters (it choked when I was trying to remove spaces)
string regsub(string source; string from; string to
{
string perlstr = “”;
perlstr = “echo ‘” + source + “’ | perl -pe ‘s/” + from + “/” + to + “/g’”;
return system(perlstr);
}
But, yes; to have some of these builtin would be great.
By that matter, what are the thoughts of binding in an established scripting language sometime? Say, having PHP native or something else that allows one to do file i/o, GUI toolkits, register procedures? I realise JavaScript and TCL/Tk can do this, but to have to communicate via hcommand is awkward and slow.
Thanks for the snippet on using PERL for the substitution. Just FYI, I changed it a teeny bit to allow spaces in the parameters (it choked when I was trying to remove spaces)
string regsub(string source; string from; string to
{
string perlstr = “”;
perlstr = “echo ‘” + source + “’ | perl -pe ‘s/” + from + “/” + to + “/g’”;
return system(perlstr);
}
But, yes; to have some of these builtin would be great.
By that matter, what are the thoughts of binding in an established scripting language sometime? Say, having PHP native or something else that allows one to do file i/o, GUI toolkits, register procedures? I realise JavaScript and TCL/Tk can do this, but to have to communicate via hcommand is awkward and slow.
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
Here is another handy thing - this snippet will strip leading numbers, spaces, punctuation (except underbars); ultimately yeilding a name that could be a valid Houdini node name.
# legalize node names
#
string legalize_name(string source)
{
string perlstr = “”;
perlstr = “echo ‘” + source + "’ | perl -pe 's/^[]*|[^^_]//g'";
return system(perlstr);
}
# legalize node names
#
string legalize_name(string source)
{
string perlstr = “”;
perlstr = “echo ‘” + source + "’ | perl -pe 's/^[]*|[^^_]//g'";
return system(perlstr);
}
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
- old_school
- Staff
- 2540 posts
- Joined: July 2005
- Offline
By that matter, what are the thoughts of binding in an established scripting language sometime? Say, having PHP native or something else that allows one to do file i/o, GUI toolkits, register procedures? I realise JavaScript and TCL/Tk can do this, but to have to communicate via hcommand is awkward and slow.
My gut tells me that building up hscript is the best solution of them all. Give it the functionality it needs to do what you want, especially handling of strings, vectors, matricies, and arrays. The overlap between this and VEX will get blurred pretty quickly.
-jeff
There's at least one school like the old school!
- jason_iversen
- Member
- 12474 posts
- Joined: July 2005
- Offline
It'd be beautiful to have hscript become VEX-like with procedures and strong datatyping. Add arrays and File I/O and you're golden. This would also mean the the Expression language could be tossed and expression would be written in this new “VScript”
I'd love to see this too.
RIP, PERL support in Houdini. :? We miss you.
I'd love to see this too.
RIP, PERL support in Houdini. :? We miss you.
Jason Iversen, Technology Supervisor & FX Pipeline/R+D Lead @ Weta FX
also, http://www.odforce.net [www.odforce.net]
also, http://www.odforce.net [www.odforce.net]
-
- Quick Links