Create a Menu to Run Python Extensions

Your Python extensions can be organized in a Geosoft menu file to be presented and easily run by your users.  To do this you will place your Python script (.py file) in the ../user/python folder and your menu (.omn file) in the ../user/omn folder. Your menu can be added to a running Oasis montaj project from the "Manage menus..." tool.

As an example, the following shows how to create a menu item to run the hello_world_extension.py.

Place Python Script in the Python folder

The script:

hello_world_extension.py
import geosoft.gxapi as gxapi
import geosoft.gxpy as gxpy

# a python script must have a rungx(), which is executed by OM when the script is run
def rungx():

    # get the current gx context
    gxp = gxpy.gx.GXpy()

    # say hello to the user identified by gxp.gid.
    gxapi.GXSYS.display_message("GX Python", "Hello {}".format(gxp.gid))

Place this in ../user/python folder:

Create a menu file

Create a menu file (with extension .omn) in your C:\Program Files\Geosoft\Desktop Applications 9\user\omn folder. For example, the following menu file named MyPython.omn will present Hello as an option to the user:

MyPython.omn
/ My Python extensions
/------------------------------------------------------------------------------

MENU "MyPython"
ITEM "Hello"   ,hello_world_extension.py

Place this in the ../user/omn folder:

Load the Menu

Your user will load the menu into an open project by selecting the Manage Menus... button  which will open the menu manager.  Your custom menu will appear under User Menus:

Run the Script

For the Python script to run your user must have installed and configured Python to run Geosoft modules. See Python Installation and Configuration.

Once the menu is loaded, MyPython will appear among the Geosoft menus. Select the Hello option: