Hey @Dunhou,
our c4d_string.str files use standard ASCII escaping (of unicode). There is the relatively new py-cmd_gui_resources_2024 example which documents this (of particular interest would be unicode_encode_strings.py for you). But when I wrote unicode_encode_strings.py, I think it was a deliberate decision of mine to exclude the so called control characters in ASCII/Unicode (i.e., \x00 to \x1F as Python Unicode escape sequences). Which includes the whitespace characters like \t, \n, \r, etc. So, the script will not encode them for you.
If you take the code example from above and wanted to add a line break in its help string, you cannot use \n in the string, because it would be escaped as \\n in the output, which is not what you want. Instead, you would have to use \x0A (i.e., the value 10 which is the code point for a line break in ASCII). But since this is not Python, but our C++ code which follows the Unicode standard to the letter, we do not use the \x prefix but \u and also pad it to 4 digits, so it would actually be \u000A for a line break.
STRINGTABLE
{
IDS_PLUGIN_NAME "Py - Resource Gui";
IDS_PLUGIN_HELP "Opens a dialog window that is populated\u000a using resource files.";
}
[image: 1777885216433-d48918e5-eca2-4b9d-90f5-36101de3f0bc-image.png]
If you wanted a more generic solution than writing such strings by hand, you would have to update EscapeUnicode in unicode_encode_strings.py to something like this:
def EscapeUnicode(item: str) -> str:
"""Escapes both non-ASCII and control characters in a string to their unicode code point representation,
e.g., \u000A for a line break.
"""
return re.sub(r"([^\x00-\x7f]|\x00-\x1F)",
lambda m: "\\u{:04x}".format(ord(m.group(1))), item
)
You could also just escape everything, but that would make the strings less readable in the resource files. I am personally also not sure it is a good idea to allow users putting control characters into strings, primarily due to whitespace. I would for example say that it is not wanted that strings in general and tooltips in particular contain line breaks, and that it is up to Cinema 4D to handle wrapping strings. When I look at our Move tool, I see no line breaks in the help string? The help string is just 'Move Tool', the other things (the name and the shortcut) are added by Cinema 4D dynamically (and therefore put onto a new line).
[image: 1777885575797-2d99ee72-e853-415c-a4a6-448796c526b7-image.png]
Cheers,
Ferdinand