ARAP scripts can run Python Language scripts opening up access to huge library of code written in the Python language. For astronomy, this includes the popular AstroPy package.


Before using this feature:


  • install the 32-bit version of the Anaconda installation of Python (other installations may work, but have not been tested)
  • setup ARAP to use this installation
  • restart ARAP and ensure that you see the message: "Python Language interface has been loaded."


Available Python commands are here.


To run your first Python script try the command:


python runstring "print ('Hello World!')"


You won't see the "Hello World!" as the Python console is not redirected, but if this command runs without displaying an error, then the Python Language interface is working properly.


To run a Python script file (eg. test.py) use the following syntax:


python runfile c:\arap\test.py


After each 'python' command check the variable PYTHONERROR. It will be "true" if an error occurred. See the system log to view the nature of the error.


Passing Variables to and from a Python Script


ARAP has 2 pre-defined variables used to pass an ARAP variables to and from a Python script: PYTHONINPUT and PYTHONOUTPUT. They are functionally equivalent despite that their names imply a more restricted use.


To use this feature, add the following to your Python script:


import ARAP


To access PYTHONINPUT in Python use:


ARAP.Input


To access PYTHONOUTPUT in Python use:


ARAP.Output


A sample ARAP script is here that shows how to set the Python variables, run a script, and show the Python variables afterwards.


Capturing and Returning Python Console Output


To capture Python console output, see the code in this sample. The console output will be placed in the PYTHONCONSOLE variable.


Important Note: Python scripts run from the main thread of ARAP. That means they are "blocking" to the ARAP user interface, meaning the user interface will freeze and become non-responsive until the Python code completes. This means that users cannot stop a running script. You should take care in creating Python code so that it does not execute for too long OR includes a time out mechanism in case it runs longer than expected or it hangs up. A sample time out mechanism in shown in this sample Python script.