Python plugin and Linux CLR arguments
-
Hello,
I am currently trying to export the render settings from a .c4d file with python on Linux. If I'm not mistaken the only way to achieve this on Linux is to write a .pyp plugin that reads commandline arguments as explained here and use a special flag to activate a settings exporting script.
However I couldn't get any output in the console with that type of plugin, even with the example from the docs. Is it possible to use such a plugin on the Linux CLR version of c4d ?I tried the plugins with both S24 and R23 versions in a docker container based on Ubuntu 18.04. Rendering (with Arnold or Redshift) works fine.
Any help would be greatly appreciated.
Best regards, -
Hi,
while with c4dpy you can execute a python script, the command-line render doesn't.
if you try to create a plugin, PluginMessage will be called before your document is loaded, so you will only have access to the default document.The workaround is to load yourself the document in the PluginMessage:
The problem I see is that if your project has plugins, you are not guarantee that they will be already loaded.import c4d import sys from datetime import datetime from contextlib import redirect_stdout import os.path def PluginMessage(id, data): if id==c4d.C4DPL_COMMANDLINEARGS: # react to command line arguments # redirect the print to a file with open('d:\\log.txt', 'w') as f: with redirect_stdout(f): # now we can use print to directly print to the file print(datetime.now(), sys.argv) #print arguments fileName = sys.argv[0] if os.path.isfile(fileName): flags = c4d.SCENEFILTER_OBJECTS # open the document doc = c4d.documents.LoadDocument(fileName, flags) if doc is None: print (datetime.now(), "file {} not loaded".format(fileName)) return True print (datetime.now(), "file {} loaded".format(fileName)) # retrieve the active render settings rd = doc.GetActiveRenderData() if rd is None: print (datetime.now(), "can't retrieve the render settings") return True # access render settings print (datetime.now(), "Resolution of the current file ", rd[c4d.RDATA_XRES], rd[c4d.RDATA_YRES]) # close the document c4d.documents.KillDocument(doc) else: print (datetime.now(), "file {} not loaded".format(fileName)) print (datetime.now(), "finished") return True return False
If you still want to render the document, you can get inspired by our c++ example
What's the issue you are facing? there's maybe another way of doing it.
Cheers,
Manuel -
Thanks for the answer and the example.
The goal is to get the render settings and a few other parameters from a file without rendering it. I have to do it on linux so the ways to achieve it are limited.
With your plugin code I had the same results I had with the example from the documentation, nothing happened and I had the message
Warning! Unknown arguments:
right before C4D END.I install these plugins by putting the .pyp file in
/opt/maxon/cinema4dr23.110/bin/plugins
but they don't seem to load. On the other hand rendering plugins seem to load and work just fine. I also had to export the envvarg_modulePath=/opt/maxon/cinema4dr23.110/bin
for the rendering plugins to load.
Am I missing any step when adding a python plugin ?Best regards,
-
Hi,
I also have that bad argument, but the plugin is working fine using g_additionalModulePath=/media/val/empty/cmd_plugin/
the above code but with a correct path for my linux virtual machine.
with open('/media/val/empty/log.txt', 'w') as f:
./Commandline /media/val/empty/test.c4d g_additionalModulePath=/media/val/empty/cmd_plugin/
1- The render works and the log.txt is created. Just to be sure, did you execute bin/setup_c4d_env?
2 - If you just use the commandline to render a file, it works?In any case the command line render isn't created to gather information about files. Wine/c4dpy could be a better solution for that case, but you could have some issue with some rendering modules.
Cheers,
Manuel -
Hello,
Adding the path to the plugin in g_additionalModulePath fixed the issue.Thank you very much for your help.