0

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?

Luis
  • 109
  • 6
  • 1
    Does this help? https://blender.stackexchange.com/questions/20968/adding-blender-datapaths-together-as-strings-and-then-executing-the-resulting-st or this https://blender.stackexchange.com/questions/36781/calling-a-method-from-a-string ? – Ray Mairlot Apr 07 '20 at 19:49
  • 1
    getattr(bpy.ops.transform, prop, None) if prop = "foo" looks for bpy.ops.transform.foo and returns the operator callable or None if not defined. – batFINGER Apr 08 '20 at 06:02

0 Answers0