home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / scripts / RenderEngineScript / graphviz.py
Encoding:
Python Source  |  2008-01-23  |  1.1 KB  |  45 lines

  1. #python
  2.  
  3. import k3d
  4. k3d.check_node_environment(locals(), "RenderEngineScript")
  5.  
  6. graph = """
  7. digraph G {
  8.  
  9. node [ shape="box" style="filled" color="black" fillcolor="white" ];
  10.  
  11. """
  12.  
  13. for node in Document.nodes():
  14.     graph += str(node.__hash__())
  15.     graph += "[\n"
  16.     graph += "label=\"" + node.name + "\"\n"
  17.     graph += "URL=\"http://www.k-3d.org/wiki/" + node.factory().name + "\"\n"
  18.     graph += "]\n"
  19.  
  20. for node in Document.nodes():
  21.     for prop in node.properties():
  22.  
  23.         if prop.type == "k3d::inode*":
  24.             referenced_node = prop.internal_value
  25.             if referenced_node:
  26.                 graph += str(referenced_node.__hash__()) + "->" + str(node.__hash__())
  27.                 graph += "[\n"
  28.                 graph += "style=dotted\n"
  29.                 graph += "label=\"" + prop.name + "\"\n"
  30.                 graph += "]\n"
  31.  
  32.         source_prop = Document.get_dependency(prop)
  33.         if source_prop:
  34.             graph += str(source_prop.node.__hash__()) + "->" + str(prop.node.__hash__())
  35.             graph += "[\n"
  36.             graph += "taillabel=\"" + source_prop.name + "\"\n"
  37.             graph += "headlabel=\"" + prop.name + "\"\n"
  38.             graph += "]\n"
  39.  
  40. graph += "}"
  41.  
  42.  
  43. from subprocess import *
  44. Popen(["dot", "-Tsvg", "-o" + OutputImage], stdin=PIPE).communicate(graph)
  45.