SOLVED Python Plugin Development

Hi everyone, im developing for my company a plugin that runs against the commandline. Now im encountering some problems, because i do not get any errors on executing my plugin. It just aborts silently during the load process.

I tried to debug it with the console in the GUI, but to no avail. It shows me some syntax errors in the main file, but once those are fixed, it just presents the plugin_name.pyp in the Plugin Manager and "all is fine". Except for my plugin that refuses to work. I have a very old version, without external dependencies that works. After that, i moved lots of code into a external folder at C:\Users***\AppData\Roaming\Maxon\python27\libs\VC4D. Which for some time worked until it did not. I tryied to revert to older working versions, as in go to older versions of the plugin.pyp and the libs folder. Which produced the same error.

I also tried to ouput a log, but it is just the cmd log dropped after the other plugins load (VRay, etc.).
My assumption is that somewhere in the load process something fails but without creating a error.

How do i get my plugin to drop python errors and messages again?

Regards Florian
[expanded and clarified 31.03.2022]

edited by @ferdinand

Ongoing Debugging:

If i add any random non existant function to the mainbody, i get a erorr such as : Traceback (most recent call last):

NameError:name 'whatever' is not defined
Traceback (most recent call last):

If i do the same to the libs folder i get no such error.
I tryied the cinema4d specific folders, same outcome.

I tryied something else and removed a 2nd python installation i had.
Now i get a error 🐶

def PluginMessage(id, data):
  print("commandLineID: " + id)

So i spiked my PluginMessage handler with output like this:

if PluginMessage(id, data):
  print("commandLineID: " + str(id) + " but needs to be " + str(c4d.C4DPL_COMMANDLINEARGS))

Turns out in never got any arguments and just quit.
commandLineID: 1002 but needs to be 1002
Aborting no input.So thee commandline arguments i hand down, never reach the ears of the plugin.

import io.. yes i shouldnt remove that one

Hello @fss,

welcome to the Plugin Café and thank you for reaching out to us. I would recommend taking a look at our Forum Guidelines, as these line out some of the procedures used in the forum and features of the forum.

Most importantly you can use standard Markdown syntax in the forum to format your content for example with links or code markup, making things more readable. Without wanting to sound too harsh on your first posting, I must also point out that we cannot allow diary style topics, as this will make them very hard to read and answer for others. I have consolidated your postings in this case for you. You should ask a single question in a single topic, when you have more than one question, you should open multiple topics.

About your questions

There seem to be multiple things going wrong in your plugin, but one of the root causes seems to be imports not working. Please note that we do not provide any third-party library support for Python, as declared in the forum guidelines. I cannot help you debug your problems with a specific library, but we can look for some general causes.

It is in principal a bit odd that you do host the libraries for a plugin in AppData\Roaming\Maxon\python27\libs since this location is more meant for shared libraries. In case of a plugin you should ship the libraries with the plugin and use something like python-localimport or just modify sys.path manually.

Given your current solution:

  1. Could you please print out all sys.path items in the console of Cinema 4D? Feel free to obfuscate the start of directories, but please include all elements.
  2. I assume you have a CPython 2.7 installation on your machine?
  3. Have you used pip in conjunction with the Python of Cinema 4D?

There is and was a bug in our Cinema 4D Python interpreter that it will always assume the fixed path \AppData\Roaming\Python\{PYTHON_VERSION}\ to be part of sys.path, as this is what CPython does. This can lead to shared libraries, i.e., that Cinema 4D will see and be able to use libraries thar have been installed with a vanilla CPython interpreter of the same version on the users machine (2.7). So, when you installed numpy on your vanilla CPython 2.7, you could suddenly access numpy in Cinema 4D R21, but as soon as you uninstall numpy from the CPython installation, it also stops working in Cinema 4D. A fix for this problem will be released in an upcoming version of Cinema 4D, but we cannot propagate it back to R21.

It sounds a bit like you are encountering this. To receive further help, you should post more code, as we cannot follow your train of thought in this raw form.


Hi Ferdinand, thank you for your reply.
You were indeed correct, my imports were not working due to bugs. If software bugs had protein, i alone could end world hunger.

I was able to solve them after providing the
-nogui argument, which then piped out the errors again to the commandline. This worked without in the old version of the plugin, due to it not using any imports besides the local ones (none in the \AppData\Roaming\Python\{PYTHON_VERSION}). As a result the commandline put out errors. If using imports though, the commandline swallowed the output (error+stacktrace) and stayed blank until the plugin was erroring out and the system continued with other plugin calls and the CONSTRING NOT FREED at the end.