From 870f9775d7cd57b2d51c6c964842b96e5ba542c0 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov <angavrilov@gmail.com> Date: Wed, 29 Jun 2022 20:06:29 +0300 Subject: [PATCH] Depsgraph Debug: add an operator to generate an SVG and open in browser. Rather than converting the dependency graph to a bitmap image, it is more advantageous to use the vector SVG format and open it in a web browser (any modern browser supports the format), because it allows text searches within the image. This patch adds a new operator and button that does just that. Differential Revision: https://developer.blender.org/D15325 --- depsgraph_debug.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/depsgraph_debug.py b/depsgraph_debug.py index 4405eb8e3..7c8784a29 100644 --- a/depsgraph_debug.py +++ b/depsgraph_debug.py @@ -211,6 +211,35 @@ class SCENE_OT_depsgraph_stats_image(Operator, return True +class SCENE_OT_depsgraph_relations_svg(Operator, + SCENE_OT_depsgraph_image_common): + bl_idname = "scene.depsgraph_relations_svg" + bl_label = "Depsgraph as SVG in Browser" + bl_description = "Create an SVG image from the dependency graph and open it in the web browser" + + def performSave(self, context, depsgraph): + import os + import subprocess + import webbrowser + # Create temporary file. + dot_filepath = self._createTempFile(suffix=".dot") + # Save dependency graph to graphviz file. + depsgraph.debug_relations_graphviz(dot_filepath) + # Convert graphviz to SVG image. + svg_filepath = os.path.join(bpy.app.tempdir, "depsgraph.svg") + command = ("dot", "-Tsvg", dot_filepath, "-o", svg_filepath) + try: + subprocess.run(command) + webbrowser.open_new_tab("file://" + os.path.abspath(svg_filepath)) + except: + self.report({'ERROR'}, "Error invoking dot command") + return False + finally: + # Remove graphviz file. + os.remove(dot_filepath) + return True + + ############################################################################### # Interface. @@ -224,6 +253,7 @@ class SCENE_PT_depsgraph_common: row = col.row() row.operator("scene.depsgraph_relations_graphviz") row.operator("scene.depsgraph_relations_image") + col.operator("scene.depsgraph_relations_svg") # Everything related on evaluaiton statistics. col.label(text="Statistics:") row = col.row() @@ -264,6 +294,7 @@ class RENDERLAYER_PT_depsgraph(bpy.types.Panel, SCENE_PT_depsgraph_common): def register(): bpy.utils.register_class(SCENE_OT_depsgraph_relations_graphviz) bpy.utils.register_class(SCENE_OT_depsgraph_relations_image) + bpy.utils.register_class(SCENE_OT_depsgraph_relations_svg) bpy.utils.register_class(SCENE_OT_depsgraph_stats_gnuplot) bpy.utils.register_class(SCENE_OT_depsgraph_stats_image) bpy.utils.register_class(SCENE_PT_depsgraph) @@ -273,6 +304,7 @@ def register(): def unregister(): bpy.utils.unregister_class(SCENE_OT_depsgraph_relations_graphviz) bpy.utils.unregister_class(SCENE_OT_depsgraph_relations_image) + bpy.utils.unregister_class(SCENE_OT_depsgraph_relations_svg) bpy.utils.unregister_class(SCENE_OT_depsgraph_stats_gnuplot) bpy.utils.unregister_class(SCENE_OT_depsgraph_stats_image) bpy.utils.unregister_class(SCENE_PT_depsgraph) -- GitLab