Jump to: navigation, search
This page documents an experimental feature. Please tell us if you experience any problems.

ExtPy is a special ASCEND external library that adds an import handler that allows python scripts to be called from the METHODS section of your model. You can write any script you like inside your external python script, and launch it from the 'Methods' drop-down in the PyGTK GUI.

An example is models/johnpye/fourbar.a4c which makes reference to models/johnpye/fourbarplot.py

ExtPy modules

ExtPy modules have been written that

  • solve the model repeatedly and create a composite plot of the results
  • produce specialised plots that could not be produced using the old 'plot.a4l' approach.
  • perform stability analysis on the DAE system
  • set parameters in the solver based on the contents of NOTES in the model
  • run the solver (useful during 'on_load' methods on models where initialisation is a bit trickier.)
  • perform Parametric studies
  • create 3D visualisations using OpenGL (see Optimisation of frame geometry)

An advantage of using ExtPy methods instead of writing an entire 'driver' script is that you method can be called from the PyGTK GUI and can be more easily reused from multiple model files.

ExtPy methods can be used from the Tcl/Tk GUI, although obviously they can't make PyGTK GUI output in that case.


If you want to implement your own 'ExtPy' module, you should note the following basic structure:

# import the 'extpy' module for basic access to the ASCEND API
import extpy

# any stuff that might cause errors should be imported like this:
	from pylab import *


# you can import standard ASCEND components, for example:
from solverreporter import *

# this is where you define your external method
def fourbarplot(self):
	"""Document the method with a docstring; this text will appear in the ASCEND GUI"""

	# use the following if your method uses matplotlib; this will ensure
	# that visible error messages are thrown if matplotlib is not installed.

	import loading

	# to gain access to the main PyGTK GUI window, use the following:
	browser = extpy.getbrowser()


	# rest of your method here

# finally, tell ASCEND about the method you have just defined:

# the above method can be called using "EXTERNAL fourbarplot(SELF)" in ASCEND.