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
    • Recent
    • Tags
    • Users
    • Login

    Path with french letters [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 702 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

      On 19/01/2015 at 14:29, xxxxxxxx wrote:

      Hey

      Thanks for all the support -

      i have a bug in my plugin — reported from a french user

      i try to write a file to a path but with  a special letter in his username - I get an error with that path

      Sébastian = c:\users\sÇbastien\

      how can I prevent it?

      path = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_PREFS)
      path = os.path.join(path, "StagePlugin/")
      path = os.path.normpath(path)
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 19/01/2015 at 17:00, xxxxxxxx wrote:

        Hi conner,

        I had to edit the message because I got some advice to give an answer that covers all of C4D / Python's UTF-8 character set.

        This exact problem is why I don't spell my last name with the "é" inside most software ("Gaspé"), as the computer world is several years away from fully supporting Unicode, let alone IBM PC extended ASCII, and some try but get it all mixed up across the different encodings.  It's one of those 'weakest link' issues.

        I managed to reproduce the problem and found what should be the solution in this case.  C4D supports UTF-8, and Python's str type can be encoded in UTF-8 also.

        I had to add to the path the "é" as u"\u00E9" to simulate it coming out of the path preferences call, even if the call results in 'range compliant' symbols.  The code you provided will display it corrupted with the two symbols you report.  By adding "path.decode("utf-8")" it will display it as it should, the e-acute ("e accent aigu" in French).  I'm spelling it out explicitly for anyone who might be seeing the é symbol as garbage in their particular browser, however unlikely.

        Here's the code itself:

          
        import c4d  
        import os  
          
        def main() :  
            
          path = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_PREFS)  
          path = path.decode("utf-8") + u"\u00E9"  
          path = os.path.join(path, "StagePlugin/")  
          path = os.path.normpath(path)  
          
          print path  
                    
          return  
        

        This link shows you another example in the Python documentation.[URL-REMOVED]

        This link explains the encoding / decoding issue specifically.

        I hope that helps solve the problem!

        Joey Gaspe
        SDK Support Engineer


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

          On 26/01/2015 at 10:34, xxxxxxxx wrote:

          Hi conner,

          I'd like to know if my reply helped you?  I'm curious because I can't repro exactly the issue, only simulate it, so a response would put to rest any doubts we have on the C4D side that everything is OK.

          Thanks!

          Joey Gaspe
          SDK Support Engineer

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

            On 26/01/2015 at 15:17, xxxxxxxx wrote:

            I try to add the code but get an error

            ==========================

            Traceback (most recent call last) :
              File "'stage.pyp'", line 13358, in <module>
              File "'stage.pyp'", line 1238, in Strukturcheck
              File "'stage.pyp'", line 1120, in readPreferences
            TypeError: argument 2 must be str or c4d.storage.MemoryFileStruct, not unicode

            line 1120 -         if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_READ, error_dialog=c4d.FILEDIALOG_ANY) :

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

              On 26/01/2015 at 15:40, xxxxxxxx wrote:

              You should encode the path in UTF-8.

              path = path.encode('utf-8')
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 27/01/2015 at 07:47, xxxxxxxx wrote:

                Hi conner,

                Thanks for trying it.  I can speculate that what NiklasR is proposing might work (changing from 'decode' to 'encode'), since you're getting the accent from GeGetC4DPath(), not the script itself, which is as close as we could get to reproduce the issue quickly (while adding the accent with  + u"\u00E9").  Either way, please let us know if either works, or if you're still stuck.  If you're still stuck, please include the exact code and errors you get, as their variance may give us clues.

                Thanks,

                Joey Gaspe
                SDK Support Engineer

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

                  On 02/02/2015 at 12:37, xxxxxxxx wrote:

                  Due to several days of inactivity, and the feeling that the proposed fix should work, I'll close this topic as solved.

                  Joey Gaspe
                  SDK Support Engineer

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