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

    Q: Python Globals

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 532 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 03/02/2012 at 01:45, xxxxxxxx wrote:

      If I want something in say - a mograph effector to run once

      can I make a global ??
      without assigning a value (as it would zero each time the script ran if I did)

      The correct syntax and logic would be really helpful and I'm unsure of both - pls

      the sort of thing I was trying to do........have no idea how to do this correctly
      advice pls

      if global ------called Flag_something_done---- not assigned  : ?????
      Do the operation
      Flag_something_done = 1

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 03/02/2012 at 05:40, xxxxxxxx wrote:

        is_done = False  
          
        def main() :  
          global is_done  
          if not is_done:  
              # make it done ...  
              is_done = True
        

        But setting globals is IMHO not a good style. I prefer using mutable objects available from the global-scope.

        data = type('', (), dict(is_done = False))()  
          
        def main() :  
          if not data.is_done:  
              # make it done ...  
              data.is_done = True
        

        Originally posted by xxxxxxxx

        if global ------called Flag_something_done---- not assigned  : ?????
        Do the operation
        Flag_something_done = 1

        If you really want to make it dirty:

        def main() :  
          if not globals().get('is_done', False) :  
              # make it done ...  
              globals()['is_done'] = True
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 03/02/2012 at 06:46, xxxxxxxx wrote:

          🙂
          cheers Niklas

          I prefer to keep things as correct as possible
          I like the idea behind the mutable object with global scope

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 05/02/2012 at 03:29, xxxxxxxx wrote:

            Thanks for the info Niklas

            And yes it works - but...

            As far as the Python Effector is concerned
            it appears this method can't be used
            as the global is only set when the file is opened and first run

            For the Effector
            it needs something that can process

            'is this the same as the last past through'?
            if True - skip setting it

            and its also unclear if the effector in Parameter mode
            is working differently from the effector in Full mode
            Can the same method be used for both

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 05/02/2012 at 09:31, xxxxxxxx wrote:

              Could you please post what you have tried?

              Cheers,
              Niklas

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