3
$\begingroup$

To my knowledge, some built-in operators are written in python. This could be handy if I wanted to create a modified version of an operator for my add-on, since I could probably just copy the code and tweak it.

However, I don't know how to:

  1. tell if any operator is a python one
  2. find its code

In my particular case, I'd like to get the code for bpy.ops.scene.new(type='LINK_COPY') (provided it's a python operator) but of course a general method to find operator code would help more than just the code for this one for my future add-on projects.

$\endgroup$
7
  • 2
    $\begingroup$ stackoverflow.com/questions/20339053/… Re code recommend the inspect module. eg inspect.getsourcelines(bpy.types.CONSOLE_OT_banner) Possibly more a generic python question. $\endgroup$
    – batFINGER
    Commented Jun 4, 2020 at 0:20
  • $\begingroup$ Thanks for the tip. However, when I do this with an operator, e.g. inspect.getsourcelines(bpy.ops.scene.new()), I get a TypeError: module, class, method, function, traceback, frame, or code object was expected, got set' $\endgroup$ Commented Jun 4, 2020 at 17:00
  • $\begingroup$ To be expected? If you run op in console it prints {'FINISHED'} which is a set. I doubt also if the output of inspect.getsourcelines(bpy.ops.scene.new) will be that useful. Look at bpy.ops.scene.new.get_rna_type() Get the type bpy.types.SCENE_OT_new then look at the types execute method. Since there are no answers maybe rejig Q towards how to get the operator code. $\endgroup$
    – batFINGER
    Commented Jun 5, 2020 at 12:14
  • $\begingroup$ Sorry I don't know what you mean by the "types execute method" and I'm not sure about "rejig Q". I assume it means "clarify the original question and make it more specific"? $\endgroup$ Commented Jun 6, 2020 at 18:46
  • 1
    $\begingroup$ Feels like this is going in circles. That one is written in c. inspect will only give python source code. See comment 1... lol. $\endgroup$
    – batFINGER
    Commented Jun 7, 2020 at 11:10

0

You must log in to answer this question.

Browse other questions tagged .