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