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

    how to program plugins with python?

    Cinema 4D SDK
    r25 python
    3
    20
    4.8k
    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.
    • love_me_renderL
      love_me_render
      last edited by

      Firstly, thank you very much for the detailed tips!
      Now I understand. I need an external developement-environment to compile a Python-Plugin.
      The basic idea was to make my tree generator upwards and downwards more compatible. In C++ I would have to write a new plugin for almost every C4D version, but that's difficult because you only ever have one version.
      As a C++-programmer for decades, I have fundamental difficulties understanding Python plugins.
      I can still manage Python scripts, but I can't get my head round Python plugins.
      How do you compile them? Are the C4D on-board tools enough? Or do you need an external Python development-environment? If so, which one is best? Is there a gigantic SDK for it like for C++?
      Klaus

      1 Reply Last reply Reply Quote 0
      • bacaB
        baca
        last edited by

        Hi @love_me_render,

        It seems like you're a bit overthinking the process.
        But it's much simpler.

        Python plugin executes in runtime, and there's no compilation needed.
        It's required that pyp file implements a class and registers that class as a plugin (usually in the footer of the pyp file). That's it.
        Also plugin file structure should follow same scheme as c++ plugin, so Cinema would handle resources automatically.

        Once again — you just need to download any python plugin (or all of them) from the official GitHub, put them into Cinema4D/plugins folder (or whatever appropriate place) and start Cinema4D.
        Switch to "Script" layout (not necessary, but it's comfortable to see the console).

        You'll see those plugins in the "Extension" menu -> click on any item, and it should generate an instance in object manager (if it's an object plugin obviously).

        Then you can use any text editor to edit corresponding pyp file.
        Just add some print to the console on Init, or on Update class callback,
        save it,
        hit "Reload Python Plugins" in Cinema4D,
        and create new plugin instance once again
        — you'll see message(s) in the python console.

        And that would be a time to create new subject with more specific questions šŸ˜‰


        As a side note,
        Python computation is relatively slow, and it doesn't support multiprocessor execution in Cinema. Also there're some limitations comparable to c++ api.

        In the defence of c++ plugin development — with new Maxon subscription model, you might assume most of users are on the latest release.
        So there might be an option for you to maintain latest release versions only.

        1 Reply Last reply Reply Quote 1
        • love_me_renderL
          love_me_render
          last edited by

          Thank you baca, this is very helpful information.
          So I "only" have to write a pyp-text-file and save it in a plugin folder. Brilliant.
          But how are the "res" folders and the like created?
          I have the last permanent version with R25, therefore I haven't the newest version, I don't want a subscription.

          bacaB 1 Reply Last reply Reply Quote 0
          • bacaB
            baca @love_me_render
            last edited by

            @love_me_render those are manually created,
            luckily all of them also text files.

            I'm not really familiar with cpp development, thought it's same manual process...

            Btw there's plugin structure overview in official doc: developers.maxon.net/docs/py/2024_0_0a/misc/pluginstructure.html

            1 Reply Last reply Reply Quote 1
            • love_me_renderL
              love_me_render
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • love_me_renderL
                love_me_render
                last edited by

                Thank you all. Now I have understood šŸ™‚

                1 Reply Last reply Reply Quote 0
                • love_me_renderL
                  love_me_render
                  last edited by

                  Hi,
                  after several weeks of working on porting my tree generator plugin from C++ to Python, I have now realised that the result in Python is much too slow compared to C++.
                  Even a single tree is calculated far too slowly. With several clones of trees, the result is completely unusable.
                  If there is no solution to increase the computing speed of the generated Python plugin by a factor of tens, I will revert to C++.
                  Is there perhaps a way to compile the Python plugin text file into machine code?

                  My conclusion: Python is well suited for small calculations and objects with a few polygons.
                  Not for larger, more complex projects.

                  Klaus

                  bacaB i_mazlovI 2 Replies Last reply Reply Quote 0
                  • bacaB
                    baca @love_me_render
                    last edited by

                    Hi @love_me_render ,

                    That's true.

                    Python is good to operate with several objects PSRs, or to apply built-in commands onto geometry.
                    But since it's not only slower comparable to c++, but also single-processing — it's not worth to deal with Python for intense computations.

                    If you pursue easier delivery, install and support — check if Scene Nodes suit you.
                    Those have great performance to build geometries.
                    That's not a coding, however your logic skills will be required to build nodes setups.

                    1 Reply Last reply Reply Quote 0
                    • i_mazlovI
                      i_mazlov @love_me_render
                      last edited by i_mazlov

                      Hi Klaus,

                      @baca is again completely right! šŸ‘

                      Although python has lots of advantages (really fast start for coding, no need in compilation, reloading changes without restarting cinema etc just to mention a couple), however, this doesn't come with no cost. It is quite slow especially in highly loaded parts of code execution (like scene hooks or GetVirtualObjects()).

                      There's an opportunity to offload expensive parts of your code into C++ library and then call these functions from within your python execution environment. This approach is called Python bindings, you can search more information about it yourself, e.g. here: Python Bindings: Calling C or C++ From Python.

                      However, this tend to speed things up when you have an expensive task that is executed not too frequently. I'm not aware of what you're doing in your plugin, but it sounds like you have to deal with numerous amount of C4D objects, which drastically slows down your plugin. If that's the case, then I assume the speed up you would gain from the python bindings wouldn't be significant.

                      Cheers,
                      Ilia

                      MAXON SDK Specialist
                      developers.maxon.net

                      1 Reply Last reply Reply Quote 2
                      • love_me_renderL
                        love_me_render
                        last edited by

                        Hi,
                        thank you for the tips.

                        Here is my C++ -treegenerator-plugin, written for R25:

                        http://www.klausfilm.bplaced.net/TreeGenerator/Website_Treegenerator.html

                        Cheers
                        Klaus

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