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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Python Node Executing Twice (R20.059 Bug?)

    Cinema 4D SDK
    r20 python
    2
    4
    534
    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.
    • B
      bentraje
      last edited by

      Hi,

      I'm trying to create a toggle function using a custom user data.
      The problem is the Python Node in the Node Editor executes the function twice.
      For this reason, I am stuck on perpetual loop.

      You can see an illustration file here:
      https://www.dropbox.com/s/zn56e8tc5u7jn6c/c4d120_python_node_execute_twice.c4d?dl=0

      If you press the Print Me (the Toggle Button), it prints "Hello World" twice. You can also see the Mode A changing to Mode B then going back to Mode A again.

      I labeled as a "bug" since I don't recall a similar behavior in R19.

      Can you confirm? Thank you

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

        Hi, @bentraje I can indeed confirm the change of behavior since R20 SP2 (since R20.028 to be precise).
        The issue is that the Xpresso tag is executed from the user interaction and the thread responsible to update the data. Since user interaction are done in the main thread a correct workaround is to do checks for it like so

        import c4d
        
        
        def main():
            node = op
            nodeMaster = node.GetNodeMaster()
            owner = nodeMaster.GetOwner()
            hostObject = owner.GetObject()
        
            if Input1 == 1 and c4d.threading.GeIsMainThread():
                if hostObject[c4d.ID_USERDATA,2] == 0:
                    hostObject[c4d.ID_USERDATA,2] = 1
                else:
                    hostObject[c4d.ID_USERDATA,2] = 0
        

        Finnally note this is not an issue related to Python but a more general issue regarding Xpresso.
        In any case, I've open a bug report.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • B
          bentraje
          last edited by bentraje

          Hi @m_adam

          Thanks for the response especially the specific version it changed.
          Since I'm expecting the file will be used by versions below R20,
          I just added this line in the code:

          if c4d.GetC4DVersion() >= 20028 :
               if Input1 == 1 and c4d.threading.GeIsMainThread():
                            # Do Something
          else:
               if Input1 == 1:
                           # Do Something
          

          Thanks again. Have a great day ahead!

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

            My workaround still works for earlier version so you don't really need to check for version but it's up to you.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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