re order user data



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

    Hi,

    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?

    cheers,
    Iain



  • 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.DTYPE_LONG, 
              c4d.DTYPE_REAL, 
              c4d.DTYPE_VECTOR, 
              c4d.DTYPE_STRING, 
              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) :
                op.RemoveUserData(i)
                
            # 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)
            c4d.EventAdd()
            
    if __name__=='__main__':
        main()
    


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

    thanks littledevil for the reply! I appreciate the insight.


Log in to reply