Blender 3D: Blending Into Python/Blender Python C API
Mini Unfinished Guide to adding a C/API extension[edit | edit source]
Add blurb- what this is good for etc.
Heres a mini tutorial
- Find a variable that you can not access from BPython
- Look for a button that modifies the value in the user interface
- Write down the buttons tooltip
- Use a find tool to find the Tooltip for the button in the source code (There are some source code searching tools you can get)
- The line with the tooltip will also reference a variable. Now you know what the variable name is for the button.
- Go into Python code folder and open the relevant C file (Lamp.c, Material.c etc.)
- Find a similar exististing variable in the c file- (e.g., if your setting a flag, then find another BPy function that sets a flag)
- Look for every instance of this variable, under each instance, copy it and replace the name with your new one. make the obvious modifications.
make sure to add the setattr and getattr values for class variable names. You don't have to do this, but you probably should eventually.
Recompile and test!
Sometimes not all variables are seen directly from the UI.
As fas as I know all blender datatypes are structs internally.
To find all the variables used by this DataType-
Look through the files in- Blender/source/blender/makesdna/...
They are named well and you can see all the variables.