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 Python
 Package Installation is easier in 2020b
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic  Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cpyang

USA
1406 Posts

Posted - 05/27/2020 :  6:11:18 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
You can easily install Python packages with Origin2020b, just run InstallPythonPackages from the Script Window, for example to run the follow Excel export code, need to install xlsxwriter, then just open Script Window and type
InstallPythonPackages(0,xlsxwriter)
and hit enter.

To try this code, open Code Builder, new a py file in UFF, like call it test1.py, then paste the code below, save the file, and from Script Window type "run -pyf test1.py". This code assume you have a worksheet to export with some data:


import PyOrigin
import xlsxwriter
 
wks =  PyOrigin.ActiveLayer()
file = PyOrigin.GetPath(PyOrigin.PATHTYPE_USER)+'Data.xlsx'
workbook = xlsxwriter.Workbook(file)
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
for i, col in enumerate(wks):
	header = col.GetLongName();
	unit = col.GetUnits();
	data = col.GetData()
	worksheet.write(0, i, header, bold)
	worksheet.write(1, i, unit, bold)
	worksheet.write_column(2, i, data)

workbook.close()


There is also an App for installing packages, see

https://www.originlab.com/fileExchange/details.aspx?fid=414

Please note that if you had error with Python before you install a package, you need to restart Origin.

CP

nick_n

Finland
125 Posts

Posted - 05/28/2020 :  10:12:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
Thank you very much! With App it is so easy now. I guess, both InstallPythonPackages and App should be mentioned in help files. Best regards,

Nikolay
Go to Top of Page

Castiel

343 Posts

Posted - 05/31/2020 :  06:51:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang



#2021 will be enumerate(wks.Columns)
for i, col in enumerate(wks.Columns()):




Alternatively, this also works:
#2021 will be enumerate(wks.Columns)
#for i, col in enumerate(wks.Columns())
for i, col in enumerate(wks):

                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************

Edited by - Castiel on 05/31/2020 06:58:33 AM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 05/31/2020 :  07:05:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Castiel,

I updated my example above, this indeed allow the same code to work in 2020b and going forward where we fixed the bug that list in OriginObjects not accessible as properties.

CP
Go to Top of Page
  Previous Topic 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