Loading text file via User Data input into Python

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.

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

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!

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