When calling an object's children from the Python API, where is the C/C++ that responds to this?

New to Blender development, and Python to C/C++ function interface programming but I’ve worked with Java to C++ (JNI) and JS to C++ in the past. I’ve been trying to understand what C/C++ code gets called when this python snippet, specifically the “obj.children”:

obj = context.object
for child in obj.children:
  print_id(child)

Is the context object the trojan for everything in the scene, so that getting the list of children is purely done in Python? I’ve debugged inside collection.cc and object.cc but I’m having trouble understanding how the Python API interfaces with the source C code.

Long story short, I want to add Blender support to a plugin that currently works with Maya, Max, and MotionBuilder, and the source is written in C++. So my idea is to build a dll and have Blender’s Python API be the middle man passing the objects to the DLL where they are converted to my generic types, then manipulated and sent back through the Python API.

Appreciate any guidance, and thanks in advanced.

1 Like

I think for what you are trying to do, how Blender makes the Python API interface with the C/C++ code should be irrelevant. That aspect is not part of the public API, nor would you be able to recreate it because it’s a quite custom system integrated with the rest of Blender.

Some relevant code is in rna_object.cc and bpy_rna.cc, but I don’t think it will help you much.

How to convert the Blender Python data structures to your C++ data structures would be up to you. I recommend using a library like nanobind.

4 Likes

Thanks for the reply, this clears up most of my questions (the rest I just have to resolve through experimenting). Also saves me the trouble of trying to recreate what the Python API already does since it’s quite a complex undertaking.