Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    pass Variable from After Effects to C4D

    Cinema 4D SDK
    python macos 2024
    3
    7
    1.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Tudor
      last edited by

      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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Tudor
        last edited by ferdinand

        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 as File > Open would in that app. Cinema 4D cannot open *.py files in this manner (because there is no such thing as a PythonLoader), 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 like op, doc, etc are not predefined). You are of course also bound by the headless nature of c4dpy, i.e., everything GUI related is off-limits.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        T 1 Reply Last reply Reply Quote 0
        • T
          Tudor @ferdinand
          last edited by

          @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.

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @Tudor
            last edited by ferdinand

            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 of c4dpy in the example terminal output I have posted above.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            T 1 Reply Last reply Reply Quote 0
            • T
              Tudor @ferdinand
              last edited by Tudor

              @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.

              T 1 Reply Last reply Reply Quote 0
              • T
                Tudor @Tudor
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • M
                  m_adam
                  last edited by m_adam

                  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.

                  MAXON SDK Specialist

                  Development Blog, MAXON Registered Developer

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post