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
 Accessing workbook meta data, user tree or comment
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jan.oechsler

Germany
8 Posts

Posted - 02/11/2021 :  08:05:03 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
How can i access some meta data of a workbook, sheet or plot.

Is it possible to access the "user tree" somehow? Or if that is not possible is it possible to access the "comment" section of a worksheet, book or graph?



Cheers
Jan

Chris D

428 Posts

Posted - 02/11/2021 :  09:42:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Look at code below for some examples of setting and getting book, sheet, and graph properties.
It seems not possible to get the various trees at this time.

Is is important to note that the originpro package is still young and will be improved as we have development time and get feedback such as this from our users.


import originpro as op

book = op.new_book()

book.name = 'mybook'
bn = book.name

book.lname = 'My Book Long Name'
bln = book.lname

book.set_str('comments', 'These are some book comments')
bc = book.get_str('comments')

wks = book[0]

wks.name = 'mysheet'
wn = wks.name

wks.lname = 'My Sheet Long Name'
wln = wks.lname

# Whoops these won't work!
wks.set_str('comments', 'These are some sheet comments')
wc = wks.get_str('comments')

# But these will
wks.obj.Comments = 'These are some sheet comments'
wc = wks.obj.Comments

gr = op.new_graph()

gr.name = 'mygraph'
gn = gr.name

gr.lname = 'My Graph Long Name'
gln = gr.lname

gr.set_str('comments', 'These are some graph comments')
cc = gr.get_str('comments')


Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

i.reuter

12 Posts

Posted - 05/19/2021 :  08:53:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm facing the same question how to get and edit the "user tree". Is there any plan to integrate this function in near feature?

We use user trees to save relevant meta information for measurement data stored in corresponding workbooks. We'd like to be able to "autofill" user trees while reading and processing data files with (external) python. Our external python program parses measurement files and passes the calculated data to Origin using originpro package.

If there is any other concept for handling meta data, we would be happy to adopt our workflow. As an interim solution, I've considered using additional data sheets inside a workbook for meta information.

Best,
Ingo
Go to Top of Page

YimingChen

1620 Posts

Posted - 05/19/2021 :  12:45:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please check this blog to read metadata using Python. Please Let us know how it works. Thank you.
https://blog.originlab.com/accessing-metadata-using-python

James
Go to Top of Page

YimingChen

1620 Posts

Posted - 05/19/2021 :  4:23:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Access to worksheet user tree was added in Origin 2021b, namely .userprops as a dict or .usertree as an xml ElementTree, see the code below:


import originpro as op
wks = op.new_sheet()
wks.set_str('tree.data.name', 'Larry')
wks.set_int('tree.data.age', 37)
wks.set_float('tree.data.mean', 23.56)

#access as xml tree
trWks = wks.usertree
trData = trWks.find('data')
for child in trData:
    print(f'{child.tag} = {child.text}')

#or you can access it as a dict
dd = wks.userprops['data']
print(dd)



James
Go to Top of Page

i.reuter

12 Posts

Posted - 05/20/2021 :  07:41:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Access to worksheet user tree was added in Origin 2021b, namely .userprops as a dict or .usertree as an xml ElementTree, see the code below:


import originpro as op
wks = op.new_sheet()
wks.set_str('tree.data.name', 'Larry')
wks.set_int('tree.data.age', 37)
wks.set_float('tree.data.mean', 23.56)

#access as xml tree
trWks = wks.usertree
trData = trWks.find('data')
for child in trData:
    print(f'{child.tag} = {child.text}')

#or you can access it as a dict
dd = wks.userprops['data']
print(dd)



James



Your example worked like a charm. Thanks for clarification and the provided code lines. This allows us to import data more efficient.

Best,
Ingo
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