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
 op.save not working properly

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
Kositi Posted - 07/28/2021 : 05:53:22 AM
Hello,

I tried run the examples for externaly Code (https://www.originlab.com/doc/ExternalPython/External-Python-Code-Samples). In the fourth lesson I tried to change the directory to my Desktop by using:

op.save(op.path("u")+ "C:/.../Desktop" + "Example4.opju")


Everthing was working execpt the saving. It seems, like Python is not saving the file.

Thank you for your help.
17   L A T E S T    R E P L I E S    (Newest First)
pavi-chem Posted - 05/26/2023 : 11:25:48 AM
Awesomee, it works.

I also tried this as an alternative and it works :)

output_file_path = filedialog.asksaveasfilename(title="Save Output Origin File", filetypes=[("Origin Project Files", "*.opju")])

# Save the project to the specified output file path using both op.oext and op.save
if op.oext:
op.save(os.path.abspath(output_file_path))

Thanks a bunch!
Pavi.
YimingChen Posted - 05/24/2023 : 4:22:12 PM
You need to replace the slash in the file path with backslash. Try the script below


output_file_path = filedialog.asksaveasfilename(title="Save Output Origin File", filetypes=[("Origin Project Files", "*.opju")])
modified_file_path = output_file_path.replace('/', '\\')
op.save(modified_file_path)


James
pavi-chem Posted - 05/24/2023 : 08:35:30 AM
Hi, I have similar problem saving the file. the code runs without error but doesn't create the opju file. But it does allow me to save manually.

# Prompt user for the output Origin file name
output_file_path = filedialog.asksaveasfilename(title="Save Output Origin File", filetypes=[("Origin Project Files", "*.opju")])

# Save the project to the specified output file path using both op.oext and op.save
if op.oext:
op.save(output_file_path)
else:
gr.save(output_file_path)

In case you need full code for more info:
import originpro as op
import os
import tkinter as tk
from tkinter import filedialog

# Very useful, especially during development, when you are
# liable to have a few uncaught exceptions.
# Ensures that the Origin instance gets shut down properly.
# Note: only applicable to external Python.
import sys


def origin_shutdown_exception_hook(exctype, value, traceback):
"""Ensures Origin gets shut down if an uncaught exception"""
op.exit()
sys.__excepthook__(exctype, value, traceback)


sys.excepthook = origin_shutdown_exception_hook

# Only run if external Python
if op.oext:
op.set_show(True)

# Prompt user to select an Origin template file for graph 1
root = tk.Tk()
root.withdraw()
template_file_path = filedialog.askopenfilename(title="Select Origin Template File for Graph 1", filetypes=[("Origin Template Files", "*.otpu")])

# Prompt user to select a CSV file for the selected template
csv_file_path = filedialog.askopenfilename(title=f"Select CSV File for {os.path.basename(template_file_path)}", filetypes=[("CSV Files", "*.csv")])

# Load the CSV file into Origin worksheet
wks = op.new_sheet()
wks.from_file(csv_file_path, False)

# Create a new graph using the selected template for graph 1
gr = op.new_graph(template=template_file_path)

# Add plot to the graph using the data from the worksheet
gr[0].add_plot(wks, 1, 0, type=230)
gr[0].rescale()

# Tile all windows
op.lt_exec('win-s T')

# Prompt user for the output Origin file name
output_file_path = filedialog.asksaveasfilename(title="Save Output Origin File", filetypes=[("Origin Project Files", "*.opju")])

# Save the project to the specified output file path using both op.oext and op.save
if op.oext:
op.save(output_file_path)
else:
gr.save(output_file_path)

Appreciate any help :)


PAVI
minimax Posted - 11/02/2022 : 01:13:58 AM
quote:
However, in my case these lines still won't work.


Hi Sciroccogti,

Would you mind to paste your real script which has the problem?
Sciroccogti Posted - 10/28/2022 : 10:35:06 AM
I dont think so. The 'save' button still works well. It's quite weird.

quote:
Originally posted by YimingChen

Maybe you don't have the privilege to write to the drive. Can you run Origin as administrator and try the script again?

quote:
Originally posted by Sciroccogti

However, in my case these lines still won't work.

It seems that originpro can only save files to UFF(user files folder).

