Skip to content

Exporting GunnsDraw Networks

Jason Harvey edited this page Feb 19, 2021 · 1 revision

The gunns/draw/netexport.py Python script is used to auto-generate the network C++ code from a GunnsDraw drawing. It does several things:

  1. Uncompresses the file if is compressed.
  2. Checks for errors in the drawing file.
    1. Warnings are output to the console with a yellow message, but the script keeps running.
    2. Errors are output with a red message, and the script aborts.
  3. Does maintenance updates on the drawing:
    1. Re-numbers the nodes if there is a gap in their numbers.
    2. Does shape data updates on links & spotters. This is described in detail below.
  4. Re-saves the drawing file with the maintenance updates, and in the un-compressed format. If any substantive changes were made to your drawing contents (like shape data or node numbering), the script will remind you at the end to synchronize the drawing in your open Draw.io app.
  5. Outputs the generated network C++ code as .hh and .cpp files in the same folder as your source drawing.
  • Run the netexport.py script by going into the gunns/draw/ folder, then do: $ python ./netexport.py
    • You can add the path/filename of the diagram .xml file to the command line, else it will pop up a file selection browser for you to select the file.
  • netexport.py has no depedencies on non-standard python packages. Our goal is to keep it independent of any non-standard libraries to reduce install burden on users.
    • However, note that some OS distributions don’t include Tkinter, which is normally a standard package in Python. Our GunnsDraw scripts depend on it, so you may have to install it if you don’t have it.

Here are the arguments and options the script accepts:

  • -h, —help: shows a help message and exits
  • -d: looks in your ~/Downloads folder for a newer version of the drawing file.
    • This is handy when you run Draw.io in a web browser that only saves updates to the drawing in your Downloads folder.
    • If it finds a newer date/timestamp on the drawing in your Downloads folder than the file location you specify, it will pop-up a message asking if you want to use the Downloads version or not.
    • If you say yes, it will process the version from your Downloads folder and save the maintained version over the path/file that you selected.
  • -m: Only does the error checks and maintenance on the drawing file, and does not export the network code.
  • -g: Only exports the network code, and skips much of the error checks and drawing file maintenance. Note this option isn’t implemented yet.
  • -p EXT_PATHS: uses the supplied environment variable as the paths to check for custom shape libraries. If you don’t use this option, the script will check your GUNNS_EXT_PATH environment variable by default. These environment variables can list multiple paths, delimited with a colon (:), similar to PATHS in Linux environments. You can optionally include ‘-I’ in front of paths; the script will strip will consider paths with or without the preceding ‘-I’.
  • netexport.py now has full support for the electrical, thermal & fluid aspects.
  • Note that the network class name is defined by the name of the network container object in the drawing. This is the name of the output .hh and .cpp files, and the name of the class declarations in the .hh. If this name differs from the drawing .xml file name, the export script will allow it, but output a warning message.
  • You can invoke the script from anywhere. We recommend creating a handy alias for it, like:
    • alias gdn ’python ~/repos/gunns/draw/netexport.py -p GUNNSDRAW_PATH ’
    • Then you can just command line: $ gdn (drawing file) to export a drawing from anywhere.
Clone this wiki locally