[Closed] If File name already exists, automatically save as another?
Ok, so I have integrated a one click export button into my rollout gui that saves the file in a directory etc. The problem however is that everytime I click Export it will automatically try to replace a previous exported file.
Is there anyway, when I click Export, for maxscript to check the directory for an existing name and if it exists and apply something like the uniquename?
The code I am currently using is from Deftang1 over on the AREA site:
select $copy*
newFileName = uniquename "Sword"
newFilePath = pathConfig.GetDir #export
completeFilePath = (newFilePath + "/" + newFileName)
I thought that the newFileName would be unique everytime i.e. Sword_001, Sword_002 etc, but I realise now Maxscript is just assigning the first uniquename it thinks of everytime. This is my problem.
Cheers, K
You could test to see if the filename that the script is currently using exists by doing a test on the openFile filestream command.
essentially you can try and read the file, and if it does not exist then it will return undfined. you could test for that, and if it reads the file, then the code could prompt you to make a new filename, or it could make a new one itself and try again.
this is the command:
openFile <filename_string> [ mode:<mode_string> ]
UniqueName means unique amongst scene nodes, it has nothing to do with files.
To check for a file’s existence, use doesFileExist <filename>
i think that will be easier in your case just generate unique name for every exported file with no check the file for existence. you can add for example suffix to base file name using current time in filetime format, like:
(dotnetclass "DateTime").Now.ToFileTime()
the highest number will give you the most recent export file.
Thanks everyone for your input, its is much appreciated. DenisT, your solution worked wonderfully as I only required some kind of simple arbitrary name that is unique every time a file is exported. I would never have thought of a date and time stamp, genius.
Thanks again everyone <3
K