SaveSceneAs - file already exists.

Discussions concerning programming of SOFTIMAGE©
Post Reply
User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

SaveSceneAs - file already exists.

Post by Hirazi Blue » 07 May 2014, 15:32

If I try to save a scene through Python scripting using SaveSceneAs, without any dialog (i.e. using a full path), I do not get “the” warning that a file with the same name already exists and if I’d care to overwrite it. Is there a way to incorporate this check/warning into a scripted SaveSceneAs? I know I could build something similar using "os.path.isfile", but being able to use the "standard system" for that would be preferred.
Stay safe, sane & healthy!

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: SaveSceneAs - file already exists.

Post by csaez » 07 May 2014, 20:28

It doesn't shows up because Softimage assumes you checked the file path in advance, otherwise the dialog would stop the execution and that's not the way scripting works.
Explicit is better than implicit: Do you want to pause the script until user interaction? code it that way ;)

Code: Select all

import os
from siutils import si, siuitk, C


def save_as(filepath):
    if os.path.exists(filepath):
        ok = siuitk.MsgBox(
            "Do you want to replace the existing '{}'?".format(filepath),
            C.siMsgYesNo, "Save Scene As")
        if ok == C.siMsgNo:
            return False  # abort
    si.SaveSceneAs(filepath)
    return True

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: SaveSceneAs - file already exists.

Post by Hirazi Blue » 07 May 2014, 20:33

Okay, thanks. I obviously wrongfully assumed the file check was to be part of the SaveSceneAs, but as you demonstrated, something can be whipped up rather quickly that does something very similar.
Stay safe, sane & healthy!

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests