INTViewer is a platform that can be extended using Java. The Python interpreter that is built-in INTViewer is based upon Jython 2.7.0 (http://www.jython.org/). It acts as a thin wrapper over INTViewer's Java API.
If you are a Java developer and want to use the Python capabilities, you might want to read this introduction to Python. This site assumes you have installed INTViewer 5.2, 2018 or later.
There are four primary ways of using Python commands inside INTViewer:
The first way is to utilize the built in Python Terminal. After opening the terminal, simply type any Python commands in the text area, and INTViewer will interpret these commands. This method is described further in the section below.
The second way of using Python with INTViewer is to create a .py file with any text editor that you are comfortable with (such as Notepad++). You can then drag and drop this file from your file system onto the INTViewer desktop or the Python Terminal, and the file will be executed. INTViewer also allows the execution of Python scripts in contextual menus. You also have the option to customize the Scripts menu.
The third way is through the command line. Simply add --pyfile pythonFilePath to the INTViewer.bat or INTViewer.sh startup scripts. The file specified by pythonFilePath will automatically run when INTViewer starts up. To force INTViewer to close after a Python script is executed, use the --pyautoclose command line argument.
The final way is to access the Python server from a separate program running on the same machine, and send commands through the RMI, TCP or SSH connection established.
There are two main ways of opening up the Python Terminal.
The first is to use the Window -> Python Terminal menu option.
The second is to open up the Python Toolbar by going to View -> Toolbars -> Python.
Then click the Python Terminal icon in the toolbar.
This "Python Terminal" button in the toolbar opens the "Python Terminal" window.
You can drag and drop items from INTViewer directly into the Python terminal:
While utilizing INTViewer's Python Terminal there are several commands that you can use.
classes - This will print out a list of all classes in the system. Alternatively you can add an argument to get a list of all classes that match a name. For instance classes *seismic* will give a list of all classes which contain the word seismic.
methods - Entering the command methods by itself will simply list all classes along with all of their methods. Usually, however, you will use this along with an argument which is the name of a class. For instance methods SeismicData will print out all of the methods for the SeismicData class.
clear - This will clear all text from the Python Terminal window.
server status - This will print out if the Python server is on or off.
server start - This will start the server if it is not already started.
server stop - This will stop the server if it is not already stopped.
server help - This will print out the available server commands.
restart - This will restart the Python interpreter. All Python variables will be cleared
imports - This will show all imports executed automatically upon the Python interpreter's start
help - This will print the basic help information for INTViewer's Python abilities.
In addition to these basic commands, any time you use the classes or methods commands, any class that is usable by the Python interpreter will have an underline. You can simply click on these classes, and all of the methods for that class will print to the terminal.
INTViewer has a Help->Python API menu item that lists all available Python classes. You can consult this API from this site: http://intviewer.int.com/intviewer/docs/pythonapi/latest/index.html
Autocompletion is also available. Press the Ctrl and Space keys together to trigger autocompletion. You can also press the Tab key. See https://www.int.com/blog/live-completion-better-autocompletion/ for more information.
You will need to utilize the PythonControlLibrary.jar file to use these commands in your project. If you installed INTViewer in C:\Program Files\INTViewer\, this library can be found at this location: C:\Program Files\INTViewer\intviewer\modules\ext\PythonControlLibrary.jar
To use the python server remotely, you will need to create a simple java file. You will need to get an instance of the com.interactive.intviewer.python.control.IPythonEvalServer using the following command:
IPythonEvalServer server = (IPythonEvalServer) ServerManager.getInstance().getRegistry(7777).lookup("PythonServer");
In this command, 7777 is the port number that you choose using the Python options within INTViewer. This option can be found under Tools -> Options -> Python.
After getting the server, you then send commands to the Python server using the eval method. The following command will open up a seismic dataset:
String result = server.eval("seismicData = SeismicData('F:\\Data\\Segy\\Attributes\\cdp_stack.xgy')");
The result string will be whatever the Python Terminal would normally print out in response to the command.
In INTViewer, there are two other remote control methods:
through Python commands sent through a socket
through SSH commands sent through SSH (with the PythonSSH plugin loaded)
Server options are listed in Tools->Options->Python->Servers