And if I try to save manually by
Ctrl+S
, it will complain
failed-fwd-i-search: _




YimingChen Posted - 10/28/2022 : 10:15:27 AM
Maybe you don't have the privilege to write to the drive. Can you run Origin as administrator and try the script again?

quote:
Originally posted by Sciroccogti

However, in my case these lines still won't work.

It seems that originpro can only save files to UFF(user files folder).

And if I try to save manually by
Ctrl+S
, it will complain
failed-fwd-i-search: _


quote:
Originally posted by cpyang

Can you first do something very simple to check if basic things working?
Like this


import originpro as op
op.new_sheet()
op.new_graph()
fn = r"c:\ab cd\test.opju"
op.save(fn)


CP




Sciroccogti Posted - 10/28/2022 : 04:07:22 AM
However, in my case these lines still won't work.

It seems that originpro can only save files to UFF(user files folder).

And if I try to save manually by
Ctrl+S
, it will complain
failed-fwd-i-search: _


quote:
Originally posted by cpyang

Can you first do something very simple to check if basic things working?
Like this


import originpro as op
op.new_sheet()
op.new_graph()
fn = r"c:\ab cd\test.opju"
op.save(fn)


CP


niaji Posted - 10/14/2022 : 08:04:03 AM
quote:
Originally posted by minimax

quote:
op.save(r'D:/'+'Nw.opju')


Origin's python does NOT support slash in path.

So for now you will have to change the script to use backslash, like
op.save(r'D:\Nw.opju')



WOW, that works. I even don't try to save but use detach() to save file by my own, lol. Thank you very much.
minimax Posted - 10/13/2022 : 9:53:39 PM
quote:
op.save(r'D:/'+'Nw.opju')


Origin's python does NOT support slash in path.

So for now you will have to change the script to use backslash, like
op.save(r'D:\Nw.opju')
niaji Posted - 10/13/2022 : 08:36:30 AM
quote:
Originally posted by minimax

quote:
What if this script doesn't work? What should I check?
BTW, it works if I run with this: op.save(op.path('u')+ 'Simple.opju')


Would you mind to paste your real script which has the problem?

And the detailed error message?


Hi, minimax, thx for your reply,
my script is very simple:
import originpro as op
op.new_sheet()
op.new_graph()
op.save(r'D:/'+'Nw.opju')

it runs without any error message but just no file produced. it only works when I save the opju into the op.path('u') folder, even the op.path('e') doesn't work.
minimax Posted - 10/12/2022 : 9:43:08 PM
quote:
What if this script doesn't work? What should I check?
BTW, it works if I run with this: op.save(op.path('u')+ 'Simple.opju')


Would you mind to paste your real script which has the problem?

And the detailed error message?
niaji Posted - 10/11/2022 : 09:57:29 AM
quote:
Originally posted by cpyang

Can you first do something very simple to check if basic things working?
Like this


import originpro as op
op.new_sheet()
op.new_graph()
fn = r"c:\ab cd\test.opju"
op.save(fn)


CP



Hi, dear Cpyang,
What if this script doesn't work? What should I check?
BTW, it works if I run with this: op.save(op.path('u')+ 'Simple.opju')
cpyang Posted - 07/29/2021 : 06:55:40 AM
I am glad that helps.

You can google "python raw string notation"

CP


Kositi Posted - 07/29/2021 : 03:39:14 AM
Wow this is working. Thanks
What is the r before the string stands for?
It seems like this matters :)
cpyang Posted - 07/28/2021 : 6:14:30 PM
Can you first do something very simple to check if basic things working?
Like this


import originpro as op
op.new_sheet()
op.new_graph()
fn = r"c:\ab cd\test.opju"
op.save(fn)


CP
Kositi Posted - 07/28/2021 : 2:02:04 PM
I tried to remove it and it still doesn´t safing the opju file. I also tried it with op.project.save(directory+name). Evertime I try to save the file outside the Origin folder it fails. I am not sure if this due to my diretory names (I have spacebars in the folder names) or if I need to go up in the directory. I also tried it with the os.path.join function and still no file in my folder.
YimingChen Posted - 07/28/2021 : 11:24:33 AM
You don't need
op.path("u")+
in the line.

James

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