Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Unicode characters

    Scheduled Pinned Locked Moved PYTHON Development
    12 Posts 0 Posters 852 Views
    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.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 19/11/2012 at 09:24, xxxxxxxx wrote:

      In Python, you just need to put 'u' before the string literal: u"\u00C5land (Finland)". Strings in CINEMA fully use Unicode characters.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 19/11/2012 at 10:39, xxxxxxxx wrote:

        Thanks.
        As always a clear and fast answer!

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 20/11/2012 at 04:24, xxxxxxxx wrote:

          Sorry, not yet completely clear.

          The following works:
          self.AddChild(MY_1SELCONTINENT, CUSTOM, u"\u00C5land (Finland)")

          This works too:
          finland = u"\u00C5land (Finland)"
          self.AddChild(MY_1SELCONTINENT, CUSTOM, finland)

          This, of course, does not work:
          self.AddChild(MY_1SELCONTINENT, CUSTOM, ufinland)

          What I want.
          I read in all variables, for example finland = "\u00C5land (Finland)"
          How to display this in my GUI?

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 20/11/2012 at 05:51, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            This, of course, does not work:
            self.AddChild(MY_1SELCONTINENT, CUSTOM, ufinland)

            How do you read ufinland  string variable? I think you could use unicode() Python built-in function.

            EDIT: Ok, I see you have finland but adding 'u' before doesn't do anything because it only works with string literals. ufinland is a new variable. So you should call unicode(finland) instead.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 20/11/2012 at 08:34, xxxxxxxx wrote:

              Sorry, that does not work.
                    finland = "\u00C5land (Finland)"
                    self.AddChild(MY_1SELCONTINENT, CUSTOM, unicode(finland))

              It display in the field: \u00C5land (Finland)

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 20/11/2012 at 10:00, xxxxxxxx wrote:

                Do you read Unicode strings from a file? You should then decode them to utf-8:

                input = open('unicode.txt')
                finland = input.read()
                print finland.decode('utf8')
                
                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 20/11/2012 at 13:27, xxxxxxxx wrote:

                  I tried following script, but it does not work it still displays:"\u00C5land (Finland)" and not the first unicode character.

                  coding: UTF-8

                  import c4d
                  from c4d import gui

                  unicode.txt contains one line:

                  "\u00C5land (Finland)"

                  def main() :
                        input = open('unicode.txt')
                        finland = input.read()
                        print "finland utf8: ", finland.decode('utf8')
                        gui.MessageDialog(finland)

                  if __name__=='__main__':
                    main()

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 21/11/2012 at 00:17, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    I tried following script, but it does not work it still displays:"\u00C5land (Finland)" and not the first unicode character.

                    unicode.txt contains one line:

                    "\u00C5land (Finland)"

                    This is because the unicode file should contain "Ã…land (Finland)", not "\u00C5land (Finland)".
                    Here's the code I used:

                    # coding: UTF-8
                    # If you specify UTF-8 encoding, you then don't need to replace Ã… by \u00C5 in your code
                    # See string literal below
                      
                    import c4d
                    from c4d import gui
                      
                      
                    def WriteUnicode() :
                        utf8_string = u"Ã…land (Finland)".encode('utf8')
                        output = open('unicode.txt', 'w')
                        output.write(utf8_string)
                        output.close()
                      
                    def ReadUnicode() :
                        input = open('unicode.txt')
                        utf8_string = input.read()
                        print utf8_string.decode('utf8')
                      
                      
                    def main() :
                        WriteUnicode()
                        ReadUnicode()
                      
                      
                    if __name__=='__main__':
                        main()
                    
                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 21/11/2012 at 02:08, xxxxxxxx wrote:

                      Ok, clear.
                      However, the input I read from the files uses "\u00C5land (Finland)"
                      I use the Cinema 4d file \CINEMA 4D R13\modules\advanced render\sky\res\cities.csv
                      So, how to read that file and display it properly?

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 21/11/2012 at 04:35, xxxxxxxx wrote:

                        Originally posted by xxxxxxxx

                        Ok, clear.
                        However, the input I read from the files uses "\u00C5land (Finland)"
                        I use the Cinema 4d file \CINEMA 4D R13\modules\advanced render\sky\res\cities.csv
                        So, how to read that file and display it properly?

                        Ok, I finally found the solution 🙂.
                        We have to decode the string with  unicode_escape codec to produce a string that is suitable as raw Unicode literal in Python source code (u'' does this directly with literals).
                        Here's the code:

                        finland = "\u00C5land (Finland)"
                        print finland # Stored as '\\u00C5land' (double escape)
                        print finland.decode('unicode_escape')
                        

                        And this code is the same than:

                        finland = u"\u00C5land (Finland)"
                        print finland
                        
                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 21/11/2012 at 07:26, xxxxxxxx wrote:

                          Thank you very much.
                          Appreciate the patience and willing to solve it.

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