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
 op.save not working properly
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Kositi

Germany
4 Posts

Posted - 07/28/2021 :  05:53:22 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

YimingChen

1618 Posts

Posted - 07/28/2021 :  11:24:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You don't need
op.path("u")+
in the line.

James

Edited by - YimingChen on 07/28/2021 11:25:01 AM
Go to Top of Page

Kositi

Germany
4 Posts

Posted - 07/28/2021 :  2:02:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/28/2021 :  6:14:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Kositi

Germany
4 Posts

Posted - 07/29/2021 :  03:39:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Wow this is working. Thanks
What is the r before the string stands for?
It seems like this matters :)
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/29/2021 :  06:55:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I am glad that helps.

You can google "python raw string notation"

CP


Go to Top of Page

niaji

China
5 Posts

Posted - 10/11/2022 :  09:57:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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')
Go to Top of Page

minimax

351 Posts

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

niaji

China
5 Posts

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

minimax

351 Posts

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

niaji

China
5 Posts

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

Sciroccogti

2 Posts

Posted - 10/28/2022 :  04:07:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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



Edited by - Sciroccogti on 10/28/2022 04:16:22 AM
Go to Top of Page

YimingChen

1618 Posts

Posted - 10/28/2022 :  10:15:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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




Go to Top of Page

Sciroccogti

2 Posts

Posted - 10/28/2022 :  10:35:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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: _




Go to Top of Page

minimax

351 Posts

Posted - 11/02/2022 :  01:13:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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?
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 05/24/2023 :  08:35:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

YimingChen

1618 Posts

Posted - 05/24/2023 :  4:22:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 05/26/2023 :  11:25:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
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