Last active
May 21, 2023 18:38
-
-
Save p2or/68e43e1909e08ae48ff343039afa7ce7 to your computer and use it in GitHub Desktop.
Catch operator error report #Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://blender.stackexchange.com/q/63347/3710 | |
import bpy | |
class CustomDissolveEdgeOperator(bpy.types.Operator): | |
bl_idname = 'custom.dissolve_edges' | |
bl_label = 'Custom Edge Dissolve' | |
bl_options = {'REGISTER', 'UNDO'} | |
''' | |
@classmethod | |
def poll(cls, context): | |
return bpy.ops.mesh.dissolve_edges.poll() | |
''' | |
def execute(self, context): | |
if bpy.ops.mesh.dissolve_edges.poll(): | |
print("Context correct") | |
try: | |
bpy.ops.mesh.dissolve_edges() | |
except RuntimeError as exception: | |
error = " ".join(exception.args) | |
print("error:", error) | |
self.report({'ERROR'}, error) | |
else: | |
print ("Context incorrect") | |
self.report({'ERROR'}, "Context incorrect") | |
return {'FINISHED'} | |
def draw_edge_dissolve(self, context): | |
layout = self.layout | |
layout.operator("custom.dissolve_edges") | |
def register(): | |
bpy.utils.register_class(CustomDissolveEdgeOperator) | |
bpy.types.VIEW3D_MT_edit_mesh_delete.append(draw_edge_dissolve) | |
def unregister(): | |
bpy.utils.unregister_class(CustomDissolveEdgeOperator) | |
bpy.types.VIEW3D_MT_edit_mesh_delete.remove(draw_edge_dissolve) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment