Cython, return BaseContainer

On 19/07/2015 at 22:20, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   16 
Platform:   Windows  ;   
Language(s) :     C++  ;   PYTHON  ;


I'm  trying to understand how to use reinterpret_cast to grab data from one class to other.
I have packed gvnode in ui and trying to make concept of py-module.

I have function, which return BaseContainer Class from reinterpret_cast gvnode,
something like:
void foo()
> _node stuff
> ...
> BaseContainer* bca = node->GetOpContainerInstance();
> return bca;
> _


** _cdef extern from "getbc.cpp":
> void foo()
i stack how properly work with such stuff. I read several tutorials, but** don't understand a few things

On 20/07/2015 at 11:21, xxxxxxxx wrote:

I'm starting to write concept for c4dtoa api py module ... i have small experience of py-binding with several projects(not for c4d)

Will post as text code. Lets start, small dirty code

Question i stack with BaseMaterial in c4dtoa.pyx. I still don't understand some things in cython

build.bat :

set MSSdk=1  
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"  
python.exe build_ext --inplace  

# -*- coding: utf-8 -*-  
from distutils.core import setup  
from Cython.Build import cythonize  
setup(ext_modules = cythonize(  
         "c4dtoa.pyx",                 # our Cython sourc  
         sources=["aGetNode.cpp"],  # additional source file(s)  
         language="c++",             # generate C++ code  


# -*- coding: utf-8 -*-  
cdef extern from "c4d_basematerial.h":  
  ctypedef struct BaseMaterial:  
  ctypedef void* BaseMaterial  
cdef extern from "aGetNode.h":  
  void aGetNode(BaseMaterial* material)  
def a_Get_Node(material) :  
  print "true"  
  cdef BaseMaterial material  


#include "c4d.h"  
#include "aGetNode.h"  
void C4DTOA::aGetNode(BaseMaterial * material)  
  if(!material)  return FALSE;  
  GePrint("Init mat");  
  BaseContainer* bc = material->GetDataInstance();  
  BaseLink* bl = bc->GetBaseLink(C4DAI_SNMATERIAL_SHADER_NODE);  
  if (bl)  
    GvNode* bl2d = reinterpret_cast<GvNode*>(bl->GetLink(material->GetDocument()));  
    if (bl2d)  
      BaseContainer* bca = bl2d->GetOpContainerInstance();   
    GePrint("No link");  


#include "c4d.h"  
#include "c4d_basematerial.h"  
namespace c4dtoa {  
  class C4DTOA {  
      virtual void aGetNode(BaseMaterial* material);  

On 21/07/2015 at 00:16, xxxxxxxx wrote:

Has anybody try to cythonize c4d stuff in modules? Or need to use pythonLibrary?



 # -\*- coding: utf-8 -\*-  
cdef extern from "c4dapi/c4d_basematerial.h":  
	cdef cppclass BaseMaterial:  
		void BaseMaterial()

I reread docs, add Basematerial... still can't to understand how point at mat?!

On 21/07/2015 at 10:13, xxxxxxxx wrote:

Hi Ilya,

I'm sorry, but SDK Support team won't be of much help here. Not only is this beyond our scope, but even worse, none of us has played around with Cython, yet. Sorry.
Hopefully we have a knowing member in our community.

On 21/07/2015 at 10:28, xxxxxxxx wrote:

Hello Andreas
Thank you for answer.

I have dialog with coworker, he wrote need more attention at description of class and wrap c++ to cython another way.

I started with something "complex", will to prepare simple dummy for understanding of c4d stuff binding

Why i start? I found pyapi methods - c4d.bc.GetLink or .GetObjectLink - are not work for me and checkout your method(discussion with Mohamed Sakr) in c++ and it works(thank for that). I mean - GetBaseLink and etc. And i'm trying expand pyapi of c4d

Hopefully we have a knowing member in our community.

Probably i know 2 persons and they are Sebastian Rath(father 😉 of pyC4D) and Niklas Rosenstein(he brought one latest cython build, gave this cyber "drug"  and has wonderful examples at his git) Clap

On 22/07/2015 at 00:05, xxxxxxxx wrote:

One little or tiny progress is being... but not all work, sad thing

i read several questions at stackover flow , a few coders extract function from cpp, not from headers like me(i tried - many faults)... before i use dll to linking for some cad tools, thinking, that's my fault. I also not often compile cython modules -> low experience of it.

On 23/07/2015 at 13:36, xxxxxxxx wrote:

Hey Ilya,

getting Cython and the Cinema 4D C++ API work together will be a tough task. You must use the
PythonLibrary  in lib_py.cpp  to translate Cinema 4D C++ objects to Python objects and the reverse.
In order to use the Cinema 4D API from your Cython Module, it needs access to the C4DOS which is
the all-mighty function table for all the API calls in the C4D SDK. You need to find someway to initialize
the C4DOS inside your Cython module.


On 23/07/2015 at 16:21, xxxxxxxx wrote:

Hi Niklas

getting Cython and the Cinema 4D C++ API work together will be a tough task

Yes, but one thing i understand that needs to prepare numerous pxd-files to reconstruct or convert/translate c4dstuff to cython stuff or any 3dparty sdk >> to get classes, functions and etc. then prepare in pyx(not all we can get from c4d module)
(i'm playing with autopxd stuff like xdress >> to simplify my life 😉)

i get  a few working things, like in-line stuff(in functions with pre-/faked c4d module, closer to "pure python mode")... only something needs  from headers of sdk(c4d or arnold) to bring new functions

You must use the PythonLibrary  in lib_py.cpp  to translate Cinema 4D C++ objects to Python objects and the reverse.

Thanks, soon, i will. I saw your APEX(-tension) and remember your questions about it > sdk teamer wrote that it "poor" documented or something like