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

    Is example ExecutePythonScript() also avialable in R19

    Cinema 4D SDK
    r19 c++ python sdk
    3
    4
    467
    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.
    • P
      pim
      last edited by

      Maxime pointed me this great example ExecutePythonScript() of running a python script from c++.
      See https://developers.maxon.net/forum/topic/12439/reading-script-file-into-memory/4

      I succeeded to compile this example in R20.
      Now, because we still have user running R19, I want to do the same in R19.

      Is this possible?
      Is there a similar example for R19.
      Especially, setting scope variables is really good and what I need.

      I can use the example from https://developers.maxon.net/forum/topic/8164/10638_can-c-execute-python-solved/5, but that one does not support scope variables (I guess).

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        The interfaces used in the ExecutePythonScript() are part of the python.framework, which was introduced with R20. So I guess that there is nothing equivalent in prior versions.

        1 Reply Last reply Reply Quote 0
        • P
          pim
          last edited by

          Yes, I think so too.
          Thanks.

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hi Pim sorry for the late reply, this is possible by using the lib_py.h (typically this is somehow what we used before R20 to expose feature in python, but it's way elder, not everything is possible to do, you have less control than with the new python.framework, and the lib_py.h is not maintained (so don't expect any enhancement in it) Only the python.framework will be enhanced.

            // Init Python
            GePython pythonScope;
            pythonScope.Init();
            
            // Acquiere the GIL
            GePythonGIL gil_state;
            
            pythonScope.SetNode("doc", doc);
            // If doc->GetFirstObject() is nullptr, op variable will not be declared in the python scope, and you cant add a None.
            pythonScope.SetNode("op", doc->GetFirstObject());
            
            maxon::String pythonCode = "\
            import c4d\n\
            \n\
            def main():\n\
                print(doc, op)\n\
            \n\
            if __name__ == '__main__' :\n\
                main()\n\
            "_s;
            
            StopAllThreads();
            pythonScope.Run(pythonCode);
            

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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