2 Access Origin From Python with OriginExt
OriginExt is a Python package that enables you to access Origin functionality from Python. OriginExt is built on Origin’s COM/Automation interface that Python functions as the client application that connects with Origin. It allows exchange data back and forth between Python and Origin and can also send commands from Python to be executed by Origin.
To obtain OriginExt, go to this pypi.org page.
Follow the steps below to generate and connect to an Origin instance from external Python.
- Run Origin 2019b or later version (64bit) as Administrator once, and quit.
- Install Python 3.7.2 (64bit).
- Make sure to Set Environment Variables during installation. If not, you need to add Python root and Scripts subpath to the Path environment variable
- From Windows Command Line, cmd.exe:
- Execute the command to install the package.
pip install OriginExt.
- If Python was installed for All Users, you need to run cmd as Administrator
- Start a Python Console.
- Run the following test script to connect to Origin:
import OriginExt as O
app = O.Application()
app.Visible = 1
More Examples on OriginExt
Here is an example on how to create an Origin project with some data
import OriginExt as O
Oapp = O.Application()
name = Oapp.CreatePage(Oapp.OPT_WORKSHEET,"MyBook","Origin")
wbook = Oapp.Pages(name)
wks = wbook.Layers(0)
for ii in range(0,wks.Columns.Count,1):
tmp = range(0,10)
tmp = [x + ii for x in tmp]
col = wks.Columns(ii)
#need to do this to make sure Origin is closed
For more examples on communicating with Origin from external Python, please refer to our Automation Server documentation.
|Note: OriginExt is built with Microsoft (MS) Visual Studio 2019 (or later version).
If you are using an earlier version of Origin, you might see a MS DLL error at Origin startup, such as the error "ModuleNotFoundError: No module named 'originext'". In this case, we suggest you to download and install the MS redistributable package. The needed MS redistributable packages are listed in this web page, you can download the suitable package(s) according to the version of Origin you are using.