[Closed] Controlling Save
If I wanted to control the saving of a max file would it be best to use the filePreSaveProcess?
I essentially want to the to make sure the maxfileName meets the required array count, if it does, then save the max file, else prompt an error message.
the filename format needs to be something along the lines of “1034_v011.max”
Filterstring with “_” and then made the array count match 2 it would work.
Your method seems quiete logic, the only thing I’d change is the kind of testing the input string.
I’d go with a regular expression on this, in your case like that:
pattern = "\d\d\d\d_v\d\d\d.max" -- define an input of that form <four digits>_v<three digits>.max
input = "1034_v011.max" -- your current input string
rgx = dotNetObject "System.Text.RegularExpressions.Regex" pattern
rgx.IsMatch input
-- Outputs: true
-- changing the input-string to something like "1024_a03d.max" will return "false"
I see you use \d for testing a digit. Is there an equivalent for a character?
Of course there is. \w should do the job for characters a-z and A-Z not sure about hyphens.
You got it. Great stuff man. I was un aware of this. I was looking around on http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx and never saw the \w method. That sure makes things better.
This is very useful.
I’ve not got to build a callback which tests the users input at same time and re-prompts if the users input is incorrect otherwise it continues to save the file. At a quick look around it doesn’t seem like it’s going to be as straight forward as expected on that end. I’m not sure which callback will work best if any.
Yes, the regex-stuff is a bit hard to find… I had to gather those stuff some months ago \s will work for white spaces by the way. I think there is some information on Wikipedia as well.
Not sure, why you’d have to check that immediately when the user types in the stuff. Why does it not work to let the user hit “okay” and then check if the input was correct, otherwise re-open the Save Dialog and letting him write the stuff again?
Not sure, why you’d have to check that immediately when the user types in the stuff. Why does it not work to let the user hit “okay” and then check if the input was correct, otherwise re-open the Save Dialog and letting him write the stuff again?
I would check immediately after the user hits “okay” or “save” but I don’t want to actually save the max file unless the file name meets the required format, otherwise re-open the Save Dialog. That’s what I want it to do.
As far as I know saving a file and opening the file save dialog are two different pairs of shoes. That’s why I was asking. What you might do is opening the dialog, let the user enter a name, hit “Save” and then check the name. I might be wrong, if the maxfile save dialog is different, but every other dialog works this way.
Yeah that is very true, there would have to be a few checks. One which tests the input if the maxfile is being saving for the first time and then another which tests if a user opens a file and tries to save it without a proper format.
Does that make sense?