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 Python
 How to check if user has Origin 2021 or later?

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
ChemistryGuy 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()


8   L A T E S T    R E P L I E S    (Newest First)
minimax Posted - 08/05/2022 : 01:59:52 AM
nice script
Castiel 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 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.
ChemistryGuy 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.")


minimax 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 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?
ChemistryGuy Posted - 08/03/2022 : 07:31:48 AM
Thank you!
Castiel 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
------------------------------------------

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