The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Automation Server/COM and LabVIEW
 Problem with python and COM
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

paul.goulain

France
1 Posts

Posted - 09/17/2019 :  3:07:31 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 9.0.0 SR2
Operating System: WIN 10

Hi,

I'm trying to control Origin from a Jupyter notebook using Python 3.7 and the originExt and the win32com library. I noticed that both libraries have pros and cons.

Right now, I have a problem with the Save COM function. Here is the code i use :

import random
import win32com.client # COM module

# Connect to Origin
origin = win32com.client.Dispatch("Origin.ApplicationSI")

# Create a new workbook named "Python" using the "origin" template
pageName = origin.CreatePage(2, "Python", "origin") # 2 for WorksheetPage

# Generate X data to be the even numbers from zero to 100.
# Note: the end of range is exclusive
xData = range(0,101,2)

# Generate Y data to be random numbers
yData = []
for i in range(0,len(xData)):
yData.append(random.random())

# Put the X and Y data into the worksheet
origin.PutWorksheet(pageName, xData, 0, 0) # row 0, col 0
origin.PutWorksheet(pageName, yData, 0, 1) # row 0, col 1

origin.Save("C:\\Users\\Paul\\Downloads\\Orglab93-64bit-116\\bin\\project.opj")

and here is the error output :

TypeError Traceback (most recent call last)
<ipython-input-181-553b0a389dac> in <module>
21 origin.PutWorksheet(pageName, yData, 0, 1) # row 0, col 1
22
---> 23 origin.Save("C:\\Users\\Paul\\Downloads\\Orglab93-64bit-116\\bin\\project.opj")
24

TypeError: 'bool' object is not callable

Am i using the COM function Save the wrong way ?

Paul

lkb0221

China
497 Posts

Posted - 11/27/2019 :  5:08:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this:


import OriginExt
import numpy as np

if __name__ == "__main__":
app = OriginExt.Application()
app.Visible = app.MAINWND_SHOW
pageName = app.CreatePage(app.OPT_WORKSHEET)
testDataX = range(0, 101, 2)
testDataY = np.random.rand(1, len(testDataX))
app.PutWorksheet(pageName, testDataX, 0, 0)
app.PutWorksheet(pageName, testDataX, 0, 1)
app.Save("D:\\project.opj")
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000