[Bf-extensions-cvs] [870f9775] master: Depsgraph Debug: add an operator to generate an SVG and open in browser.

Alexander Gavrilov noreply at git.blender.org
Thu Jun 30 10:39:06 CEST 2022


Commit: 870f9775d7cd57b2d51c6c964842b96e5ba542c0
Author: Alexander Gavrilov
Date:   Wed Jun 29 20:06:29 2022 +0300
Branches: master
https://developer.blender.org/rBA870f9775d7cd57b2d51c6c964842b96e5ba542c0

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

===================================================================

M	depsgraph_debug.py

===================================================================

diff --git a/depsgraph_debug.py b/depsgraph_debug.py
index 4405eb8e..7c8784a2 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)



More information about the Bf-extensions-cvs mailing list