Notifications
Clear all

[Closed] checkForSave() question

Hi there,

I’ve been trying to get my head around the checkForSave() function, it should be simple but I can’t get it to make sense.

It seems that there is no way to detect if the user clicks yes or no – it checks if you click cancel, but yes and no both return true. It seems quite strange to have two buttons that return the exact same result – yet there’s nothing in the documentation to suggest otherwise.

Any help appreciated, as always.

8 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

there is no way to get what button (yes or no) user clicked. But you can get the file’s modification date (getFileModDate) before the calling of checkForSave and after and make up a conclusion about user’s action.

I think this is right, i grabbed old code, so I might be wrong. Basically, you check if the path is undefined or not (Hit cancel or No), if it isn’t then they hit yes.

on saveToFile  pressed do
 		(
 			
 				if screenFolderPath == undefined then
 				(
 					screenFolderPath = getSavePath caption:"Save Screenshot to.." initialDir:"$scripts"
 					screenFolderLocation.text = screenFolderPath as string
 				)
 			
 				else
 				(
 					screenFolderPath =  getSavePath caption:"Save Screenshot to.." initialDir:(screenFolderPath)
 					screenFolderLocation.text = screenFolderPath as string
 				)
 			
 		)

of course the user can save the file with a new name… in this case maxfilepath or maxfilename will be changed.

 lo1

what about calling getSaveRequired() right after the dialog?
If the user did save, this function should return false.

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

that’s the best solution. i just forgot about this…
actually you can call it right before as well…

(@mixx)
Joined: 11 months ago

Posts: 0

I don’t think so, since checkForSave() doesn’t save on it’s own – it requires you to determine whether it should actually save anything (which is why I’d want it to return the users answer to that very question).

Thanks for your replies everyone – it seems to me checkForSave is a somewhat useless function then*, since it doesn’t actually perform any saving of it’s own, and two of the buttons return the same result, so I can’t base any logic on whether to save or not on the feedback from checkForSave. That said, I suppose I can work around it.

*at least for my purposes, there might be uses I just can’t see them

I would have expected checkForSave to return “yes,no or cancel” or “true, false or undefined” based on which of the three buttons were pressed though – does anyone know why it doesn’t? (or is it just one of those things that MaxScript does to toy with your sanity?)

The CheckForSave() simply triggers the internal mechanisms of Max for dealing with an unsaved scene before opening or resetting. It was not written for MAXScript, it just exposes some pre-MAXScript SDK method (read: pre-Max 2.0!).

To do what you want, you can build your own better mouse trap using getSaveRequired() which will tell you if the scene should be saved or not, and a yesNoCancelBox(), something like

fn CheckForSaveForReal =
(
if getSaveRequired() then 
	yesNoCancelBox "The Scene has been modified.
Do you want to save your changes?" title:"3ds Max"
else 
	#no
)

This does not save, just answers the question with #yes, #no or #cancel. It will also return #no if the scene was not modified.

1 Reply
(@mixx)
Joined: 11 months ago

Posts: 0

Thanks Bobo – yeah that’s what I was planning to do, to “work around it”, as it were. Thanks for the explanation – it’s always nice to know a few of the “why’s” as well as the “that’s-just-the-way-it-is’s”