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

    Python tag executing repetitively

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 346 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 18/08/2013 at 07:41, xxxxxxxx wrote:

      Hello everyone.

      I have a problem which I keep stumbling upon when at varying stages when working on python elements within my scene. I have had this problem with both python xpresso nodes and python tags.

      My understanding is that if either object(node or tag) has 'Frame Dependent' disabled, the script should only execute when the scene is updated in one way or another e.g. view port redraw or value change somewhere etc(please let me know if I have misunderstood this). The majority of the time this is how it operates, however sometimes the script will just keep executing again and again and won't stop, then when I try to change something in the code, the changes are not accepted and the script keeps running as if unchanged.

      Has anyone else encountered this problem? Anyone know how to fix it?

      I'm very much hoping this is me missing something and not a bug, any help would me much appreciated.

      Thanks

      Adam

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

        On 18/08/2013 at 07:57, xxxxxxxx wrote:

        Sounds like you are calling c4d.EventAdd() in your tag. Could you post the code?

        -Niklas

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

          On 18/08/2013 at 08:03, xxxxxxxx wrote:

          1. the infinite loop is more likely caused by your code. such fundamental errors are usually not in the c4d code.

          2. enabling 'frame dependent' will ensure that your tag is only executed once per frame. a tag can appear multiple times in the expression queue for a pass/frame.

          3. post your code.

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

            On 18/08/2013 at 08:17, xxxxxxxx wrote:

            Hi Niklas,

            Thanks, that was exactly it, it's astonishing I've managed to get as far as I have with python without realising this. 😂 - my script was unconditionally calling c4d.EventAdd() an the very end of the script.

            Btw, I'm the same guy that tweeted you about your python lessons poll on Friday, just to bridge the link.

            Thanks for the input littledevil, all of my loops have a finite number of iterations and so I didn't think it was that. Also my code is such a mess at the moment it would require some tidying before I could  post if for someone to understand without ambiguity.

            Thank you both!

            Adam

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

              On 18/08/2013 at 08:55, xxxxxxxx wrote:

              Hi Adam,

              you figured it right, calling c4d.EventAdd() unconditionally is the fault. It triggers an immediate refresh
              and leads to an infinite loop. However, calling c4d.EventAdd() from a Tag is not always bad. This is
              useful if you change a parameter on your Tag and you want to give immediate feedback to the user.

              This technique is applied when treating boolean parameters as buttons. The only drawback
              with this technique is, that the code is still not executed from the main thread and any GUI
              operations are prohibited.

              def main() :
                  # ...
                
                  if op[c4d.ID_USERDATA, 1]:
                      op[c4d.ID_USERDATA, 1] = False
                      c4d.EventAdd()
                
                      # Do an action
                      return
                
                  # ...
              

              I see, Adam, thanks for the hint. Good to know. 🙂

              Cheers,
              -Niklas

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