Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    re order user data

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 303 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          thanks littledevil for the reply! I appreciate the insight.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post