Follow

Python/Command language info for "interrupting" execution

You are writing your script to play in EnSight, either with the command language or in python. During this process, you may want to execute a series of commands, stop the execution to allow inspection, and then start the sequence playing again. How to do this?

You can place an "interrupt:" command in the .enc file. 
When this command is hit the execution will stop and the command dialog should pop up. Selecting the step or play button from that point will start execution of the next command or the rest of the commands respectively.
 
This will work in the command language, but if you try to move this to python through the conversion routine in EnSight, a sendmesg command will be created, and it won't work as expected. 
This is due to the fact that python has a different syntax for interrupting a script. The user can do just about anything they want with python, display a dialog that doesn't return until a button is pushed, wait for input from somewhere, etc. That choice is up to the user and their knowledge of python.
 
Example 1: 
=========
 
You could have the sequence:
 
ensight.view_transf.rotate(5.921671e+001,7.203685e+001,0.000000e+000) 
ensight.view_transf.rotate(-1.456919e+001,-2.210849e+001,0.000000e+000) 
ensight.view_transf.zoom(9.157048e-001) 
ensight.view_transf.rotate(-4.723238e+001,1.787103e+001,0.000000e+000) 
ensight.view_transf.rotate(4.746736e+001,1.805528e+001,0.000000e+000)
 
and want to "interrupt" between the zoom and rotate commands.
 
When running as a Python script, you could:
 
from cei.qtgenericdlg import *
 
[....]
 
ensight.view_transf.rotate(5.921671e+001,7.203685e+001,0.000000e+000) 
ensight.view_transf.rotate(-1.456919e+001,-2.210849e+001,0.000000e+000) 
ensight.view_transf.zoom(9.157048e-001) 
ret = QtGui.QMessageBox.information(ensight.qtparent(),"Pause","pause...") 
ensight.view_transf.rotate(-4.723238e+001,1.787103e+001,0.000000e+000) 
ensight.view_transf.rotate(4.746736e+001,1.805528e+001,0.000000e+000)
 
This will "interrupt" script execution and it will continue when the dialog is dismissed, but the dialog is Modal and will constrain interaction while it is being displayed.
 
Example 2: 
========= 
You could write the same code like this:
 
def foo1(): 
ensight.view_transf.rotate(5.921671e+001,7.203685e+001,0.000000e+000) 
ensight.view_transf.rotate(-1.456919e+001,-2.210849e+001,0.000000e+000) 
ensight.view_transf.zoom(9.157048e-001)
 
def foo2(): 
ensight.view_transf.rotate(-4.723238e+001,1.787103e+001,0.000000e+000) 
ensight.view_transf.rotate(4.746736e+001,1.805528e+001,0.000000e+000)
 
foo1() 
ret = DisplaySimpleOKCancel(...,foo2())
 
And replace the DisplaySimpleOKCancel with a modeless dialog that would call foo2 if the "ok" button is pressed.
 
Example 3: 
========= 
If every line of your Python file meets the requirements listed here,
 
 
you can literally change the .py extension to .enc and play it back in the command dialog as a command file and use the interrupt: command.
 
The key limitation is that between lines of Python, that need to be executed in the same context (stack/vars/etc), you cannot let EnSight start any commands.
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments