Jump to content

[SOLVED]VEX Concat File Path and File Name?


Atom

Recommended Posts

Hi All,

 

I am trying to construct an attribute that is a filename. However, as with many languages there is a problem with BACK\SLASHES in a string. I have tried double slashing to resolve the issue but it seems to have no effect. I always get a mangled string as my filename when I review it in the Geometry Spreadsheet.

 

How do define a file path string in VEX so I can properly store it as an attribute in the spreadsheet?

s@element_name = "";
string full_path = "";
string path_to_maps ="C:\\Users\\Developer\\Documents\\Maps\\cc0_Lens Flare Rig Elements";
string element_names[] = {"Star3.png","Star4.png","Star5.png"};
for(int i=0; i< @numpt; i++) {
    //full_path = sprintf("%s%s", path_to_maps,element_names[i]);
    full_path = concat(path_to_maps,element_names[i]);
    setpointattrib(geoself(), "element_name", i, full_path, "set");
    full_path = "";
}

post-12295-0-80035700-1446915587_thumb.j

Edited by Atom
Link to comment
Share on other sites

Your escape sequences are valid in .vfl or other normal VEX sources. Code field is a string parameter being expanded as normal expression. It also seems that for Snippet and Wrangle nodes it expanded twice (using HScript rules), with additional expansion between evaluated code field and VEX code generation. So, in Point Wrangle you need to use eight backslashes to get your escape sequence correct in generated VEX code: \\\\\\\\ > \\\\ > \\. To get two resulting backslashes in string you need to use sixteen \\\\\\\\\\\\\\\\ > \\\\\\\\ > \\\\. You can use lesser, actually 5 and 13, because leading \\\ in HScript expanding into \\ and, again, doing it twice for Snippet and Wrangle: \\\\\ > \\\ > \\ and \\\\\\\\\\\\\ > \\\\\\\ > \\\\. But I suggest to use "scalable" tactic. Inline VOP correctly expands it's string once, so, use four to get one and eight to get two. And SESI may fix it someday for Wrangle and Snippet also.

 

In docs for Python's Regexes it is called Backslash Plague, and solution is using raw strings. VEX's Regexes was introduced in H14 as well as python-style raw strings syntax. In theory, you can use raw strings, but it still working correct only inside direct VEX source. With an interesting exception for single backslash, you still need to flood backslashes in code fields.

# Original parameter:
 "test\\\\\\\\test"
 "test\\\\\\\\\\\\\\\\test"
r"test\test"
r"test\\\\\\\\test"

# Expanded parameter:
 "test\\\\test"
 "test\\\\\\\\test"
r"test\test"
r"test\\\\test"

# Generated VEX Code:
 "test\\test"
 "test\\\\test"
r"test\test"
r"test\\test"

# Resulting string:
test\test
test\\test
test\test
test\\test
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...