ExtPy: Difference between revisions
Restored page from Google Cache, uploaded by John Pye |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{experimental}} | |||
ExtPy is a special ASCEND external library that adds an [[Import_handlers|import handler]] that allows python scripts to be called from the <tt>METHODS</tt> 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. | ExtPy is a special ASCEND external library that adds an [[Import_handlers|import handler]] that allows python scripts to be called from the <tt>METHODS</tt> 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 {{src|models/johnpye/fourbar.a4c}} which makes reference to {{src|models/johnpye/fourbarplot.py}} | An example is {{src|models/johnpye/fourbar.a4c}} which makes reference to {{src|models/johnpye/fourbarplot.py}} | ||
== ExtPy modules == | == ExtPy modules == | ||
ExtPy modules have been written that | ExtPy modules have been written that | ||
* solve the model repeatedly and create a composite plot of the results | * solve the model repeatedly and create a composite plot of the results | ||
| Line 22: | Line 20: | ||
ExtPy methods can be used from the Tcl/Tk GUI, although obviously they can't make PyGTK GUI output in that case. | ExtPy methods can be used from the Tcl/Tk GUI, although obviously they can't make PyGTK GUI output in that case. | ||
== Notes == | == Notes == | ||
If you want to implement your own 'ExtPy' module, you should | If you want to implement your own 'ExtPy' module, you should note the following basic structure: | ||
<source lang=" | <source lang="py"> | ||
# import the 'extpy' module for basic access to the ASCEND API | |||
import extpy | import extpy | ||
| Line 44: | Line 41: | ||
# this is where you define your external method | # this is where you define your external method | ||
def fourbarplot(self): | 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 | # use the following if your method uses matplotlib; this will ensure | ||
| Line 62: | Line 59: | ||
extpy.registermethod(fourbarplot) | extpy.registermethod(fourbarplot) | ||
# the above method can be called using | # the above method can be called using "EXTERNAL fourbarplot(SELF)" in ASCEND.</source> | ||
[[Category:Extending_ASCEND]] | [[Category:Extending_ASCEND]] | ||
Latest revision as of 03:01, 17 April 2012
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.
Notes
If you want to implement your own 'ExtPy' module, you should note the following basic structure:
Invalid language.
You need to specify a language like this: <source lang="html">...</source>
Supported languages for syntax highlighting:
a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn