I'm trying to use loop-cut and slide in Python.
I've tried the following: Loop cut and slide using python script in blender How do I override context for bpy.ops.mesh.loopcut? Loop Cut and Slide using Python
The best I can get is "no error and no loop cut". -_- (new_outsideWall is a procedurally created object)
The following code selects the correct object, enters 3D view, goes to edit mode, does NOT generate a loop cut, exits edit mode and returns to previous screen view. No error at all.
I know it has something to do with either bpy.ops.mesh not targeting the correct mesh, or override not being in the right context. But being a complete noob, I have no idea how to fix, nor can I locate the answer.
Thanks.
In case you're wondering, I'm trying to create a "random building generator" and this is the adjustable cutout for the window textures. ^_^
old_type = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'
bpy.context.view_layer.objects.active = new_outsideWall
new_outsideWall.select_set(True)
bpy.ops.object.editmode_toggle()
def view3d_find( return_area = False ):
# returns first 3d view, normally we get from context
for area in bpy.context.window.screen.areas:
if area.type == 'VIEW_3D':
v3d = area.spaces[0]
rv3d = v3d.region_3d
for region in area.regions:
if region.type == 'WINDOW':
if return_area: return region, rv3d, v3d, area
return region, rv3d, v3d
return None, None
region, rv3d, v3d, area = view3d_find(True)
override = {
'scene' : bpy.context.scene,
'region' : region,
'area' : area,
'space' : v3d
}
bpy.ops.mesh.loopcut_slide(
override,
MESH_OT_loopcut = {
"number_cuts" : 1,
"smoothness" : 0,
"falloff" : 'INVERSE_SQUARE', # Was 'INVERSE_SQUARE' that does not exist
"edge_index" : 1,
"mesh_select_mode_init" : (True, False, False)
},
TRANSFORM_OT_edge_slide = {
"value" : 0,
"mirror" : False,
"snap" : False,
"snap_target" : 'CLOSEST',
"snap_point" : (0, 0, 0),
"snap_align" : False,
"snap_normal" : (0, 0, 0),
"correct_uv" : False,
"release_confirm" : False,
"use_accurate" : False
}
)
bpy.ops.object.editmode_toggle()
bpy.context.area.type = old_type
{'CANCELLED}
ie doing nada. $\endgroup$