What is the best way to locate a function from the bpy module in Blender's source code? I've downloaded the source code and I'm aware you can also browse through it online.
As an example, I would like to inspect bpy.ops.render.render().
What is the best way to locate a function from the bpy module in Blender's source code? I've downloaded the source code and I'm aware you can also browse through it online.
As an example, I would like to inspect bpy.ops.render.render().
Get the idname like:
bpy.ops.render.render.idname()
# 'RENDER_OT_render'
(or simply take render.render and replace the . by _OT_)
Search that operator in the source code, and find it here:
blender\source\blender\editors\render\render_internal.c
/* contextual render, using current scene, view3d? */
void RENDER_OT_render(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name = "Render";
ot->description = "Render active scene";
ot->idname = "RENDER_OT_render";
/* api callbacks */
ot->invoke = screen_render_invoke;
ot->modal = screen_render_modal;
ot->cancel = screen_render_cancel;
ot->exec = screen_render_exec;
You'll likely wanna look for the exec function code (screen_render_exec) and see what it does.
Python offers a module for live inspection. If the function is a python function located in a .py file, you can use these functions.
For example,
import bpy
import inspect
#get sourcefile of a panel
inspect.getfile(bpy.types.VIEW3D_PT_transform_orientations)
#...blender-2.69-windows64\blender-2.69-windows64\2.69\scripts\startup\bl_ui\space_view3d.py
bpy.data.texts.new('source').write(
inspect.getsource(bpy.types.VIEW3D_PT_transform_orientations)
)
(for the difference between .getfile and .getsourcefile see this post on stackoverflow)
inspect.getfile(bpy.ops.render.render) not work? I get a TypeError error saying it is not a module, class, method, function, traceback, frame, or code object.
– Garrett
Feb 09 '14 at 22:42
inspect.getfile() using a bpy.types class. So the proper call for an operator is inspect.getfile(getattr(bpy.types, bpy.ops.render.render.idname())), which will raise a TypeError: <RNA_Types object at 0x0000000003A875A0> is a built-in class. You need search it in the C code (see my answer where to find it).
– CodeManX
Feb 09 '14 at 22:55
idname()likebpy.types.Scenein the code? – McLawrence Sep 05 '17 at 09:05blenkernel,makesrnaandmakesdna: https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/BKE_scene.h / https://developer.blender.org/diffusion/B/browse/master/source/blender/makesdna/DNA_scene_types.h / https://developer.blender.org/diffusion/B/browse/master/source/blender/makesrna/intern/rna_scene.c / https://developer.blender.org/diffusion/B/browse/master/source/blender/makesrna/intern/rna_scene_api.c – CodeManX Sep 05 '17 at 09:42bpy.types.Scene()class – McLawrence Sep 05 '17 at 09:56rna_scene.c. Are you looking for the glue code that exposes the properties and methods to Python? – CodeManX Sep 05 '17 at 10:32intern/bpy.c:285https://goo.gl/RUkrYc (shortened URL because SO breaks Phabricator deep links). The Scene type is not exposed explicitly anywhere as far as I can tell, because it is part of the DNA/RNA system and all types are exposed my generic code to make the properties and functions defined in the C code available in the bpy python interface. If you need more information, I suggest to contact the Blender developers via IRC. – CodeManX Sep 05 '17 at 11:03