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

    Execute a Python Code Within PyCharm that Connects to C4D?

    Cinema 4D SDK
    python r20
    4
    14
    4.1k
    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 bentraje

      Hi,

      Is it possible to run/execute Python code within Pycharm and the lines get processed immediately in C4D?

      Currently,
      (1) I edit the python file in Pycharm.
      (2) Open the python file within C4D's Script Manager
      (3) Then Execute.

      And if you make changes in python file, C4D prompts you every time to save the changes which is slightly cumbersome.

      Basically, I would just like to reduce it to one step
      (1) Edit and run/execute the python file within Pycharm

      Basically, I'm looking for something like MayaCharm (https://plugins.jetbrains.com/plugin/8218-mayacharm) equivalent for C4D?

      Thank you for looking at my problem

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

        Sure. See here: https://developers.maxon.net/docs/py/2023_2/manuals/introduction/python_c4dpy.html

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

          @mp5gosu

          Thanks for the response, but correct me if I'm wrong but that documentation is for autocompletion.
          I already have a set-up a like that, but it does not connect with C4D.

          For instance,
          If I run a print ("Hello World"), it appears okay in Pycharm but no reaction in C4D application itself. The c4dpy.exe and the cinema4d.exe are in the same version.

          For comparison, with the Maya Pycharm, if I run a print ("Hello World"), the phrase appears in the console in Maya.

          Is thre a way around this?

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

            If you run c4dpy from PyCharm, any code that can be run in Cinema 4D is executed. You can see it in the Terminal.
            It depends on how you invoke your script when running Cinema 4D in normal mode.
            You may want to consider this thread: https://developers.maxon.net/forum/topic/11070/run-python-script-at-cinema4d-opening/2
            and also read about the initialization of scripts at startup: https://developers.maxon.net/docs/py/2023_2/manuals/introduction/python_init_py.html

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

              Thanks for the response @mp5gosu. But the init file is not really what I am looking for. Correct me if I'm wrong its the set-up to run scripts at start-up.

              Anyway, you can see the problem in this illustration video:
              https://www.dropbox.com/s/g4y7lzmtv25huq9/c4d077_runCode_from_pycharm.mp4?dl=0

              If C4D and Pycharm is connected, the Hello World should be present both in PyCharm and C4D

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

                Oh hey, now I understand you. 🙂
                You get indeed a reaction from c4dpy, it is written in you PyCharm console, namely Hello World.
                But here seems to be a misunderstanding.
                c4dpy is an interpreter, it does not run nor interact with your Cinema 4D installation. c4dpy is a so to say "standalone python interpreter" with access to Cineama 4D's api.

                You can load documents, modify and save them - all without having to open Cinema 4D.
                OR
                you can use Cinema 4D's script manager to write your scripts (the video shows that you already did that.
                Another option would be to have a command plugin. I'm usually writing my plugins in PyCharm and use a build configuration that designates Cinema as external tool. This way, I have a gui environment and debugging tools avilable.

                Hope, this helps a bit. Maybe some of the devs will be of more help here.
                edit: But from what I can tell, it's not so easily possible to achieve the same live link like MayaCharm offers.

                1 Reply Last reply Reply Quote 2
                • mikeudinM
                  mikeudin
                  last edited by

                  You need something like this solution for Sublime Text
                  Maybe you can adapt that code, fork repo and create what you need for PyCharm.

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

                  1 Reply Last reply Reply Quote 1
                  • M
                    mp5gosu
                    last edited by

                    @mikeudin That would require him to write an own listener plugin. I believe, that is way out of scope.

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

                      @mp5gosu
                      Thanks for the confirmation that it's not yet available. This will help me be in peace that I am at a dead end at the moment 🙂

                      @mikeudin

                      Thanks for the reference! But I am afraid, that is beyond my skillset. But will keep it in mind if Sublime will be supported in the future for the autocompletion.

                      1 Reply Last reply Reply Quote 0
                      • a_blockA
                        a_block
                        last edited by

                        Sorry for joining in so late. And I think, all relevant points have already brought up.
                        I just wanted to add one twist or slightly different point of view:

                        c4dpy is a so to say "standalone python interpreter" with access to Cineama 4D's api.

                        Actually c4dpy is a full headless Cinema 4D, which can be used as a Python interpreter in IDEs.

                        Cheers,
                        Andreas

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

                          @a_block

                          Thanks for the response. Am I correct to say that Sublime is not yet supported currently for autocompletion? It's not included in the c4dpy documentation. Correct me if I'm wrong. but it only includes PyCharm and Visual Studio.

                          1 Reply Last reply Reply Quote 0
                          • mikeudinM
                            mikeudin
                            last edited by

                            @bentraje said in Execute a Python Code Within PyCharm that Connects to C4D?:

                            Am I correct to say that Sublime is not yet supported currently for autocompletion?

                            Well, there is a plug-in.
                            But it needs to be updated for Cinema 4D R20.

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

                            1 Reply Last reply Reply Quote 1
                            • a_blockA
                              a_block
                              last edited by

                              @bentraje
                              Probably mikeudin is right. I have never checked Sublime in this regard, though it's certainly a very nice editor. c4dpy itself can probably be used with other IDEs (like for example Ultra Edit Studio) as well, it's just that we only documented, what we tested here. But unfortunately we can only provide support for what we tested here, so with other IDEs you'd be either on your own or would need to rely on our forum community.

                              Cheers,
                              Andreas

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

                                Thanks for the confirmation @a_block

                                Will hope for the best in the future regarding sublime

                                Have a great a day ahead!

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