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

    Listen Specific UserData field [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 586 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 19/03/2016 at 23:15, xxxxxxxx wrote:

      Hi, i need to execut some functions from my script everytime when user change something in one user data field. Im just a beginer in python sdk and i dont understand very well how it works but i thought a little and i made for my userdata field that i want to listen a clone  and i hide it from script(just to store the old value) and i compare always with main field. If something changed i do something. In may case i just change the value of chekbutton.

      here my script:

      import c4d

      def main() :
          obj = op.GetObject() #get an object with python tag
          ud = obj.GetUserDataContainer() #get an userdata container
          ud[2][1][c4d.DESC_HIDE] = True #hide my field copy 
          obj.SetUserDataContainer(ud[2][0], ud[2][1])
          new = obj[c4d.ID_USERDATA,1] #value of my filed that i want to listen
          old = obj[c4d.ID_USERDATA,3]  #value of clone 
          
          if old != new:
              obj[c4d.ID_USERDATA,2] = 1 - obj[c4d.ID_USERDATA,2] #change value of radiobutton to oposite
              obj[c4d.ID_USERDATA,3] = new #store value of my field to clone

      So it works well but it looks like a trick. Is there other method to listen a change in userdata filed?

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

        On 21/03/2016 at 03:07, xxxxxxxx wrote:

        Hello,

        what exactly do you mean with "script"? Do you mean a script that is stored and executed from the Script Manager? A script in the Script Manager can only be executed from that Script Manager, it cannot be triggered by an event.

        Or is your script stored in a Python Tag? Then the best way would be indeed to store the old value in another user data field and compare it with the current value.

        Best wishes,
        Sebastian

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

          On 21/03/2016 at 05:09, xxxxxxxx wrote:

          From python tag. Thank you.

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

            On 21/03/2016 at 05:26, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            Or is your script stored in a Python Tag? Then the best way would be indeed to store the old value in another user data field and compare it with the current value.

            You can store the old value without an additional user data field.

            import c4d
            G = {}
              
            def main() :  
                value = op[c4d.ID_USERDATA, 1]
                if value != G.get('old_value') :
                    # Value changed or first time the script is run (eg. if 
                    # the scene was just opened).
                    G['old_value'] = value
            

            Best,
            Niklas

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

              On 21/03/2016 at 07:30, xxxxxxxx wrote:

              good method NiklasR. Thank you

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