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
    • Recent
    • Tags
    • Users
    • Login

    Python - c++ interoperability

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 247 Views
    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.
    • H Offline
      Helper
      last edited by

      On 01/02/2015 at 03:28, xxxxxxxx wrote:

      I wonder is there an easy way to call c++ functions from python in a way that translates references and pointers to api classes like baseobjects and such.

      I'm thinking of boost python http://www.boost.org/doc/libs/1_57_0/libs/python/doc/tutorial/doc/html/index.html here.

      So i could do in c++

        
      String HelloObject(BaseObject* op)   
      {   
      return op->GetName()   
      }   
        
      void Register()   
      {   
      MakeModule("test")   
      Wrap(HelloObject)   
      }   
      

      And in Python

        
      import test   
        
      someop = doc.GetFirstObject()   
      print test.HelloObject(someop)   
      

      I can do something similar less conveniently by abusing the messaging system (create plugin node, let it handle MSG_BASECONTAINER).

      I figured the facilities to enable this are already there because we have the wrapping of the c++ api.

      Also i'm very very curious how you wrapped the c++ api. boost python? low level c python api? swig? I attempted this like 10 years ago by myself. But i quickly gave up because i didn't know (and still don't) how to deal with ownership transfer between the c++ and python side. Hence my interest. For instance doc.InsertObject(op) would take the ownership, and the python object must not free the wrapped object. op.GetName() on the other hand preserves the ownership. Would you mind telling me how you deal with this? Also there are tons of api functions. I suspect that you use some kind of automatic wrapping leading me back to the problem of ownership. I have to say i'm very impressed by the python wrapping!

      Cheers,

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 02/02/2015 at 10:07, xxxxxxxx wrote:

        Hi Michael,

        The API library to extend Python with C++ (lib_py.h) isn't currently documented and is limited. It only allows to deal with basic data types.

        Note we cannot disclose any information on the implementation of Cinema 4D.

        Regards
        Yannick

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 03/02/2015 at 00:51, xxxxxxxx wrote:

          Well this is unfortunate. Thanks anyway.

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