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

    Loading text file via User Data input into Python

    PYTHON Development
    0
    4
    413
    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
      Helper
      last edited by

      On 17/09/2014 at 11:57, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   15 
      Platform:      Mac OSX  ; 
      Language(s) :       PYTHON  ;

      ---------
      Hello,

      I have been gifted a fully functioning Python script from a colleague that turns text data into .OBJ files. The issue I'm having is that ideally I could load my external files into this script using User Data I attach to a Null. The script works perfectly if I hard code the file path like this...

      inpName = '/Users/winnebango/Desktop/DataFile.dynain'

      If I do this...

      inpName = '[c4d.ID_USERDATA,1]'

      Nothing works and it tells me that file does not exist.

      I've been searching for 2 days how to get the file directory info from this User Data and just cannot seem to find anything. Is there a way to get the file path from the User Data and store it into a string that can be assigned to a variable?  I've been out of coding practice for almost 10 years so I know I'm just missing a couple key things, but I don't know what those are. Any help is greatly appreciated. Thank you.

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

        On 17/09/2014 at 13:01, xxxxxxxx wrote:

        You don't say what kind of UD gizmo you're using
        Here's an example of getting the text from a Filename type UD gizmo

        import c4d  
        def main() :  
           
          #The UserData gizmo is a Filename type gizmo  
          ud = op[c4d.ID_USERDATA, 1]  
            
          #Check if the ud is empty  
          #Only grabs the text from the UserData gizmo if it's not empty  
          if len(ud) > 0:   
              print ud  
            
          c4d.EventAdd()  
          
        if __name__=='__main__':  
          main()
        

        -ScottA

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

          On 17/09/2014 at 13:57, xxxxxxxx wrote:

          I honestly can't thank you enough. I was seriously only missing the 'op' part of the syntax. Once I got your script pasted into mine I was able to start implementing it accordingly and now my stuff works. I was even able to add in a gui message telling me that my file was saved! You really honestly made my day and I hope someone does the same for you!

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

            On 17/09/2014 at 14:04, xxxxxxxx wrote:

            Lol. You're welcome.
            Many people have helped me. many, many, many, people.
            It literally took a "village" to get me where I'm at now with the C4D sdk's.

            I'm currently messing around in the Mudbox SDK right now. And I'm feeling very newbish all over again.
            So I know how frustrating it feels.

            -ScottA

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