<?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[Add&#x2F;Remove Groups of User Data]]></title><description><![CDATA[<p dir="auto">I've set up a user data interface, and would like to be able to click the add/remove buttons at the top, which would create additional tracks. Is this possible, or would one need to resort to C++ for this kind of behavior?<br />
<img src="https://developers.maxon.net/forum/assets/uploads/files/1554402836474-user-data.png" alt="user data.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">For clarification, I am trying to do the Add/Remove behavior similar to how Constraint tags work:<br />
<img src="https://developers.maxon.net/forum/assets/uploads/files/1554403043209-constraint.png" alt="constraint.png" class=" img-fluid img-markdown" /></p>
]]></description><link>http://developers.maxon.net/forum/topic/11469/add-remove-groups-of-user-data</link><generator>RSS for Node</generator><lastBuildDate>Thu, 19 Nov 2026 00:59:53 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/11469.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 04 Apr 2019 18:39:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Wed, 21 Aug 2019 13:17:15 GMT]]></title><description><![CDATA[<p dir="auto">@m_magalhaes said in <a href="https://developers.maxon.net/forum/post/59042" target="_blank" rel="noopener noreferrer nofollow ugc">Add/Remove Groups of User Data</a>:</p>
<blockquote>
<p dir="auto">Hello,</p>
<p dir="auto">I was also talking about something like this. But it's not the best way to go. I suggest a TagData (plugin) with his own UI.</p>
<pre><code>pyTagCode = '\
import c4d \n\
#Welcome to the world of Python \n\
\n\
def main():\n\
    print "this ia a message"\n\
\n\
'



import c4d

# Main function
def main():
    if op is None:
        gui.MessageDialog("Please selecte a target object")
    tag = c4d.BaseTag(c4d.Tpython)
    tag[c4d.TPYTHON_CODE] = pyTagCode
    op.InsertTag(tag)
    c4d.EventAdd()   

# Execute main()
if __name__=='__main__':
    main()
</code></pre>
<p dir="auto">By the way, don't forget you can save tag presets, that include python tags. You can simple add them with right click on your object in OM and "Load tag preset"</p>
<p dir="auto">Cheers,<br />
Manuel</p>
</blockquote>
<p dir="auto">Oh this is good to know! Thanks so much for the information, this is quite helpful!</p>
<p dir="auto">Matt</p>
]]></description><link>http://developers.maxon.net/forum/post/59078</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59078</guid><dc:creator><![CDATA[mrittman]]></dc:creator><pubDate>Wed, 21 Aug 2019 13:17:15 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Sun, 18 Aug 2019 08:58:44 GMT]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I was also talking about something like this. But it's not the best way to go. I suggest a TagData (plugin) with his own UI.</p>
<pre><code>pyTagCode = '\
import c4d \n\
#Welcome to the world of Python \n\
\n\
def main():\n\
    print "this ia a message"\n\
\n\
'



import c4d

# Main function
def main():
    if op is None:
        gui.MessageDialog("Please selecte a target object")
    tag = c4d.BaseTag(c4d.Tpython)
    tag[c4d.TPYTHON_CODE] = pyTagCode
    op.InsertTag(tag)
    c4d.EventAdd()   

# Execute main()
if __name__=='__main__':
    main()
