
|
The "Jython Console" application module enables one to write small programs in
the Python programming language to control
Modelzilla and Modelzilla applications.
Jython is an implementation of Python that
runs within the Java environment. (Jython generates Java bytecode based on a
Python source file.)
Here is a link to the Python manual.
Rather than include Jython support in the Modelzilla framework, it is packaged as an application module, so that there is no Jython dependency in the framework. Over the past few years, we have experimented with Jython, resulting in some Jython dependencies being sprinkled around the Modelzilla code. This has all been removed as of the release of the "Jython Console" ap-mod. The Java-based framework now has nothing to do with Python. A scripting system is useful for:
How Macros workCurrently the macro system is limited to creating and specifying database nodes that are creatable through the GUI anyway. Macro development is distinguished from application module development by the classes a macro imports and uses. A macro does not define new database node types, or work with the lower level geometry classes in meshGeom.geom. It is to assemble database nodes. These then do the computation. Thus a macro usually runs quite quickly to simply assemble database nodes, which then to the complex computations after the macro is finished. Because the output of a macro is kept in the database, the result of a macro is saved to the MVG files.Macros do not remain resident in the database. We are planning on making database resident macros happen in the future. A database resident macro would be like regular database node that accepts input from other nodes and does its job every time the input changes. Its job would typically be to create more database nodes which it would store as children of itself. Issues related to select ability and lifespan of the derived nodes have to be solved before this ability can be offered. Jython comes with the MZ Jython Console distributionWe are redistributing Jython as allowed by their license agreement. This makes it easier for everyone. You can get the latest versoin of Jython at http://www.jython.org. It is important to set the PYTHON_PATH variable in the file ModelzillaProject/JythonGUI/lib/regestry. This is the file Jython will look at to find its settings. The PYTHON_PATH variable controls where Jython looks for python packages loaded with the import statement. If you have your own Jython already, you may remove the one that comes with our Jython Console distribution, and make sure to point you your copy in the MZ starter script.Note that as of this writing, Jython crashes the Java virtual machine under Windows. Using Jython InteractivlyJython can be used interactively, entering one line at a time. To do this, after loading the Jython ap-mod, hit the "New Console" button. But before you do this, fill in the field "startup" in the little Jython control panel. A Python script given here will be run in the context of the Jython input panel created with the "New Console" button. The examples directory has a small script that creates the X_HighLevels objects. Each console window has an independent Jython context with independent symbol definitions.
Note that we are using a Java GUI based console rather than the operating system console because
there is no way to start Jython after Modelzilla otherwise. It is also possible to
start MZ from Jython in the OS console with:
To test the your Jython is working, at the prompt enter something like:
Some interactive sample codeThe Jython Console lets you use the macro class libraries of each application module and the framework. For example, the Modelzilla framework has a class called MZ_HighLevels, which has a set of functions for doing general management of the model. CAD-Zilla has CAD_HighLevels for doing convenient geometrical modeling. VincentVanMol has VVM_HighLevels for doing convenient molecular graphics. The start of a script that uses these handy classes should do something like:
You can now use the high level method sets like this:
You can also use the regular developer API from Jython:
Running prepared scriptsThe most useful way to run Jython scripts is write them in an external editor and simply hit the "Run Script" button from the Jython controls. Once the filename is entered you can just hit this button each time you change the script with your external editor. Another way to do it is to put the script in your PYTHON_PATH directory (set in the file ModelzillaProject/JythonGUI/lib/regestry), and import it from the interactive console, ex:import FibonocciRectanglesIf you make changes to a script, it can be reimported using the Python built-in reload() function. Ex: reload(FibonocciRectangles)You will need to use import package_name, then reload(package_name). Doing a from package_name import X will not work for Python reload() function. Java MacrosModelzilla has a macro facility that is independent of Jython. It is possible to write a script, aka a macro, in Java. You simply extend the Java class harmonic.mz.functions.Module, override the function execute(), and put the compiled class file in the classpath defined in the mz startup script and run it from the "Applications" control area. A marco in Python has the advantage of not requiring that the Java process be restarted if changes are made to the macro. |
|