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
 How to check if user has Origin 2021 or later?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ChemistryGuy

Australia
49 Posts

Posted - 08/03/2022 :  05:54:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
------------------------------------------
Go to Top of Page

ChemistryGuy

Australia
49 Posts

Posted - 08/03/2022 :  07:31:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!
Go to Top of Page

ChemistryGuy

Australia
49 Posts

Posted - 08/03/2022 :  07:36:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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?
Go to Top of Page

minimax

351 Posts

Posted - 08/03/2022 :  10:42:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

ChemistryGuy

Australia
49 Posts

Posted - 08/04/2022 :  03:47:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

minimax

351 Posts

Posted - 08/04/2022 :  04:40:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

Castiel

343 Posts

Posted - 08/04/2022 :  06:47:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
------------------------------------------
Go to Top of Page

minimax

351 Posts

Posted - 08/05/2022 :  01:59:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
nice script
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