Execute a Python Code Within PyCharm that Connects to C4D?
-
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 -
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=0If C4D and Pycharm is connected, the
Hello World
should be present both in PyCharm and C4D -
Oh hey, now I understand you.
You get indeed a reaction from c4dpy, it is written in you PyCharm console, namelyHello 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. -
You need something like this solution for Sublime Text
Maybe you can adapt that code, fork repo and create what you need for PyCharm. -
@mikeudin That would require him to write an own listener plugin. I believe, that is way out of scope.
-
@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 momentThanks 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.
-
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 -
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.
-
@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. -
@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 -
Thanks for the confirmation @a_block
Will hope for the best in the future regarding sublime
Have a great a day ahead!