Rename Layers with Python containing Emoji?
-
import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def create_and_rename_layer(doc, layer_name): new_layer = c4d.documents.LayerObject() new_layer.SetName(layer_name) root_layer = doc.GetLayerObjectRoot() new_layer.InsertUnderLast(root_layer) c4d.EventAdd() return new_layer def main() -> None: layer_1_string = "Layer 1: \N{grinning face with smiling eyes}" print(layer_1_string) layer_1 = create_and_rename_layer(doc, layer_1_string) layer_2_string = "Layer 2: \U0001F600" print(layer_2_string) layer_2 = create_and_rename_layer(doc, layer_2_string) layer_3_string = "Layer 3: 🤣" print(layer_3_string) layer_3 = create_and_rename_layer(doc, layer_3_string) if __name__ == '__main__': main()
I've the code above, with which I try to create and rename layers, so they contain lovely Emoji. Though when I execute the code, I see the Emoji in the Console, but the layers refuse to rename accordingly.
When I edit a layer by hand, I can input Emoji with no issues:
-
The same is true, trying to rename objects in the OM: It works manually, but not via script. Is it an encoding issue?
-
Hello @gaschka,
Thank you for reaching out to us. Yes, this is an encoding issue. In general, Unicode is supported by the Python to C++ bindings, as you can see, French, German, and Turkish diacritics are all correctly transported, as well as Chinese characters.
But all these are part of the Basic Multilingual Plane (BMP) while the emojis are part of the Supplementary Multilingual Plane (SMP) of the Unicode table. It could either be that there is something not implemented or some bits get chopped off while data is sent to the C++ layer. I don't really know, the person who is responsible for the Python bindings, @m_adam, is on vacation. I will ask him once he is back, as I too would be guessing what is happening here exactly.
Cheers,
Ferdinand