re order user data

  • On 25/11/2013 at 16:45, xxxxxxxx wrote:


    Perhaps I am looking at it the wrong way, as I am still coming to grips with how the userdata container works - but I'd like to reorder the userdata on a generator object without removing it and rebuilding it. I can see that GetUserDataContainer() returns a list of containers - that's great - but I can't see a way to pass a new reordered list back to the object's userdata (I can only set or add individual elements, and new items are always added to the end of the stack regardless of ID).

    Any tips?


  • On 26/11/2013 at 02:25, xxxxxxxx wrote:

    the indices arent working that way you think they do. an example sorting ud by its type:

    import c4d
    ORDER = [ c4d.DTYPE_BOOL, 
              c4d.CUSTOMDATATYPE_SPLINE ]
    def main() :
        if op:
            udata = op.GetUserDataContainer()
            nid   = udata[len(udata)-1][0][1].id
            # delete existing ud
            for i in xrange(len(udata) + 1) :
            # we walk over our stored ud looking into the descid . for other ordering types like the name
            # look into c4d.Description - the name would be data[c4d.DESC_NAME] for example.
            res = []
            for dtype in ORDER:
                for descid, data in udata:
                    if descid[1].dtype == dtype:
                       nid += 1
                       descid[1].id = nid
                       res.append((descid, data))
            # write data back
            for descid, data in res:
                op.SetUserDataContainer(descid, data)
    if __name__=='__main__':

  • On 26/11/2013 at 19:27, xxxxxxxx wrote:

    thanks littledevil for the reply! I appreciate the insight.

Log in to reply