Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Rename Layers with Python containing Emoji?

    Cinema 4D SDK
    2024 python windows
    2
    3
    581
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gaschkaG
      gaschka
      last edited by gaschka

      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.

      Cinema_4D  2024-03-03 um 15.34.56.png Cinema_4D  2024-03-03 um 15.35.00.png

      When I edit a layer by hand, I can input Emoji with no issues:

      60812c8a-6f62-490d-b6f7-036e7d839f1c-image.png

      1 Reply Last reply Reply Quote 0
      • gaschkaG
        gaschka
        last edited by

        The same is true, trying to rename objects in the OM: It works manually, but not via script. Is it an encoding issue?

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @gaschka
          last edited by

          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.

          5bfdbc74-f638-4fd8-8df9-2b95479b233b-image.png

          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

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • First post
            Last post