<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[RemoveUserData does not fully remove User Data]]></title><description><![CDATA[<p dir="auto">If I add a string field with AddUserData.<br />
And then I delete that string field with DeleteUserData.<br />
And then try to add a float field with AddUser Data:<br />
I get<br />
TypeError: <strong>setitem</strong> expected str, not float<br />
And if I try to get the value before EventAdd, I get the old, deleted value</p>
<p dir="auto">Anyone know any workarounds? Like how to flush the memory of the user data?</p>
]]></description><link>http://developers.maxon.net/forum/topic/10984/removeuserdata-does-not-fully-remove-user-data</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 14:43:12 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/10984.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Sep 2018 23:58:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to RemoveUserData does not fully remove User Data on Mon, 10 Sep 2018 14:07:29 GMT]]></title><description><![CDATA[<p dir="auto">This worked. Thank you.</p>
]]></description><link>http://developers.maxon.net/forum/post/55637</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/55637</guid><dc:creator><![CDATA[dmp]]></dc:creator><pubDate>Mon, 10 Sep 2018 14:07:29 GMT</pubDate></item><item><title><![CDATA[Reply to RemoveUserData does not fully remove User Data on Mon, 10 Sep 2018 09:59:33 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Even if a user data parameter is removed its data is still stored. And when [] operator is used, the Python API layer checks the type of a parameter before setting its data.<br />
The solution is to use <code>del()</code> passing the parameter data to clear its type and value. Then the parameter can be set any data.</p>
<p dir="auto">Here is how I modified the script you posted:</p>
<pre><code>import c4d

def AddUserData(obj, dtype, name):
    if obj is None: return

    # Retrieves default user data container for the passed type
    bc = c4d.GetCustomDataTypeDefault(dtype)
    bc[c4d.DESC_NAME] = name

    # Adds the user data
    element = obj.AddUserData(bc)

    # Returns the user data description ID
    return element

def main():
    # Searches for 'Cube' object
    cube = doc.SearchObject('Cube')
    if cube is None:
        return

    # Adds string user data
    dataID = AddUserData(cube, c4d.DTYPE_STRING, "String")
    cube[dataID] = 'bob'

    # Removes user data
    cube.RemoveUserData(dataID)
    # Clears user data type and value
    del(cube[dataID])

    # Adds float user data
    dataID = AddUserData(cube, c4d.DTYPE_REAL, "Float")
    cube[dataID] = 22.2

    # Updates Cinema
    c4d.EventAdd()

if __name__=='__main__':
    main()
</code></pre>
<p dir="auto">Note it's recommended to use <em>main()</em> like in the default script. Also when Cinema 4D runs scripts <em>doc</em> is the active document (<em>op</em> is the active object).</p>
]]></description><link>http://developers.maxon.net/forum/post/55631</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/55631</guid><dc:creator><![CDATA[y_puech]]></dc:creator><pubDate>Mon, 10 Sep 2018 09:59:33 GMT</pubDate></item><item><title><![CDATA[Reply to RemoveUserData does not fully remove User Data on Sun, 09 Sep 2018 00:18:48 GMT]]></title><description><![CDATA[<p dir="auto">Here's a simple test to run in the script editor:<br />
Add a Cube to the scene.</p>
<pre><code>import c4d
current_doc = c4d.documents.GetActiveDocument()  
cube = current_doc.SearchObject('Cube')

def AddStringDataType(obj):
  if obj is None: return

  bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_STRING) 
  bc[c4d.DESC_NAME] = "String"           

  element = obj.AddUserData(bc)  
  obj[element] = 'bob'       
  c4d.EventAdd()             
  
def AddFloatDataType(obj):
  if obj is None: return
  bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL)
  bc[c4d.DESC_NAME] = "Float"
  element = obj.AddUserData(bc)
  obj[element] = 22.2
  c4d.EventAdd()
  
AddStringDataType(cube)
cube.RemoveUserData(1)
AddFloatDataType(cube)
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/55621</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/55621</guid><dc:creator><![CDATA[dmp]]></dc:creator><pubDate>Sun, 09 Sep 2018 00:18:48 GMT</pubDate></item></channel></rss>