Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Insert User Data Track in Python

    Cinema 4D SDK
    3
    10
    1.6k
    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
      Hugo BATTISTELLA
      last edited by

      Hello,
      I would like to add track (timeline) for each user data I have set on a object .
      Here is the code I tried, but I don't know why it's not working

      Here is the code I wrote :

      import c4d
      from c4d import gui
      
      
      #Création d'une piste pour chaque donnée utilisateur
      def AddAnimationTrack(op):
              
          LED = c4d.CTrack(op,c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA,1,c4d.DTYPE_GROUP),c4d.DescLevel(c4d.ID_USERDATA,2,c4d.DTYPE_GROUP),c4d.DescLevel(c4d.ID_USERDATA,3,c4d.DTYPE_REAL)))
          op.InsertTrackSorted(LED)
      
          return True
      # Main function
      def main():
          AddAnimationTrack(op)
      
      # Execute main()
      if __name__=='__main__':
          main()
      

      I work on R21.
      You can see the scene here : ADD_TRACK - 1.c4d

      Thank you for helping

      ferdinandF 1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by Cairyn

        Your DescID looks weird. Try something like:

        c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER),
                            c4d.DescLevel(userdata_entry,c4d.DTYPE_LONG))
        

        with userdata_entry being the actual ID of the user data.

        (Disclaimer: I didn't sit down and try this, but the code is from a script dealing with animations (FindTrack), so I'm confident it should work.)

        H 1 Reply Last reply Reply Quote 0
        • H
          Hugo BATTISTELLA @Cairyn
          last edited by

          @cairyn said in Insert User Data Track in Python:

          c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER),
          c4d.DescLevel(userdata_entry,c4d.DTYPE_LONG))

          Hello ! Thank you for replying !

          I've put your code but get a error :
          "Traceback (most recent call last):
          File "scriptmanager", line 19, in <module>
          File "scriptmanager", line 15, in main
          File "scriptmanager", line 9, in AddAnimationTrack
          NameError: global name 'userdata_entry' is not defined"

          Maybe I didn't get what I should do with "userdata_entry"

          CairynC 1 Reply Last reply Reply Quote 0
          • H
            Hugo BATTISTELLA
            last edited by

            This is what the code looks like now :

            import c4d
            from c4d import gui
            
            
            #Création d'une piste pour chaque donnée utilisateur
            def AddAnimationTrack(op):
            
                LED = c4d.CTrack(c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER),
                                c4d.DescLevel(c4d.ID_USERDATA,3,c4d.DTYPE_LONG)))
                op.InsertTrackSorted(LED)
            
                return True
            # Main function
            def main():
                AddAnimationTrack(op)
            
            # Execute main()
            if __name__=='__main__':
                main()
            
            CairynC 1 Reply Last reply Reply Quote 0
            • CairynC
              Cairyn @Hugo BATTISTELLA
              last edited by Cairyn

              @hugo-battistella userdata_entry is a variable I was using in the script. It stands for the ID of the user data entry as shown in the user data dialog on the right side, for example 1 here:

              863eaf01-45bc-495d-b0cf-b5c5351eaeac-image.png

              If you have that user data in your object, you can query op (the selected object) in the console like this:

              op[c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER),c4d.DescLevel(1,c4d.DTYPE_REAL))]
              

              This is also true if the data entry is part of a group.

              1 Reply Last reply Reply Quote 0
              • CairynC
                Cairyn @Hugo BATTISTELLA
                last edited by

                @hugo-battistella The DescID represents a hierarchical structure, so it makes no sense to put ID_USERDATA into the second DescLevel. The first DescLevel identifies the UserData structure within the object. The second DescLevel identifies the entry in that UserData by its ID (for which you'd have to define a proper constant yourself).

                Also, the constructor for a track requires the object as first parameter. This code works for me:

                import c4d
                from c4d import gui
                
                def AddAnimationTrack(op):
                
                    LED = c4d.CTrack(op, 
                                c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA,c4d.DTYPE_SUBCONTAINER),
                                c4d.DescLevel(1,c4d.DTYPE_REAL)))
                    op.InsertTrackSorted(LED)
                
                    return True
                
                def main():
                    AddAnimationTrack(op)
                    c4d.EventAdd()
                
                if __name__=='__main__':
                    main()
                

                (provided I have a user data with ID 1 as shown in the screenshot from my last post, and this object is selected.)

                1 Reply Last reply Reply Quote 1
                • H
                  Hugo BATTISTELLA
                  last edited by

                  Hello @Cairyn,
                  thank you a lot for this answer. I try this quikly but now I have a better understanding of the Desclevels concept !

                  1 Reply Last reply Reply Quote 0
                  • H
                    Hugo BATTISTELLA
                    last edited by

                    That works find ! Thank you so much

                    1 Reply Last reply Reply Quote 0
                    • ferdinandF
                      ferdinand @Hugo BATTISTELLA
                      last edited by ferdinand

                      Hello @Hugo-BATTISTELLA,

                      thank you for reaching out to us. And thank you at @Cairyn for answering the question. We do not have to add anything here, because @Cairyn did already a fantastic job.

                      If you have however follow-up questions, please do not hesitate to ask them.

                      Cheers,
                      Ferdinand

                      MAXON SDK Specialist
                      developers.maxon.net

                      1 Reply Last reply Reply Quote 0
                      • ferdinandF
                        ferdinand
                        last edited by

                        Hello @JH23,

                        without any further questions or postings, we will consider this topic as solved by Wednesday and flag it accordingly.

                        Cheers,
                        Ferdinand

                        MAXON SDK Specialist
                        developers.maxon.net

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