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 add note window to my origin file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

pavi-chem

United Kingdom
26 Posts

Posted - 06/14/2023 :  12:10:39 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2022b (64-bit) SR1
9.9.5.171 (Academic)
Copyright © 1991-2022 OriginLab Corporation

Hi Origin team,

I am trying to add a text note with the information of the input prompts in the python script to keep track of the data files used but I am getting error as op.new_doc() doesn't exist, could anyone help with that?

origin_project = op.new_doc()
note_window = origin_project.add_note_window()

# Add notes with the file information
note_window.add_text("Graph 1 Information:")
note_window.add_text(f"Graph 1 Template: {os.path.basename(template_file_path_1)}")
note_window.add_text(f"Graph 1 Template Path: {template_file_path_1}")



Thanks a bunch!
Pavi.

minimax

351 Posts

Posted - 06/15/2023 :  06:28:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi pavi-chem,

Currently there is no python interfaces on note window.

We will try to improve it.

We added it to our record database: ORG-27294.
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/15/2023 :  5:03:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

thanks for the quick response. For now I am saving it as a separate text file. Looking forward for the update :)

Thanks a bunch!
Pavi.
Go to Top of Page

minimax

351 Posts

Posted - 06/26/2023 :  01:58:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi pavi-chem,

We have just released a new version of originpro, v1.1.7

https://pypi.org/project/originpro/1.1.7/

You can upgrade it on Connectivity menu - Python Packages.

Following is a sample script on notes window.
import originpro as op
import os

template_file_path_1=op.path('e')+'line.otpu'

nt1=op.new_notes()
nt1.append("Graph 1 Information:")
nt1.append(f"Template: {os.path.basename(template_file_path_1)}")
nt1.append(f"Template Path: {os.path.dirname(template_file_path_1)}")


More methods/properties can be seen on
https://my.originlab.com/forum/topic.asp?TOPIC_ID=47987
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/26/2023 :  07:14:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That was fast! thank you for updating here. My code will be even more better with this :)
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 07/11/2023 :  08:08:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I finally got to add the note information but I am keep getting an error "An error occurred: 'int' object is not callable"

I ma unsure where this is from and the code was running perfectly before I added the note part. could you help me sort it out please?


import originpro as op
import tkinter as tk
from tkinter import filedialog
import sys
import os


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)

try:
# Prompt user to select an Origin template file for graph 1
root = tk.Tk()
root.withdraw()
template_file_path_1 = 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_1)}",
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
gr1 = op.new_graph(template=template_file_path_1)
gr1[0].add_plot(wks, 1, 0)
gr1[0].rescale()

# Prompt user to select an Origin template file for graph 2
template_file_path_2 = filedialog.askopenfilename(title="Select Origin Template File for Graph 2",
filetypes=[("Origin Template Files", "*.otpu")])

# Prompt user to select an XLSX file for the second graph
xlsx_file_path = filedialog.askopenfilename(title=f"Select XLSX File for {os.path.basename(template_file_path_2)}",
filetypes=[("XLSX Files", "*.xlsx")])

# Load the XLSX file into a new worksheet
wks2 = op.new_sheet()
wks2.from_file(xlsx_file_path, False)

# Create a graph page with the user-selected template for graph 2
gr2 = op.new_graph(template=template_file_path_2)
gl2 = gr2[0]

# Prompt user for the range of columns to plot for graph 2
column_range = input("Enter the range of columns (e.g., 1-12) for graph 2: ")
start_col, end_col = map(int, column_range.split("-"))
y_columns = list(range(start_col, end_col + 1))

for col in y_columns:
plot = gl2.add_plot(wks2, col, 0)

# Group and Rescale the graph
gl2.group()
gl2.rescale()

# Prompt user to select an Origin template file for graph 3
template_file_path_3 = filedialog.askopenfilename(title="Select Origin Template File for Graph 3",
filetypes=[("Origin Template Files", "*.otpu")])

# Prompt user to select an XLSX file for graph 3
xlsx_file_path = filedialog.askopenfilename(title=f"Select XLSX File for {os.path.basename(template_file_path_3)}",
filetypes=[("XLSX Files", "*.xlsx")])

# Load the XLSX file into a new worksheet
wks3 = op.new_sheet()
wks3.from_file(xlsx_file_path, False)

# Create a graph page with the user-selected template for graph 3
gr3 = op.new_graph(template=template_file_path_3)
gl3 = gr3[0]

# Prompt user for the range of columns to plot for graph 3
column_range = input("Enter the range of columns (e.g., 1-12) for graph 3: ")
start_col, end_col = map(int, column_range.split("-"))
y_columns = list(range(start_col, end_col + 1))

for col in y_columns:
plot = gl3.add_plot(wks3, col, 0)

# Group and Rescale the graph
gl3.group()
gl3.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:
output_file_path = os.path.abspath(output_file_path)
op.save(output_file_path)

# Creating a notes window
nt = op.new_notes()

# Appending input information to the notes
nt.append("Input Information:")
nt.append(f"Graph 1 Template: {os.path.basename(template_file_path_1)}")
nt.append(f"Graph 1 CSV File: {os.path.basename(csv_file_path)}")
nt.append(f"Graph 2 Template: {os.path.basename(template_file_path_2)}")
nt.append(f"Graph 2 XLSX File: {os.path.basename(xlsx_file_path)}")
nt.append(f"Graph 3 Template: {os.path.basename(template_file_path_3)}")
nt.append(f"Graph 3 XLSX File: {os.path.basename(xlsx_file_path)}")

# Appending output file information to the notes
nt.append("\nOutput Information:")
nt.append(f"Output File: {os.path.basename(output_file_path)}")

# Displaying the note
nt.view()

