How to expand/eval string in VEX?

   3943   8   2
User Avatar
Member
120 posts
Joined: 1月 2012
Offline
Hi,

In Python we have something like hou.expandString() to evaluate string with ie. env variables.
In VEX is kinda works automatically, but not when I use chsraw().

Please taka a look at screenshot.

I would like to get the raw string from parameter, do some string modification, and write it to attribute as an expanded(evaluated) version of string. $JOB should expand to path. I am puzzled why it doesn't.

I saw in some old post that there used to be eval() and evals() functions, but they are no more.

Edited by tas3d - 2021年3月28日 14:00:39

Attachments:
Screenshot 2021-03-28 135447.jpg (48.5 KB)

Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
146 posts
Joined: 9月 2011
Offline
Use chs() rather than chsraw() if you want Houdini to expand aliases. Is there some particular reason you're favouring chsraw()? You can still perform string manipulation shenanigans - this works, for example:
s@myname = chs("my_parm_with_job_alias_in_it") + "/test_folder/test_file.ext";
Edited by howiem - 2021年3月29日 01:57:43
User Avatar
Member
120 posts
Joined: 1月 2012
Offline
Hi,

Here is better explanation of why I use chsraw()

I have this string in paramemter:

$JOB/houdini/geo/GEO_ProcessedSection.$F4.bgeo.sc

I would like to replace '.$F4.' with @primnum.
If I use chs(), then I wont have frame padding pattern, it will be expanded to current frame.
Once I manipulate string, I would like to write it to @path in expanded form.

On the bright side, I got it working in PythonSOP. Just curious what happened to evals() and what is the replacement method.

Thanks!
Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
8007 posts
Joined: 9月 2011
Online
tas3d
Hi,

Here is better explanation of why I use chsraw()

I have this string in paramemter:

$JOB/houdini/geo/GEO_ProcessedSection.$F4.bgeo.sc

I would like to replace '.$F4.' with @primnum.
If I use chs(), then I wont have frame padding pattern, it will be expanded to current frame.
Once I manipulate string, I would like to write it to @path in expanded form.

On the bright side, I got it working in PythonSOP. Just curious what happened to evals() and what is the replacement method.

Thanks!

why not use a different token than "$F4" for the file number? Use a c format string, "%04d", and then use sprintf to format with the frame number.
User Avatar
Member
120 posts
Joined: 1月 2012
Offline
That is a cool solution.

To be even more accurate and still on point with my problem, I actually use '${F}'.
This is what is generated by File - Geometry parameter, so I want to make it easy for users. They just pick the sequence and don't worry about pattern.
Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
8007 posts
Joined: 9月 2011
Online
tas3d
To be even more accurate and still on point with my problem, I actually use '${F}'.
This is what is generated by File - Geometry parameter, so I want to make it easy for users. They just pick the sequence and don't worry about pattern.

Yeah, I can see wanting to allow users to use the file chooser. In that case, you might need to use two path parameters. One exposed to the user, and another with an expression that does the substitution. Then vex only sees the evaluated path with the substituted token.
User Avatar
Member
130 posts
Joined: 6月 2019
Offline
tas3d
Hi,

Here is better explanation of why I use chsraw()

I have this string in paramemter:

$JOB/houdini/geo/GEO_ProcessedSection.$F4.bgeo.sc

I would like to replace '.$F4.' with @primnum.
If I use chs(), then I wont have frame padding pattern, it will be expanded to current frame.
Once I manipulate string, I would like to write it to @path in expanded form.

On the bright side, I got it working in PythonSOP. Just curious what happened to evals() and what is the replacement method.

Thanks!

For this particular case abspath() and relpath() would work.
They expand path variables.
User Avatar
Member
120 posts
Joined: 1月 2012
Offline
Thanks
Unfortunately, not good
Edited by tas3d - 2021年3月30日 13:07:18

Attachments:
Screenshot 2021-03-28 135447.jpg (48.5 KB)

Michal Tas Maciejewski @ www.vfxtricks.com
User Avatar
Member
130 posts
Joined: 6月 2019
Offline
tas3d
Thanks
Unfortunately, not good

yeah, sorry ) I was confused by the fact that literals are already expanded in vex. Looks like there's no runtime evaluation of string (and hscript in general).

Like you can do something like this:
s@path = chsraw("job");
s@path = re_replace(r"\x24JOB", "$JOB", s@path);
but this would be just for $JOB and doesn't seem viable
  • Quick Links