how to close c4dpy inside a script?
- 
 I am using command-line to execute a C4D script through c4dpy.exe. I want to close c4dpy after the script execution completes. How can I do this? def main(): parser = argparse.ArgumentParser() parser.add_argument('--args', type=str, help='argument to be passed') args = parser.parse_args() if args.args: print(f'Received argument: {args.args}') # quit c4d? c4d.CallCommand(12104)In addition, I am rendering a octane scene in this script, but sometimes the rendering process keeps running and it is unclear whether it is a bug in c4dpy or if I am using c4dpy incorrectly. import c4d import os class RenderAgent: def __init__(self): self.progress = 0 def render(self, doc, save_path=None, thread=None): self.progress = 0 rd = doc.GetActiveRenderData() rd[c4d.RDATA_ALPHACHANNEL] = 1 bmp = c4d.bitmaps.MultipassBitmap(int(rd[c4d.RDATA_XRES]), int(rd[c4d.RDATA_YRES]), c4d.COLORMODE_RGB) bmp.AddChannel(True, True) # Renders the document if thread: thread = thread.Get() if c4d.documents.RenderDocument(doc, rd.GetData(), bmp, c4d.RENDERFLAGS_EXTERNAL, thread, prog=self.PythonCallBack, wprog=self.PythonWriteCallBack) != c4d.RENDERRESULT_OK: #print("Failed to render the temporary document.") return False if save_path: bmp.Save(save_path, c4d.FILTER_PNG, data=None, savebits=c4d.SAVEBIT_ALPHA) return bmp def PythonCallBack(self, progress, progress_type): self.progress = float(int(progress*100)) if self.progress>100: self.progress = 100 print(self.progress) # !! # When i print self.progress inside octane renderer scene (Actually, I am using a logging module. It can redirect the print output to an external log.txt file.) # it will still return 0 after it return 100 # It seems that the renderer has entered an infinite loop. def PythonWriteCallBack(self, mode, bmp, fn, mainImage, frame, renderTime, streamnum, streamname): ... # call this in c4dpy # simple code RA = RenderAgent() save_path = r"..." RA.render(doc, save_path)my log file looks like this: LEVEL:1 - 2023-05-06 16:10:23 rendering start LEVEL:1 - 2023-05-06 16:10:23 rendering:0.0 # ... (rendering LEVEL:1 - 2023-05-06 16:10:23 rendering:100.0 # it seems like render finished but LEVEL:1 - 2023-05-06 16:10:23 rendering:0.0 LEVEL:1 - 2023-05-06 16:10:23 rendering:0.0 ... # (it keeps output 0.0
- 
 Hello @JACK0319, Thank you for reaching out to us. As announced here, Maxon is currently conducting a company meeting. Please understand that our capability to answer questions is therefore limited at the moment. Your question is a bit ambiguous since you do not disclose how you invoke your code, but I assume you are passing the script as an argument to the c4dpy executable. # Content of test.py import c4d print (f"I am a script using the '{c4d.__name__}' module.") In this case, the c4dpyexecutable will terminate itself once the script has exited, just as a vanillaCPythonwould. If you use c4dpy as a REPL interpreter instead, you must use the commonexit()function. You can also use this function in a script, but some people (me included) would consider usingexit()in a script bad style. But in your case the problem seems to be that c4d.documents.RenderDocumentnever terminates the render loop. I would recommend to:- Put a print or log statement after your RenderDocumentso that you can unambiguously see if the function is ever exited or not.
- Check if the same problem does also occur when your invoke the script from the Script Manager.
- Check if the same problem does also occur when you use the Standard Renderer as the render engine (or Redshift).
 Cheers, 
 Ferdinand
- Put a print or log statement after your 
- 
 Hello @JACK0319, without further questions or postings, we will consider this topic as solved by Monday 05/06/2023 and flag it accordingly. Thank you for your understanding, 
 Maxime.
