Author |
Topic |
|
ChemistryGuy
Australia
49 Posts |
Posted - 08/03/2022 : 05:54:02 AM
|
Origin Ver. and Service Release: 2022b Operating System: Windows 11
I have developed a Python program that automates Origin to perform some tasks, which I have distributed to many users.
However, some users have older versions of Origin, which lack Python compatibility. When they try to use the program it does not succeed.
I want to display a meaningful error message when this happens. However I do not have an older version of Origin to test my code on.
Therefore I wanted to ask the Origin team, please would you advise me if there is a way to check the user's Origin version via Python? For instance, if I run the below code, is an exception raised?
# Import OriginPro library
import originpro as op
# Start Origin instance
def origin_shutdown_exception_hook(exctype, value, traceback):
'''Ensures Origin gets shut down if an uncaught exception'''
op.exit()
sys.__excepthook__(exctype, value, traceback)
if op and op.oext:
sys.excepthook = origin_shutdown_exception_hook
# Attach to running Origin project, if one is open
op.attach()
|
|
Castiel
343 Posts |
Posted - 08/03/2022 : 07:03:01 AM
|
quote: Originally posted by ChemistryGuy
Origin Ver. and Service Release: 2022b Operating System: Windows 11
I have developed a Python program that automates Origin to perform some tasks, which I have distributed to many users.
However, some users have older versions of Origin, which lack Python compatibility. When they try to use the program it does not succeed.
I want to display a meaningful error message when this happens. However I do not have an older version of Origin to test my code on.
Therefore I wanted to ask the Origin team, please would you advise me if there is a way to check the user's Origin version via Python? For instance, if I run the below code, is an exception raised?
# Import OriginPro library
import originpro as op
# Start Origin instance
def origin_shutdown_exception_hook(exctype, value, traceback):
'''Ensures Origin gets shut down if an uncaught exception'''
op.exit()
sys.__excepthook__(exctype, value, traceback)
if op and op.oext:
sys.excepthook = origin_shutdown_exception_hook
# Attach to running Origin project, if one is open
op.attach()
#get Origin version number
v = op.lt_float('@V') # v >= 9.8 for Origin 2021 or later
------------------------------------------
Be The Change
You Want To See
In The World
------------------------------------------
|
|
|
ChemistryGuy
Australia
49 Posts |
Posted - 08/03/2022 : 07:31:48 AM
|
Thank you! |
|
|
ChemistryGuy
Australia
49 Posts |
Posted - 08/03/2022 : 07:36:29 AM
|
Once again I really appreciate your quick reply.
However, I have found that this takes 3 seconds to execute, which could be inconvenient for users if it runs every time they use the code.
Is there possibly any quicker method of checking this? |
|
|
minimax
351 Posts |
Posted - 08/03/2022 : 10:42:03 PM
|
It is not getting version takes a long time, but starting Origin requires time.
the script "import originpro as op" does not start Origin instance yet, but the first script which access op will, and this period cannot be omitted.
import originpro as op
import time
#init op, and it takes some time
op.lt_exec('ty hello')
tic = time.perf_counter()
v = op.lt_float('@V')
toc = time.perf_counter()
print(f'get version took {toc - tic:0.4f} seconds')
--> get version took 0.0002 seconds |
|
|
ChemistryGuy
Australia
49 Posts |
Posted - 08/04/2022 : 03:47:47 AM
|
Thank you for explaining why this process requires this much time.
Based on this, please would you advise me if the following code would be robust for checking the users version number? The user may have Origin open or closed when they run the code.
try:
op.attach()
except:
v = op.lt_float('@V') # v >= 9.8 for Origin 2021 or later
if v < 9.8:
print("Your Origin version does not support Python connectivity. Please install Origin 2021 or later.")
else:
print("Origin failed to attach for some other reason.")
else:
print("Origin attached successfully.")
|
Edited by - ChemistryGuy on 08/04/2022 03:48:30 AM |
|
|
minimax
351 Posts |
Posted - 08/04/2022 : 04:40:08 AM
|
If your py script's minimum version is 9.8, the script can be
try:
import originpro as op
except:
print("originpro package requires Origin 2021 or later.")
else:
print("import successfully.")
since the 1st supported version of originpro package is 2021, import will already fail in older versions. |
|
|
Castiel
343 Posts |
Posted - 08/04/2022 : 06:47:34 AM
|
quote: Originally posted by ChemistryGuy
Once again I really appreciate your quick reply.
However, I have found that this takes 3 seconds to execute, which could be inconvenient for users if it runs every time they use the code.
Is there possibly any quicker method of checking this?
Have a try of this: https://raw.githubusercontent.com/lab-plug/taklamakan/main/query_origin_info.py
------------------------------------------
Be The Change
You Want To See
In The World
------------------------------------------
|
|
|
minimax
351 Posts |
Posted - 08/05/2022 : 01:59:52 AM
|
nice script |
|
|
|
Topic |
|