Update User Data during loop

On 01/10/2013 at 02:38, xxxxxxxx wrote:

Hello everybody. Below I have a very simplified version of what I'm trying to create.

The simplified code:
Runs a loop to get all of the user data and prints it to the console
Creates a new user data object (just lifted that straight from the documentation)
Runs the same loop again and print to the console again.

The results in the console are identical and I have to run the script again to be able to access the new userdata.

Import c4d

def main() :
  obj = doc.SearchObject("Null")

ud = obj.GetUserDataContainer()
  for id, bc in ud:
      print id, bc[1]   # The readout on console shows Test data 1 and Test data 2
  bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) # Create default container
  bc[c4d.DESC_NAME] = "Test data 3"                        # Rename the entry

element = obj.AddUserData(bc)     # Add userdata container
  obj[element] = 0                # Assign a value
  c4d.EventAdd()                    # Update

for id, bc in ud:
      print id, bc[1] #The readout on console shows Test data 1 and Test data 2 but no sign of Test data 3
if __name__=='__main__':

I know I can set all of the parameters before I create the userdata, however what I intend to do is create a group and then clone some userdata and nest it in the group without having to run the script twice.

My question is: Can I access newly created/cloned userdata within a single execution of a script?

Any help is much appreciated.



On 01/10/2013 at 08:09, xxxxxxxx wrote:

scripts are single threaded / executed from the c4d main thread. the general approach you would
take on this would be a python tag. the python tag code single threaded too, but it allows you to
use some fallthrough construct to split your task into two passes.

if data not in userdata:
elif condition is met:
edit: lol, I just realized that I have hit the posting count sweet spot for my nick ;)

On 01/10/2013 at 08:25, xxxxxxxx wrote:

UserData works the same way as other objects.
If you change it in some manner. You have to grab it again after the changes were made to get it's current values.

import c4d  
def main() :  
  obj = doc.SearchObject("Null")  
  #The master UD container  
  ud = obj.GetUserDataContainer()  
  #Print the current UD entries in the master container    
  for id, bc in ud:  
      print id, bc[1]  
  bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG)  
  bc[c4d.DESC_NAME] = "Test data 2"  
  element = obj.AddUserData(bc)     #Add this new userdata to the master UD container  
  obj[element] = 10                 #Assign a value to it  
  #We've changed the master UD container above  
  #So we have to grab it again to get the current stuff in it  
  ud = obj.GetUserDataContainer()  
  for id, bc in ud:  
      print id, bc[1]  
if __name__=='__main__':  


On 01/10/2013 at 08:36, xxxxxxxx wrote:

@littledevil Ha, Demonic post! - I'm privileged. I'm actually using a Python Node for this bit and created a sloppy workaround which involved an Iterator Node to trigger the Python twice.

@ScottA That's what I was looking for! Thank you. I feel like bashing my head off the desk for missing that. Solved!