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

    Python Tag not updating

    Cinema 4D SDK
    python
    3
    9
    1.2k
    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.
    • SwinnS
      Swinn
      last edited by Manuel

      Hi, I have a null with some User Data on it and a Python tag attached to it. When I make changes in the User Data, the Python tag does not seem to see them. If I make a slight change to the Python tag, then it does. Is there a way to get the Python tag to react to User Data changes without modifying it? Thanks.

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi @Swinn, thanks for reaching out us.

        With regard to your issue, please have a look at this thread where it was discussed how to have a python tag reacting to a button userdata assigned to the tag's parent. In your case you might be more interested in parsing the events stream until you encounter a MSG_DESCRIPTION_POSTSETPARAMETER .

        import c4d
        
        def message(msg_type, data):
            if msg_type == c4d.MSG_NOTIFY_EVENT:
                event_data = data['event_data']
                msg_id = event_data['msg_id']
                if msg_id == c4d.MSG_DESCRIPTION_POSTSETPARAMETER:
                    desc_id = event_data['msg_data']['descid']
                    if desc_id[1].id == 1: # The ID of the User Data
                        print "A little bit more off"
                        mtx =  op.GetObject().GetMg()
                        mtx.off = mtx.off + c4d.Vector(10,0,0)
                        op.GetObject().SetMg(mtx)
        
        def main():
            obj = op.GetObject()
        
            # Check if we already listen for message
            if not obj.FindEventNotification(doc, op, c4d.NOTIFY_EVENT_MESSAGE):
                obj.AddEventNotification(op, c4d.NOTIFY_EVENT_MESSAGE, 0, c4d.BaseContainer())
        

        Rest to be told that, for some yet-to-understand reason, the Python console doesn't print the text A little bit more off on the user changing the userdata, but this is neglectable if you're interested in the real action that the Python tag executes.

        Best, R

        1 Reply Last reply Reply Quote 0
        • r_giganteR
          r_gigante
          last edited by

          With regard to logging-lagging @m_adam has pointed me to this other thread.
          If you rewrite my code as

          ...
                      if desc_id[1].id == 1: # The ID of the User Data
                          txt = "A little bit more off"
                          pythonLogger = maxon.Loggers.Python()
                          pythonLogger.Write(maxon.TARGETAUDIENCE.ALL, txt, maxon.MAXON_SOURCE_LOCATION(1), maxon.WRITEMETA.UI_SYNC_DRAW)
                          mtx =  op.GetObject().GetMg()
                          mtx.off = mtx.off + c4d.Vector(10,0,0)
                          op.GetObject().SetMg(mtx)
          

          you'll be fine to go 🙂

          Cheers, R

          1 Reply Last reply Reply Quote 0
          • SwinnS
            Swinn
            last edited by

            Thanks! I will test this out.

            1 Reply Last reply Reply Quote 0
            • SwinnS
              Swinn
              last edited by

              @r_gigante said in Python Tag not updating:

              if desc_id[1].id == 1: # The ID of the User Data
              txt = "A little bit more off"
              pythonLogger = maxon.Loggers.Python()
              pythonLogger.Write(maxon.TARGETAUDIENCE.ALL, txt, maxon.MAXON_SOURCE_LOCATION(1), maxon.WRITEMETA.UI_SYNC_DRAW)
              mtx = op.GetObject().GetMg()
              mtx.off = mtx.off + c4d.Vector(10,0,0)
              op.GetObject().SetMg(mtx)

              I get an error message Traceback (most recent call last):
              File "Python UD Integration Test", line 11, in message
              NameError: global name 'maxon' is not defined

              1 Reply Last reply Reply Quote 0
              • M
                m_adam
                last edited by

                import maxon

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                1 Reply Last reply Reply Quote 0
                • SwinnS
                  Swinn
                  last edited by

                  Done. Fixed. Duh on my part. 🙂
                  Thanks!

                  1 Reply Last reply Reply Quote 0
                  • SwinnS
                    Swinn
                    last edited by

                    Now getting this error:

                    Traceback (most recent call last):
                    File "Python UD Integration Test", line 13, in message
                    File "/Applications/MAXON/Cinema 4D R20/resource/modules/python/libs/python27/maxon/interface.py", line 287, in MAXON_SOURCE_LOCATION
                    return SourceLocation(loc[0], loc[1])
                    File "/Applications/MAXON/Cinema 4D R20/resource/modules/python/libs/python27/maxon/interface.py", line 274, in init
                    Data.init(self, self._dt)
                    File "/Applications/MAXON/Cinema 4D R20/resource/modules/python/libs/python27/maxon/data.py", line 104, in init
                    self._data = Data_Create(self._dt._data, C)
                    TypeError: failed to set member 'file', caused by (exceptions.TypeError: unable to convert maxon.datatype.DataType to @char)

                    1 Reply Last reply Reply Quote 0
                    • M
                      m_adam
                      last edited by m_adam

                      make sure to pass a str value aka str(yourMessage)

                      if this doesn't solve the issue open a new topic 🙂

                      Cheers,
                      Maxime

                      MAXON SDK Specialist

                      Development Blog, MAXON Registered Developer

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