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
    • Register
    • Register
    • Login

    2024 NodeData Init isCloneInit argument for older version

    Cinema 4D SDK
    2024 python
    3
    4
    838
    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.
    • mikeudinM
      mikeudin
      last edited by

      Hello!
      In R2024 for NodeData plugins Init method now requires isCloneInit argument. But now, after code changing, older versions gives an error:

      TypeError: Init() takes exactly 3 arguments (2 given)
      

      Is there a way to make this new code feature compatible with older Cinema 4D versions? Now I have to create two pypv files: up_to_2024.pypv and 2024_and_after.pypv. Which is not convinient for developement obviously.
      Thank you!

      Checkout my python tutorials, plugins, scripts, xpresso presets and more
      https://mikeudin.net

      bacaB ferdinandF 2 Replies Last reply Reply Quote 0
      • bacaB
        baca @mikeudin
        last edited by

        Hi @mikeudin,

        I changed my python plugins to

        def Init(self, op, isCloneInit=False):
        

        So in older versions of Cinema4D it supposed to act as it act before

        mikeudinM 1 Reply Last reply Reply Quote 1
        • ferdinandF
          ferdinand @mikeudin
          last edited by ferdinand

          Hey @mikeudin,

          Thank you for reaching out to us. @baca is right, default values are an elegant way to achieve signature overloading in Python. In cases where this does not suffice, you can also make use of the fact that everything is an object in Python, which means syntax akin to a preprocessor macro will work in Python.

          """Realizes a class with a method Bar which has a different number of arguments and output depending
          on a global constant, here the version of Cinema 4D.
          
          This makes use of the fact that functions are first class objects in Python. While Python has no
          function overloading in the strict sense, we can simply attach functions based on context. We could
          even do this at runtime based on a non-constant value.
          """
          
          import c4d
          
          class Foo:
              """Implements Foo.Bar differently based on the version of Cinema 4D.
              """
              if c4d.GetC4DVersion() >= 2024000:
                  def Bar(self, arg1: int, arg2: bool) -> None:
                      print ("NEW", arg1, arg2)
              else:
                  def Bar(self, arg1: int) -> None:
                      print ("OLD", arg1)
          
          # Calls Foo.Bar. The version guard is only here so that this example can be run in all versions of
          # Cinema without throwing an error (as the number of arguments changed).
          if c4d.GetC4DVersion() >= 2024000:
              Foo().Bar(42, True)
          else:
              Foo().Bar(42)
          

          2024.0.0 and higher will run the two argument version and print NEW 42 True, everything else will run the other version and print OLD 42.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 1
          • mikeudinM
            mikeudin @baca
            last edited by

            @baca Thank you! Works like a charm!

            Checkout my python tutorials, plugins, scripts, xpresso presets and more
            https://mikeudin.net

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