title: Entity Draw with Understand Python API
body: <p>I am trying to get each entity to draw a certain type of graph using the Understand Python API. All the inputs are good and the database is opened but the the single item is not drawn. There is no error and no output file. The code is listed below. The Python code is called from a C# application which calls upython.exe with the associated arguments.</p>
  <p>The Python file receives the Scitools directory and opens the understand database. The entities are also an argument which is loaded into a temp file. The <code>outputPath</code> references the directory where the SVG file will be placed. I can't seem to figure out why the <code>item.draw</code> method isn't working.</p>
  <pre><code>import os
  import sys
  import argparse
  import re
  import json
  
  #parse arguments
  parser = argparse.ArgumentParser(description = 'Creates butterfly or call by graphs from and Understand DB')
  parser.add_argument('PathToSci', type = str, help = &quot;Path to Sci Understand libraries&quot;)
  parser.add_argument('PathToDB', type = str, help = &quot;Path to the Database you want to create graphs from&quot;)
  parser.add_argument('PathToOutput', type = str, help='Path to where the graphs should be outputted')
  parser.add_argument('TypeOfGraph', type = str, 
                      help=&quot;The type of graph you want to generate. Same names as in Understand GUI. IE 'Butterfly' 'Called By' 'Control Flow' &quot;)
  parser.add_argument(&quot;entities&quot;,  help='Path to json list file of Entity long names you wish to create graphs for')
  
  args, unknown = parser.parse_known_args()
  
  # they may have entered a path with a space broken into multiple strings
  if len(unknown) &gt; 0:
      print(&quot;Unkown argument entered.\n Note: Individual arguments must be passed as a single string.&quot;)
      quit()
  
  pathToSci = args.PathToSci
  pathToDB = args.PathToDB
  graphType = args.TypeOfGraph
  entities = json.load(open(args.entities,))
  pathToOutput = args.PathToOutput
  
  pathToSci = os.path.join(pathToSci, &quot;Python&quot;)
  sys.path.append(pathToSci)
  import understand
  
  db = understand.open(pathToDB)
  
  count = 0
  for name in entities:
      count += 1
      print(&quot;Completed: &quot; + str(count) + &quot;/&quot; + str(len(entities)))
  
      #if it is an empty name don't make a graph
      if len(name) == 0:
          break
  
      pattern = re.compile((name + '$').replace(&quot;\\&quot;, &quot;/&quot;))
      print(&quot;pattern: &quot; + str(pattern))
      sys.stdout.flush()
      ent = db.lookup(pattern)
      print(&quot;ent: &quot; + str(ent))
      sys.stdout.flush()
      print(&quot;Type: &quot; + str(type(ent[0])))
      sys.stdout.flush()
      for item in ent:
          try:
              filename = os.path.join(pathToOutput, item.longname() + &quot;.svg&quot;)
              print(&quot;Graph Type: &quot; + graphType)
              sys.stdout.flush()
              print(&quot;filename: &quot; + filename)
              sys.stdout.flush()
              print(&quot;Item Kind: &quot; + str(ent[0].kind()))
              sys.stdout.flush()
              item.draw(graphType, filename)
          except understand.UnderstandError:
              print(&quot;error creating graph&quot;)
              sys.stdout.flush()
          except Exception as e:
              print(&quot;Could not create graph for &quot; + item.kind().longname() + &quot;: &quot; + item.longname())
              sys.stdout.flush()
              print(e)
              sys.stdout.flush()
      
  db.close()
  
  The output is below:
  
  Completed: 1/1
  pattern: re.compile('CSC03.SIN_COS$')
  ent: [@lCSC03.SIN_COS@kacsc03.sin_cos(long_float,csc03.sctype)long_float@f./../../../IOSSP/Source_Files/OGP/OGP_71/csc03/csc03.ada]
  Type: &lt;class 'understand.Ent'&gt;
  Graph Type: Butterfly
  filename: C:\Users\M73720\Documents\DFS\DFS-OGP-25-Aug-2022-11-24\SVGs\Entities\CSC03.SIN_COS.svg
  Item Kind: Function
  </code></pre>