# Saving projects

**URL:** <https://forum.qoitech.com/t/saving-projects/445>\
**Category:** Automation Toolbox\
**Created:** [September 6, 2022, 9:35am UTC](https://forum.qoitech.com/t/saving-projects/445 "2022-09-06T09:35:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [September 6, 2022, 9:35am UTC](https://forum.qoitech.com/t/saving-projects/445/1 "2022-09-06T09:35:27Z")

</div>

Hi,

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

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

```

then :

```auto
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

---

<div class="post-metadata">

**Author:** ![bjorn.rosqvist](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/bjorn.rosqvist/32/238_2.png) [@bjorn.rosqvist](https://forum.qoitech.com/u/bjorn.rosqvist)\
**Post date:** [September 6, 2022, 1:42pm UTC](https://forum.qoitech.com/t/saving-projects/445/2 "2022-09-06T13:42:01Z")

</div>

Hi,

Try replacing / with \ in the proj\_filename

Best regards,  
Björn

---

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [September 6, 2022, 1:45pm UTC](https://forum.qoitech.com/t/saving-projects/445/3 "2022-09-06T13:45:41Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![bjorn.rosqvist](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/bjorn.rosqvist/32/238_2.png) [@bjorn.rosqvist](https://forum.qoitech.com/u/bjorn.rosqvist)\
**Post date:** [September 6, 2022, 2:30pm UTC](https://forum.qoitech.com/t/saving-projects/445/4 "2022-09-06T14:30:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [September 12, 2022, 7:38am UTC](https://forum.qoitech.com/t/saving-projects/445/5 "2022-09-12T07:38:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bjorn.rosqvist](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/bjorn.rosqvist/32/238_2.png) [@bjorn.rosqvist](https://forum.qoitech.com/u/bjorn.rosqvist)\
**Post date:** [September 14, 2022, 6:20am UTC](https://forum.qoitech.com/t/saving-projects/445/6 "2022-09-14T06:20:10Z")

</div>

Try something like this

```auto
#!/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!")

```

---

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [September 14, 2022, 6:36am UTC](https://forum.qoitech.com/t/saving-projects/445/7 "2022-09-14T06:36:46Z")

</div>

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
