String Errors: "Unable to evaluate" because of backticks {[SOLVED]}

   696   4   0
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Hi!

I'm using a Detail Wrangle to generate a Mel script to be used in Maya. There's one line that Houdini hates. It's this:

$createSetResult = `sets -name "column"`;
(the Mel script I'm trying to create)

I had three problems:
- quotes(")
- dollar symbol($)
- backticks(`)

For the quotes("), I can simply use a chs("quote_symbol") so I cant place a quote in that channel instead of writting it directly in the script. For the dollar symbol($), same thing but I change the Expression Language to Python instead of Hscript (icon top right).

The backtick(`) is my biggest probleme. I can't use it directly in the script and I cant use it in a chs() (python or Hscript). What option do I have?

-Olivier
Edited by olivierth - Nov. 24, 2023 13:59:27
User Avatar
Member
2537 posts
Joined: June 2008
Offline
Can't you use sprintf() to achieve the formatting you're looking for?

s@result = sprintf('\$createSetResult = \`sets -name "column"\`;');
Edited by Enivob - Nov. 24, 2023 12:32:06

Attachments:
Untitled-1.jpg (32.7 KB)

Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
201 posts
Joined: Jan. 2013
Offline
Another common way of not thinking about where to put slashes for proper escaping is to simply say that our entire string is raw.

s@result = sprintf(r'$createSetResult = `sets -name "column"`;');
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Super, this works!

I just never used any print functions before. I'm not 100% sure of what it does.

Thanks.

-Olivier
User Avatar
Member
2537 posts
Joined: June 2008
Offline
That's cool, Alex. I knew about raw strings in python. I didn't realize you could leverage them inside VEX as well.

I believe sprintf() is an implementation of the printf() function found in the C language. There are a lot of additional modifiers you can add to format number and letters inside a string.
https://www.geeksforgeeks.org/printf-in-c/ [www.geeksforgeeks.org]
Edited by Enivob - Nov. 24, 2023 16:12:36
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
  • Quick Links