7
$\begingroup$

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().

$\endgroup$
10
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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)

$\endgroup$
  • $\begingroup$ Why does 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. $\endgroup$ – Garrett Feb 9 '14 at 22:42
  • 1
    $\begingroup$ pink vertex's example shows 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). $\endgroup$ – CoDEmanX Feb 9 '14 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.