pass Variable from After Effects to C4D
-
Hello friends,
i have developed a script that should send some arguments from after effects to cinema4D. I tried over the terminal to open cinema and run my python script file.
So far so good, but how I can pass to my c4d python script some arguments?open -a cinemaAppPath myPythonScriptPath
Do have a idea or a reference this?
Thanks for your help
Cinema2024 / MacOS Ventura M1 -
Hey @Tudor,
Thank you for reaching out to us. I struggle a bit with your "is" state here as you seem to indicate that your terminal statement does work - but it cannot as Cinema 4D is incapable of doing that.
open
instructs an app to open a given file just asFile > Open
would in that app. Cinema 4D cannot open*.py
files in this manner (because there is no such thing as aPythonLoader
), the only file types that can be opened in this manner are scenes (c4d, fbx, obj, etc.) and media files (bmp, tif, png, avi, mp4, etc.). Cinema 4D has also not a command line argument with which you could pass it a script which would then be run. I talked once with @m_adam about adding that, but that never came to pass AFAIK (because c4dpy does exist).When you want to run Python code in Cinema 4D without any user interactions, you must use c4dpy. Command line arguments work there exactly like in any other Python interpreter (with
sys.argv
).hello_world.py
import c4d import sys if __name__ == '__main__': print(f"'Hello World!' with {c4d} and the command line arguments: {sys.argv}")
terminal
f_hoppe@MXBHOSX1454 % "/Applications/Maxon Cinema 4D 2024.4.0/c4dpy.app/Contents/MacOS/c4dpy" /Users/f_hoppe/Documents/code/hello_world.py -foo test -bar 1 ... 'Hello World!' with <module 'c4d' (built-in)> and the command line arguments: ['/Users/f_hoppe/Documents/code/hello_world.py', '-foo', 'test', '-bar', '1'] f_hoppe@MXBHOSX1454 %
Helpful in this context might also be this posting, especially regarding the fact the
c4dpy
environment is not identical to a Script Manager script environment (things likeop
,doc
, etc are not predefined). You are of course also bound by the headless nature ofc4dpy
, i.e., everything GUI related is off-limits.Cheers,
Ferdinand -
@ferdinand Hey, lot thanks for your help and suggestions but i'm still confused.
My first try to run my python script through the terminal still work for me.
Cinema app starts, run the PythonScript and print the value.open -a cinemaAppPath myPythonScriptPath
myPythonScript
import c4d def main(): print("Hello World") if __name__ == "__main__": main()
But otherwise I don't get any output in the cinema console if I run that over c4dpy.
I'm not sure but its also not very user-friendly to enter the license method and than it take some time for the process. -
Hey @Tudor,
When I tried to do what you claim works for you, Cinema 4D said for me that it does not support the file format "*.py" - which makes sense since Cinema 4D has no such importer node. Please clarify which command you do run explicitly.
c4dpy
also does not output to the Cinema 4D console. It is a standalone application, please read the manual I have linked above. You can also see the output ofc4dpy
in the example terminal output I have posted above.Cheers,
Ferdinand -
@ferdinand I use the Script above myPythonScript
It runs fine, I start it over:
Extensions > user Script or
File > open Project or
Terminal on mac > open -a cinemaAppPath myPythonScriptPath
and it works also on window over command line. -
This post is deleted! -
Hi with Cinema4D you can pass an absolute path to a python script, and it will be executed.
You do not need any other argument just"Cinema 4D.exe" {ABSOLUTE_PATH_TO_PYTHON_FILES.py}
.Note that this only work with Cinema 4D and not commandline ore c4dpy.
Cheers,
Maxime.