</code></pre>
<p dir="auto">By the way, don't forget you can save tag presets, that include python tags. You can simple add them with right click on your object in OM and "Load tag preset"</p>
<p dir="auto">Cheers,<br />
Manuel</p>
]]></description><link>http://developers.maxon.net/forum/post/59042</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59042</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Sun, 18 Aug 2019 08:58:44 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Sat, 17 Aug 2019 15:12:59 GMT]]></title><description><![CDATA[<p dir="auto">@zipit Thanks so much man, this is really quite helpful! I sure appreciate all the help!</p>
]]></description><link>http://developers.maxon.net/forum/post/59038</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59038</guid><dc:creator><![CDATA[mrittman]]></dc:creator><pubDate>Sat, 17 Aug 2019 15:12:59 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Sat, 17 Aug 2019 08:35:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mrittman">@<bdi>mrittman</bdi></a> said in <a href="https://developers.maxon.net/forum/post/59033" target="_blank" rel="noopener noreferrer nofollow ugc">Add/Remove Groups of User Data</a>:</p>
<blockquote>
<p dir="auto">@m_magalhaes I see, but how do you create a script that generates a python tag with that code already in it?</p>
</blockquote>
<p dir="auto">I think @m_magalhaes  was referring to <code>plugins.TagData</code> the base class for python plugins that implement a tag. This is different from the Python Scripting Tag as it appears in the C4D desktop application. For your question: Yes it possible, but I am not sure if things are what you expect them to be. Building dynamic interfaces is always quite a hassle and Cinema4D is certainty no exception to that rule.</p>
<p dir="auto">The first bit of information is that the Python Scripting Tag also supports implementing a <code>message</code> function which will allow you to listen for button clicks. The second piece would be that <code>c4d.BaseList2D</code> implements methods for adding and removing user data. Here is a short snippet which shows how to manipulate user data sitting on a Python Scripting Tag with that tags python code:</p>
<pre><code>import c4d
#Welcome to the world of Python


def main():
    pass  #put in your code here

def message(mid, data):
    """
    """
    # Check if the message data contain a UserData event
    if isinstance(data, dict) and "id" in data:
        if data["id"][0].id == c4d.ID_USERDATA:

            # Here you have to check for the ID of the Add/Remove button IDs as they appear in
            # your user data editor. For me it was the IDs 1(Add) and 2(Remove).

            # Add button adds a UserData element to the tag. Code as in SDK example code of
            # BaseList2D.AddUserData().
            if data["id"][1].id == 1:
                bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) # Create default container
                bc[c4d.DESC_NAME] = "Test"                        # Rename the entry
                element = op.AddUserData(bc)                      # Add userdata container
                op[element] = 30                                  # Assign a value
                c4d.EventAdd()                                    # Update

            # Remove button removes the last element of your user data. For details see
            # BaseList2D.RemoveUserData() int the SDK.
            elif data["id"][1].id == 2:
                _desc_id_last_item = op.GetUserDataContainer()[-1][0]
                op.RemoveUserData(_desc_id_last_item)
                c4d.EventAdd()
