Saving projects

Hi,

I would like to save my otii project.
For this, I use python and write :

def saving_project(project_id,filename):
    project_id.save(filename)

then :

try:
    otii_object = otii.Otii(connection)
    devices = otii_object.get_devices()
    if len(devices) == 0:
        print("No Arc connected!")
        sys.exit()
    my_arc = devices[0]
    proj = check_create_project(otii_object)
    enable_channels_record(otii_object, proj, my_arc)
    #filename for project : 
    proj_filename = "C:/Users/guillau1/Documents/Test automation/otii_projects/test.otii"
    saving_project(proj,proj_filename)

But it doesn’t work. I have the following error : “Error message: Save failed, no file name specified”. I tried others ways to write the command but this is always the same message.
Can you help me please ?
Thanks

Hi,

Try replacing / with \ in the proj_filename

Best regards,
Björn

Hi, thank you

But I had the right filename because now I have this error :
“SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape”

Hi,

The forum formatted my text and I didn’t see it.
It should be two \ characters, but the forum changes to one.

Best regards,
Björn

Hi,
I’ve always same error : “Error message: Save failed, no file name specified”
I tried all combinations for the path. Can you please send me one working script ?
Maybe something is wrong on mine. I may have forgot something
Thank you !
BR,
Solene

Try something like this

#!/usr/bin/env python
import time
import sys, os

sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..')))

from otii_tcp_client import otii_connection, otii_exception, otii

HOST = {
    # IP address of the server
    "IP":"127.0.0.1",
    # Port number the server is listening on
    "PORT":1905
    }

def setup_device(my_device, voltage=3.0, overcurrent=1.0, channels=["mc"]):
    my_device.set_main_voltage(voltage)
    my_device.set_max_current(overcurrent) # Set overcurrent limit
    for channel in channels:
        my_device.enable_channel(channel, True) # Enable channels, default main current

# Check if there is already an active project otherwise create a new
def check_create_project(otii_object):
    proj = otii_object.get_active_project()
    if proj:
        print("Project already active, close active project to continue")
        sys.exit()
    else:
        proj = otii_object.create_project()
        print("Project created")
    return proj

def measure(proj, my_device, duration=1):
    my_device.set_main(True) # close output relay
    proj.start_recording() # start a recording
    time.sleep(duration)
    proj.stop_recording()
    my_device.set_main(False) # close output relay
    recording = proj.get_last_recording() # Get the data from the recording
    return recording

def save_project(proj, filename):
    proj.save_as(filename)

# Connect to Otii Arc, make sure that you have TCP server running
connection = otii_connection.OtiiConnection(HOST["IP"], HOST["PORT"])
connect_response = connection.connect_to_server()
if connect_response["type"] == "error":
    print("Exit! Error code: " + connect_response["errorcode"] + ", Description: " + connect_response["data"]["message"])
    sys.exit()
try:
    otii_object = otii.Otii(connection)
    devices = otii_object.get_devices()
    if len(devices) == 0:
        print("No device connected!")
        sys.exit()
    my_device = devices[0] # All connected devices are in the list devices, uses the first
    setup_device(my_device) # Setup the device to be used
    proj = check_create_project(otii_object) # Create the measurement project
    my_recording = measure(proj, my_device, 10)
    filename = "C://Bjorn//test_of_save.otii"
    save_project(proj, filename)

except otii_exception.Otii_Exception as e:
    print("Error message: " + e.message)

print("Done!")

Hi,

This works now, thanks !
My error was to write “proj.save(filename)” and not “proj.save_as(filename)”
I don’t find this precision anywhere but I’m new on Python so maybe this was obvious for others

Best regards,
Solene