# How to find python source code for an operator preset

I'm new to python and Blender and sometimes I find strange things. My problem is I'm trying to understand an operator behavior but something's missing. I'm in this situation:

I select a mesh outside edges then I call a grid fill operator. Then the operator runs and I'm presented with the filled mesh and the parameter window where I can change values.

I'd like to know how that value, precisely "12", is set. From tests I did, it looks like it's something related to the number of selected edges, and changes every time geometry is changed. To correctly use the operator, I need to know how it's set, hence my question: how can I find that operator preset source code? Mind, I'm not asking about this:

I already know that. I'm asking where is the source code which sets the "12" value. Thank you.

• At a first glance, I guess the value is calculated on the fly. based on the selection, there is no preset (in this case). You can find the UI code for MESH_OT_fill_grid operator in source/blender/editors/mesh and the function bm_grid_fill in source/blender/bmesh/operators/bmo_fill_grid.c. That's exposed to the python api as ...mesh.fill_grid() with a span default value of 1 as you can see in the console or here: docs.blender.org/api/blender_python_api_current/… – brockmann Apr 18 '18 at 17:51
• Thank you, your suggestion is correct. I've checked briefly but still no luck. I'll be checking it better next time or I'll debug it... – Kabu Apr 19 '18 at 13:45
• Still not sure where your "confusion" comes from. Most (interactive) operators written in C for speed reasons. However, by design we can call all operators, no matter if the operator is written in python or c, the same way bpy.ops.CATEGORY.NAME, what's actually pretty nice. Why you are out of "luck"? Blenders API is well designed compared to others IMHO. – brockmann Apr 19 '18 at 15:29
• I was referring to that preset value of "12". In the C code (mind, I'm not completely sure) I didn't found where it is calculated... most probably based on selection, that what I want to find, so I could understand how the choice is made for different kinds of objects... just this... for all the rest, your hints are right.. I think you can post the solution – Kabu Apr 19 '18 at 15:36

following advice by brockmann, here is the code (from editmesh_tools.c in source/blender/editors/mesh)

const int clamp = em->bm->totvertsel;
int span;
int offset;

if (RNA_property_is_set(op->ptr, prop_span)) {
span = RNA_property_int_get(op->ptr, prop_span);
span = min_ii(span, (clamp / 2) - 1);
calc_span = false;
}
else {
span = clamp / 4;
calc_span = true;
}


so it appears span is the number total vertex divided by 4. The value is then modified by another utility which extract two loops from a single one dividing geometry by angle. Everything is done for you if you call bpy.ops.mesh.fill_grid() from a script.