</code></pre>
<p dir="auto">Cheers,<br />
zipit</p>
]]></description><link>http://developers.maxon.net/forum/post/59034</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59034</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Sat, 17 Aug 2019 08:35:42 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Fri, 16 Aug 2019 21:58:24 GMT]]></title><description><![CDATA[<p dir="auto">@m_magalhaes I see, but how do you create a script that generates a python tag with that code already in it?</p>
]]></description><link>http://developers.maxon.net/forum/post/59033</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59033</guid><dc:creator><![CDATA[mrittman]]></dc:creator><pubDate>Fri, 16 Aug 2019 21:58:24 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Fri, 16 Aug 2019 16:39:35 GMT]]></title><description><![CDATA[<p dir="auto">hello,</p>
<p dir="auto">you can surely create a script that will put in place the user data and the python tag (+ his code)</p>
<p dir="auto">But it's likely what a plugin <a href="https://developers.maxon.net/docs/cpp/2023_2/class_tag_data.html" target="_blank" rel="noopener noreferrer nofollow ugc">tagData</a> could do also.</p>
<p dir="auto">So you could just attach a tag to an object.</p>
]]></description><link>http://developers.maxon.net/forum/post/59032</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59032</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Fri, 16 Aug 2019 16:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Fri, 16 Aug 2019 14:36:06 GMT]]></title><description><![CDATA[<p dir="auto">@m_magalhaes Hey man I'm so sorry I didn't see your reply! This was extremely helpful! Pretty much exactly what I was looking for.</p>
<p dir="auto">Do you know if this can be converted to a Python script so that I can drop it into any project?</p>
]]></description><link>http://developers.maxon.net/forum/post/59031</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/59031</guid><dc:creator><![CDATA[mrittman]]></dc:creator><pubDate>Fri, 16 Aug 2019 14:36:06 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Tue, 07 May 2019 09:11:55 GMT]]></title><description><![CDATA[<p dir="auto">hello,</p>
<p dir="auto">if you don't have anything else to add, i'll mark this topic as "solved"</p>
<p dir="auto">Cheers<br />
Manuel</p>
]]></description><link>http://developers.maxon.net/forum/post/58209</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/58209</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Tue, 07 May 2019 09:11:55 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Mon, 08 Apr 2019 09:11:05 GMT]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">After some research in the forum, i've found <a href="https://developers.maxon.net/forum/topic/8461/11042_python-tag-catch-button-presson-parent-object/5" target="_blank" rel="noopener noreferrer nofollow ugc">this post</a> that show how to react to a button pressed.</p>
<p dir="auto">With that, it juste a matter of using <a href="https://developers.maxon.net/docs/py/2023_2/modules/c4d/C4DAtom/GeListNode/BaseList2D/index.html?highlight=adduserdata#BaseList2D.AddUserData" target="_blank" rel="noopener noreferrer nofollow ugc">AddUserData</a>  and his friend <a href="https://developers.maxon.net/docs/py/2023_2/modules/c4d/C4DAtom/GeListNode/BaseList2D/index.html?highlight=removeuserdata#BaseList2D.RemoveUserData" target="_blank" rel="noopener noreferrer nofollow ugc">RemoveUserData</a></p>
<p dir="auto">Let me try to explain a bit more what i've done.<br />
In the UserData tab, i've a got a group that will be used as a container, so i can add or remove thing inside without touching other userdata. I just browse through all user data using <a href="https://developers.maxon.net/docs/py/2023_2/modules/c4d/C4DAtom/GeListNode/BaseList2D/index.html?highlight=getuserdatacontainer#BaseList2D.GetUserDataContainer" target="_blank" rel="noopener noreferrer nofollow ugc">GetUserDataContainer</a> and check the parent of the fields with <a href="https://developers.maxon.net/docs/py/2023_2/consts/DESC.html?highlight=desc" target="_blank" rel="noopener noreferrer nofollow ugc">DESC_PARENTGROUP</a></p>
<p dir="auto">I'm pretty sure you will go through this code easily but if you got any questions, feel free to ask.</p>
<p dir="auto">i'm adding the file so you can play with the code directly<br />
<a href="https://developers.maxon.net/forum/assets/uploads/files/1554714433927-pc-11469.c4d" target="_blank" rel="noopener noreferrer nofollow ugc">AddRemoveGroup.c4d</a></p>
<p dir="auto">And the code. At the top, i've got the ID of both button and the group that will serve as a container.</p>
<pre><code>import c4d


# the group id where all the fiels will be created.
addButtonID = 1
removeButtonID = 2
mainGroupID  = 3



def AddGroupOfUserData():
    """
    Creating the group with differents field.
    Called by button Add
    """
    obj = op.GetObject() # get the object where we want the user data
    parentGroup = obj.GetUserDataContainer()[mainGroupID][0]
    newGroup = CreateGroup(parentGroup)

    nameString = AddString(newGroup, "Name")
    check = AddBool (newGroup, "Use Sound")
    timeField = AddTime(newGroup, "StartTime")
    AddSoundPath(newGroup, "Sound")
    
    #as function are returning the id of the userdata we can change their value
    obj[nameString] = "Default value for the string"
    #Set the bool to tru by default
    obj[check] = True
    #set the time to 0 
    obj[timeField] = c4d.BaseTime(0)

def RemoveGroupOfUserData():
    """
    this will iterate trough all group and remove the last one
    including his children
    """
    obj = op.GetObject() # get the object where we want the user data
    lastGroupID, count = GetLastGroupID()


    if lastGroupID &gt; -1:
        # we find a group so let remove all the child of that group we found
        for descID, bc in op.GetObject().GetUserDataContainer():

            if IsChildOfGroup(bc, lastGroupID):
               obj.RemoveUserData(descID)
               del(obj[descID]) #remove the information in the basecontainer

        obj.RemoveUserData(lastGroupID)
        del(obj[lastGroupID])
        obj.Message(c4d.MSG_UPDATE)


def IsChildOfGroup(bc, groupID = mainGroupID):
    """
    Check if the parent is the same id of groupID
    """
    if bc[c4d.DESC_PARENTGROUP].GetDepth() &gt; 1:
        if bc[c4d.DESC_PARENTGROUP][1].id == groupID:
            return True
    return False