except Exception as e:
print(f"An error occurred: {str(e)}")
op.exit()




Thanks a bunch!
Pavi.
Go to Top of Page

minimax

351 Posts

Posted - 07/12/2023 :  05:13:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi pavi-chem,

Firstly, this forum website supports code syntax display.

On editing you can click the "#" icon to add the code block notation.

And then you can paste the py scripts inside it, which can retain the indentation etc. for easier reading.

On the other hand, would you mind to paste the full error message log? like it should tell which line the error appears?
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 07/12/2023 :  05:35:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Minimax,

thanks for the response.

Sorry new to the forum and don't know how to use it properly. I added the program and screenshot of the error message in this g-drive: https://drive.google.com/drive/folders/1iTsgu27A215BDKowbooem94HnQgGe1pY?usp=sharing

import originpro as op
import tkinter as tk
from tkinter import filedialog
import sys
import os


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)

try:
    # Prompt user to select an Origin template file for graph 1
    root = tk.Tk()
    root.withdraw()
    template_file_path_1 = 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_1)}",
                                               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
    gr1 = op.new_graph(template=template_file_path_1)
    gr1[0].add_plot(wks, 1, 0)
    gr1[0].rescale()

    # Prompt user to select an Origin template file for graph 2
    template_file_path_2 = filedialog.askopenfilename(title="Select Origin Template File for Graph 2",
                                                      filetypes=[("Origin Template Files", "*.otpu")])

    # Prompt user to select an XLSX file for the second graph
    xlsx_file_path = filedialog.askopenfilename(title=f"Select XLSX File for {os.path.basename(template_file_path_2)}",
                                                filetypes=[("XLSX Files", "*.xlsx")])

    # Load the XLSX file into a new worksheet
    wks2 = op.new_sheet()
    wks2.from_file(xlsx_file_path, False)

    # Create a graph page with the user-selected template for graph 2
    gr2 = op.new_graph(template=template_file_path_2)
    gl2 = gr2[0]

    # Prompt user for the range of columns to plot for graph 2
    column_range = input("Enter the range of columns (e.g., 1-12) for graph 2: ")
    start_col, end_col = map(int, column_range.split("-"))
    y_columns = list(range(start_col, end_col + 1))

    for col in y_columns:
        plot = gl2.add_plot(wks2, col, 0)

    # Group and Rescale the graph
    gl2.group()
    gl2.rescale()

    # Prompt user to select an Origin template file for graph 3
    template_file_path_3 = filedialog.askopenfilename(title="Select Origin Template File for Graph 3",
                                                      filetypes=[("Origin Template Files", "*.otpu")])

    # Prompt user to select an XLSX file for graph 3
    xlsx_file_path = filedialog.askopenfilename(title=f"Select XLSX File for {os.path.basename(template_file_path_3)}",
                                                filetypes=[("XLSX Files", "*.xlsx")])

    # Load the XLSX file into a new worksheet
    wks3 = op.new_sheet()
    wks3.from_file(xlsx_file_path, False)

    # Create a graph page with the user-selected template for graph 3
    gr3 = op.new_graph(template=template_file_path_3)
    gl3 = gr3[0]

    # Prompt user for the range of columns to plot for graph 3
    column_range = input("Enter the range of columns (e.g., 1-12) for graph 3: ")
    start_col, end_col = map(int, column_range.split("-"))
    y_columns = list(range(start_col, end_col + 1))

    for col in y_columns:
        plot = gl3.add_plot(wks3, col, 0)

    # Group and Rescale the graph
    gl3.group()
    gl3.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:
        output_file_path = os.path.abspath(output_file_path)
        op.save(output_file_path)

    # Creating a notes window
    nt = op.new_notes()

    # Appending input information to the notes
    nt.append("Input Information:")
    nt.append(f"Graph 1 Template: {os.path.basename(template_file_path_1)}")
    nt.append(f"Graph 1 CSV File: {os.path.basename(csv_file_path)}")
    nt.append(f"Graph 2 Template: {os.path.basename(template_file_path_2)}")
    nt.append(f"Graph 2 XLSX File: {os.path.basename(xlsx_file_path)}")
    nt.append(f"Graph 3 Template: {os.path.basename(template_file_path_3)}")
    nt.append(f"Graph 3 XLSX File: {os.path.basename(xlsx_file_path)}")

    # Appending output file information to the notes
    nt.append("\nOutput Information:")
    nt.append(f"Output File: {os.path.basename(output_file_path)}")

     # Displaying the note
    nt.view()

except Exception as e:
    print(f"An error occurred: {str(e)}")
    op.exit()



Error window shows only this:
C:\Users\r01pg22\PycharmProjects\origin-template-1\venv\Scripts\python.exe C:/Users/r01pg22/AppData/Local/JetBrains/Toolbox/apps/PyCharm-C/ch-0/231.9011.38/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 56752 --file C:\Users\r01pg22\AppData\Roaming\JetBrains\PyCharmCE2023.1\scratches\testg2.py
Connected to pydev debugger (build 231.9011.38)
Enter the range of columns (e.g., 1-12) for graph 2: 1-13
Enter the range of columns (e.g., 1-12) for graph 3: 1-13
An error occurred: 'int' object is not callable
D_Lib: debug printing for files [.*] and level [100] is turned on
D_Lib: debug printing for files [.*] and level [200] is turned on
D_Lib: debug printing for files [.*] and level [300] is turned on

Process finished with exit code 0



Thanks a bunch!
Pavi.
Go to Top of Page

minimax

351 Posts

Posted - 07/12/2023 :  9:46:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The problem is on line
nt.view()


view is a property, not method.

So you need to call it as
nt.view=1
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 07/13/2023 :  07:21:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you, it worked :)
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