Thanks a lot!
I did more homework in the mean time and I found a similar answer on the following thread: https://blender.stackexchange.com/questions/43060/loop-cut-and-slide-using-python with a small correction on this one: https://blender.stackexchange.com/questions/160739/loop-cut-and-slide-using-python-not-working/164563#164563.
Since then I found another issue I have not solved yet:
I do not know on which faces the loopcuts will come when I do it with python.
There is a parameter called edge_index that seems to control it, and I have not found a description of how to use it.
I have created the following script to try to investigate the issue, and there is too much data for me to have a conclusion I can use. Here is the script:
# this override code works!
# From https://blender.stackexchange.com/questions/43060/loop-cut-and-slide-using-python
# and
# from https://blender.stackexchange.com/questions/160739/loop-cut-and-slide-using-python-not-working/164563#164563
import bpy
import time
import os
import pprint
os.system("cls")
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
}
##### START OF deselect All Objects FUNCTION
def deselectAllObjects():
# from https://blenderartists.org/t/element-selected-in-outliner-and-i-dont-want-it-to-be/1296825/3
for selected in bpy.context.selected_objects:
selected.select_set(False)
##### END OF deselect All Objects FUNCTION
##### START OF selectObjectByName FUNCTION
def selectObjectByName(objectToSelect):
## deselect all (just in case?) then select and activate ReferenceThickLine WITHOUT USING bpy.ops
# from https://blenderartists.org/t/element-selected-in-outliner-and-i-dont-want-it-to-be/1296825/3
for selected in bpy.context.selected_objects:
selected.select_set(False)
newObject = bpy.data.objects[objectToSelect]
newObject.select_set(True)
bpy.context.view_layer.objects.active = newObject
# other code to select only one object, using bpy.ops...
# from https://blenderartists.org/t/element-selected-in-outliner-and-i-dont-want-it-to-be/1296825/3
# don't run it, the one above works too
#bpy.ops.object.select_all(action='DESELECT')
#obj = bpy.data.objects["ReferenceThickLine"]
#obj.select_set(True)
#bpy.context.view_layer.objects.active = obj
##### END OF selectObjectByName FUNCTION
#### START OF PUTLOOPCUTS(2) FUNCTION
def putLoopCuts(kGiven, numCutsGiven):
bpy.ops.mesh.loopcut_slide(
override,
MESH_OT_loopcut = {
"object_index" : 0,
"number_cuts" : numCutsGiven,
"smoothness" : 0,
"falloff" : 'SMOOTH',
"edge_index" : kGiven,
"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
}
)
#### END OF PUTLOOPCUTS(2) FUNCTION
#### START OF DELETEALLOBJECTS() FUNCTION
def deleteAllObjects():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
#### END OF DELETEALLOBJECTS() FUNCTION
def main():
numberOfLoopcuts = 3
deleteAllObjects()
startTime = time.time()
print("At start of let's have fun: STARTING at", startTime)
deselectAllObjects()
cubeNumber = 0
for i in range(20):
for j in range(20):
bpy.ops.mesh.primitive_cube_add(enter_editmode=True, location = ((j - 0) * 4 + 1, -i * 4 - 1, 0))
bpy.context.object.name = "cube_" + str(cubeNumber) + "_" + str(i) + "_" + str(j) + "_"
cubeNumber += 1
for k in range(i, j + 1):
print(" 126 Doing k from", i, "to", (j + 1), ":", k)
putLoopCuts(k, numberOfLoopcuts)
bpy.context.object.name += str(k)
print("120 Doing i:j", i, ":", j, ":", bpy.context.object.name)
bpy.ops.object.editmode_toggle()
main()
Any ideas!