def GetLastGroupID(parent = None):
    """
    get the last group in the user data
    """
    groupID = -1
    count = 0
    for descID, bc in op.GetObject().GetUserDataContainer():
        if descID[1].dtype == c4d.DTYPE_GROUP:
            if IsChildOfGroup(bc):
                    count += 1
                    groupID = descID[1].id

    return groupID, count


def CreateGroup(parent, trackNumber = -1):
    """
    this will create a group in the user data below "myGroup" with all the different data needed
    """
    if trackNumber &lt; 0:
        # we must calculate the track number
        lastGroupID, trackNumber = GetLastGroupID()

    #Get the default container for the group type
    bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP)
    longName  = "Track " + str(trackNumber)
    shortName = "Track"  + str(trackNumber)

    bc[c4d.DESC_NAME] = longName
    bc[c4d.DESC_SHORT_NAME] = shortName
    bc[c4d.DESC_TITLEBAR] = True
    bc[c4d.DESC_GUIOPEN] = False
    bc[c4d.DESC_PARENTGROUP] = parent
    #return the group id added so we can add other element to it
    return op.GetObject().AddUserData(bc)



def AddBool (group, name):
    """
    this will create a boolean gadget in the group
    """
    bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BOOL)
    bc[c4d.DESC_NAME] = name
    bc[c4d.DESC_SHORT_NAME] = name
    bc[c4d.DESC_PARENTGROUP] = group
    return op.GetObject().AddUserData(bc)


def AddTime(group, name):
    """
    this will add the field start time for exemple
    """
    bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_TIME)
    bc[c4d.DESC_NAME] = name
    bc[c4d.DESC_SHORT_NAME] = name
    #bc[c4d.DESC_UNIT] = c4d.DESC_UNIT_TIME
    bc[c4d.DESC_PARENTGROUP] = group
    return op.GetObject().AddUserData(bc)

def AddSoundPath(group, name):
    """
    this will add the field for file
    """
    bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_FILENAME)
    bc[c4d.DESC_NAME] = name
    bc[c4d.DESC_SHORT_NAME] = name
    bc[c4d.DESC_PARENTGROUP] = group
    return op.GetObject().AddUserData(bc)


def AddString(group, name):
    """
    this will add a static string to a group
    """
    bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STATICTEXT)
    bc[c4d.DESC_NAME] = name
    bc[c4d.DESC_SHORT_NAME] = name
    #bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_STATICTEXT
    bc[c4d.DESC_PARENTGROUP] = group
    return op.GetObject().AddUserData(bc)



def message(msg_type, data) :
    if msg_type == c4d.MSG_NOTIFY_EVENT:
        event_data = data['event_data']
        if event_data['msg_id'] == c4d.MSG_DESCRIPTION_COMMAND:
            desc_id = event_data['msg_data']['id']
            if desc_id[1].id == addButtonID:
                AddGroupOfUserData()
            elif desc_id[1].id == removeButtonID:
                RemoveGroupOfUserData()
                


def main() :
    pass
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/57938</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/57938</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Mon, 08 Apr 2019 09:11:05 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Fri, 05 Apr 2019 13:17:23 GMT]]></title><description><![CDATA[<p dir="auto">@m_magalhaes I am writing it in a python tag.</p>
<p dir="auto">I should note that when it comes to programming, I’m not all that smart <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61b.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--stuck_out_tongue" style="height:23px;width:auto;vertical-align:middle" title=":P" alt="😛" /></p>
]]></description><link>http://developers.maxon.net/forum/post/57920</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/57920</guid><dc:creator><![CDATA[mrittman]]></dc:creator><pubDate>Fri, 05 Apr 2019 13:17:23 GMT</pubDate></item><item><title><![CDATA[Reply to Add&#x2F;Remove Groups of User Data on Fri, 05 Apr 2019 08:50:07 GMT]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">we need a bit more informations regarding where you are trying to create this UI :</p>
<p dir="auto">Are you writing your code in a python tag, a python generator or a python plugin ?</p>
<p dir="auto">Cheers</p>
]]></description><link>http://developers.maxon.net/forum/post/57916</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/57916</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Fri, 05 Apr 2019 08:50:07 GMT</pubDate></item></channel></rss>