This follows my question "Accessing Transform Operator History inclusive constraint_axis in Python script"
As you can see, I get an operator from the "history" stored in C.window_manager.operators inclusive properties:
lastoplist = []
if len(C.window_manager.operators[:]) > 0:
lastop = C.window_manager.operators[:]
lenop = len(C.window_manager.operators[:]) * -1
ic = -1
while ic > lenop:
if "TRANSFORM" in str(lastop[ic]):
lastopicstr = str(lastop[ic])
lastopic = lastop[ic]
lastoplist.append(lastopic)
lastopattr = getattr(lastopic, "bl_idname")
ip = C.window_manager.operator_properties_last(getattr(lastop[ic], "bl_idname"))
ic = lenop
else:
ic = ic - 1
if len(lastoplist) == 0:
print ("No Transformations!") else:
print (lastopic)
lastopicstr = str(lastopic).split('"')[1].split('_')[-1]
print ("lastopicstr:", lastopicstr)
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
""" The result should work like this but with a operator matching the fetched one: """
bpy.ops.transform.translate('INVOKE_DEFAULT')
Here is how I tried to reinvoke the operator:
""" Here come all my weak attempts to invoke the fetched operator: """
lastopic('INVOKE_DEFAULT')
bpy.ops.transform.lastopicstr('INVOKE_DEFAULT')
"bpy.ops.transform." + str(lastopicstr) + "('INVOKE_DEFAULT')"
bpy.ops.transform.str(lastopicstr)('INVOKE_DEFAULT')
bpy.ops.transform.lastopic('INVOKE_DEFAULT')
bpy.ops.transform.lastop[ic]('INVOKE_DEFAULT')
How could I get this done?
getattr(bpy.ops.transform, prop, None)ifprop = "foo"looks forbpy.ops.transform.fooand returns the operator callable orNoneif not defined. – batFINGER Apr 08 '20 at 06:02