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
    • Admin
    • Login

    Add User Data from Multiple Objects to a Null

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 464 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 17/05/2016 at 11:00, xxxxxxxx wrote:

      Hi,

      GOAL:
      Ultimately I want to create an object plugin called "Rig."
      - You place multiple objects that have User Data as children of the Rig object.
      - The rig object copies the User Data of each child and then adds them to itself.
      - It then creates an Xpresso tag and connects it's User Data to the childrens user data
      - If a child is removed or deleted, the rig updates itself.

      So if I have a two objects with user data and I put them under the "Rig" object, that rig Object will have the user data of the two objects and it can control them.

      Current Code
      I have a scene with a null named "Null" and two objects with User Data on them.  When I run this the User Data from obj get overwritten by obj2.  How can I add the obj2 user data and not overwrite the obj user data on the Null object?

      import c4d
      from c4d import gui
      #Welcome to the world of Python

      def main() :
          target = doc.SearchObject("Null")
          #print target
          obj = doc.SearchObject("Red-EpicDragonBody")
          #print obj
          obj2 = doc.SearchObject("WoodenCamera-Baseplate19mmRedSet")

      for id, bc in obj.GetUserDataContainer() :
             target.SetUserDataContainer(id, bc)
             print id

      for id, bc in obj2.GetUserDataContainer() :
              target.SetUserDataContainer(id, bc)
              print id

      if __name__=='__main__':
          main()

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

        On 18/05/2016 at 01:35, xxxxxxxx wrote:

        Hello,

        the user data is overwritten because you overwrite it. The IDs of user data parameters are unique on an object but not globally. So the user data parameters of object A have the IDs 1,2,3 ...  and the user data parameters on object B also have the IDs 1, 2, 3 … .

        So if you merge them together in one container you must create a new, offset ID for the user data of the second object or use AddUserData().

        Best wishes,
        Sebastian

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

          On 27/05/2016 at 06:59, xxxxxxxx wrote:

          Hello Matt,

          was your question answered?

          Best wishes,
          Sebastian

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

            On 27/05/2016 at 17:43, xxxxxxxx wrote:

            Hey Sebastian,

            Thanks for the reply.  In theory, I understand that the ID have to be unique.  But I need to figure how to actually implement it!

            Thanks!

            Matt

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