The answer is in the example code.
When executed over the splash screen button, it prints to console
Note have added
def dump(obj, text):
print(text, obj)
...
to the dump method to inform which of the button context members are not None
button_operator <bpy_struct, WM_OT_splash at 0x7f474dff47e8>
<bpy_struct, WM_OT_splash at 0x7f474dff47e8>.__doc__ = None
<bpy_struct, WM_OT_splash at 0x7f474dff47e8>.__module__ = bpy.types
<bpy_struct, WM_OT_splash at 0x7f474dff47e8>.__slots__ = ()
<bpy_struct, WM_OT_splash at 0x7f474dff47e8>.bl_rna = <bpy_struct, Struct("WM_OT_splash") at 0x7f477da08e48>
<bpy_struct, WM_OT_splash at 0x7f474dff47e8>.rna_type = <bpy_struct, Struct("WM_OT_splash") at 0x7f477da08e48>
Going by blenders naming convention the class instance above of WM_OT_splash
correlates to window manager operator type splash --> the registered operator bpy.ops.wm.splash()
with bl_idname = "wm.splash"
.
Ok can change up the script to get the operator from the button context.
def execute(self, context):
op = getattr(context, "button_operator")
if op:
print(op)
return {'FINISHED'}
Lets run this new code over the run script button
<bpy_struct, TEXT_OT_run_script at 0x7f9606bf4a68>
Looks familiar off to the python console. Examples of the active operator (last registered operator run) and how to get the options used in the last run of the operator. IMO the py console is a great place to peck around and work out how things work. The example script that prints the dir of available properties is another
>>> op = C.active_operator
>>> op
<bpy_struct, Operator("TEXT_OT_run_script") at 0x7f4755ffa708>
>>> op.rna_type
<bpy_struct, Struct("TEXT_OT_run_script") at 0x7f477c30cde8>
>>> C.window_manager.operator_properties_last("text.run_script")
<bpy_struct, TEXT_OT_run_script at 0x7f9606bf4b08>
To get there quickly, Feel there is a nicer way to do this, anyway
Get the operator, get its bl_idname from the class name.
If there is a property attached to the button it is reflected in the button context. From the operator get its properties (minus rna_type
) to find which belong to the operator.
Get the operator from bpy.ops
invoke it and use the settings of the button.
Following writes info re the operator and also invokes it.
def execute(self, context):
op = getattr(context, "button_operator")
if op:
foo, bar = op.bl_rna.identifier.split("_OT_")
keys = set(op.bl_rna.properties.keys()) - {'rna_type'}
kwargs = {k : getattr(op, k) for k in dir(op) if k in keys}
print(foo.lower(), bar, kwargs)
op_callable = getattr(getattr(bpy.ops, foo.lower()), bar)
# run the op
op_callable('INVOKE_DEFAULT', **kwargs)
return {'FINISHED'}
Which if run over the add custom property to workspace in 3D view UI, prints the following to console
wm properties_add {'data_path': 'workspace'}
and runs the operator adding a new custom property to the workspace.