User callbacks for Operators
often there is a need to at least supplement the behavior of an already existing specific operator (for example, to do something before executing it, or after). As far as I know, there is no functionality for this
My suggestion is to add certain callbacks to the Operator class (execute_pre, execute_post, etc...). This will make it EASY to extend existing functionality, regardless of how the operator is implemented: in the core on C++, or in the Python addon
An example of what it might look like:
def callback(self, context):
print(context.active_object.name)
...
if __name__ == "__main__":
bpy.ops.mesh.primitive_cube_add.execute_post.append(callback)
...
Now when you add a cube, its name will be displayed in the console
in the general perspective, the design will look something like this. it is definitely worth supplementing. I think more experienced scripters will definitely find something else to add
1 Comment
A consequence of this is that you can alter the functionality of other add-ons/scripts that might not consider the change and will break. Those issues will be very hard to detect as the root cause isn't in the failing add-on.
So we should find a solution that doesn't have these side effects and increase of support/maintenance.