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
 LabTalk Forum
 Activate Python Script Using LabTalk
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hrorigin

USA
3 Posts

Posted - 02/20/2023 :  1:56:57 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release: 10.0.0.154 OriginPro 2023
Operating System: Windows 10

Hi!

I was trying to set up buttons in my origin project such that clicking on it would activate a Python script. I found the following link that documents how to use LabTalk to activate the Python Script.

https://www.originlab.com/doc/en/LabTalk/ref/Run-obj#Run_Python:

I was trying to set it up such that the LabTalk script would go into the folder the origin exe exists and then go into a subdirectory where the Python files I would like to run would reside.

I tried formatting the first line of the LabTalk script like this:

string file_path$ = system.PATH.PROGRAM$ + "\MyFolder\";

But even when I had the same name for the folder in the directory with the wanted Python file the project would return that the directory was not found. The rest of the LabTalk script looks the same as in the URL but with the name of my python file instead.

Any advice is appreciated

Thank you in advance

YimingChen

1594 Posts

Posted - 02/20/2023 :  5:03:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can run Python script by clicking a button. Please check this page:
https://www.originlab.com/doc/en/python/tools/Run-Python-from-Graph-Object

By the way, if you run the following script in the script window, there is an extra '\'.

string file_path$ = system.PATH.PROGRAM$ + "\MyFolder\";
file_path$=;


James

Edited by - YimingChen on 02/20/2023 5:15:57 PM
Go to Top of Page

hrorigin

USA
3 Posts

Posted - 02/21/2023 :  08:48:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for the help James!

I was also able to find this solution using Labtalk in the same script window that you could put the Python script in.

run.python("C:\PathTo\MyFile\MyPythonScript.py", 2);


Did not know you could put the path to the file when using "2" as the second argument. Very useful if someone wants their python scripts all in one file than within the Origin project.
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