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
 All Forums
 Origin Forum for Programming
 Forum for Automation Server/COM and LabVIEW
 Problem with python and COM

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
paul.goulain Posted - 09/17/2019 : 3:07:31 PM
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

1   L A T E S T    R E P L I E S    (Newest First)
lkb0221 Posted - 11/27/2019 : 5:08:26 PM
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")

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000