Best strategy for VS Code debugging of Python Effectors (or other non-script Python) +
-
Hello,
I have been trying to figure out the best way for me to debug a Python Effector I am working on. So far, I have not found a way to connect my Python Effector code to VS Code like I do for Python scripts.
So the best I came up with so far is to try and run the Python Effect as a script by using the following structure:import c4d op: c4d.BaseObject # The Python Effector object containing this code. gen: c4d.BaseObject # The MoGraph Generator executing `op`. doc: c4d.documents.BaseDocument # The document `op` and `gen`are contained in. # ...... def main() -> bool: """ Regular Python effector code """ # The following is to run the effector as a script for debugging purposes. # This simply calls the if __name__ == '__main__': # This is used when we execute the script directly, not as a Python Effector op = doc.SearchObject("Python Effector to debug") gen = doc.SearchObject("Generator with active Python Effector to debug") main()
This seems like a convoluted way to go about debugging the Python Effector, but it is the best I have come up with so far. While it does allow me to step and debug the code, it does not allow me to see the effect, I assume because on the next scene renders, it seems the effect of my script is overridden by the regular generator execution.
My questions are:
- Is there a better way to debug Python Effector code? I have been trying to follow the documentation but I do not see anything about Python Effectors or Python Field Debugging.
- What is the best way to package a Python Effector for reuse across documents? I have not found a way to make it a plugin.
I appologise if I did not get deep enough in the documentation or if I am missing the obvious. I am fairly new to Python in Cinema 4D and this is my first question.
Thanks in advance for any help you can offer.
-
Hello @vhardy,
Welcome to the Maxon developers forum and its community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.
About your First Question
- The VS Code bridge currently only works for the script editor, not for the expressions editor. So, you cannot debug scripting elements from there (when debugging means attaching a debugger). You can of course just let them run and print statements or see errors being raised.
- What you do there, can be technically done, and effectors are somewhat a more sensible case as they can be somewhat be simulated like this. But generally this is not very feasible, you cannot simulate objects or tags like that. For effectors the problem is also that when Cinema 4D calls main() it will keep that MoGraph data you write there (i.e., continuously poll
main
). When you just invoke a script manager script, your changes will be volatile and erased by the next scene update. - When you want more debugging options, you can implement some scripting elements as full plugins, e.g., an object or tag, but that is not possible for the Python effector.
- The intended way share any form of settings, not only scripts, over document boundaries, are preset assets at the moment. You can just store a preset asset for a finished scripting element. You can then export them in asset database if you want to share them with someone else. As already mentioned, there is no full blown plugin counter part for effectors.
Cheers,
Ferdinand