Notifications
Clear all

[Closed] Saving Data in a MaxFile?

hello,

i was wondering, is it possible to save data in a max file?

Because I want to create a script where you can save data, like a string in the maxfile and that the script uses that data of the max file.

I could use external files but than i have the problem that when i do a incremental save or rename the file i will get problems. And also then you have multple files which ain’t that nice to work wih.

Is their a good way to approach this?
Maybe adding objects in the scene and use those to put data in them?

Any ideas?

thanks a lot!

5 Replies

There are so many ways to do it, I am not even sure where to start

Obviously, you can create a scene object and store the data in either a dedicated track in its parameter block, in its User Properties, or as AppData (which also uses strings). The beauty of this approach is that if you want to move the data to another scene, you can simply merge the object over.

Alternatively, you can apply a CustomAttribute to any other scene object and use its parameter block tracks to store the data. This is kind of dangerous because deleting a modifier is easier than deleting a (potentially hidden and frozen) scene object. But it is a possibility, especially if the data has to be “mobile” since you can move/copy a modifier between objects.

You can store the data as AppData in any object, including non-scene-object ones. The most often used one is the TrackView Root node which cannot be deleted and is thus the most solid location in the scene to store data in. The drawback is that you cannot easily move the data to another scene.

You can also create a persistent global variable and simply put the data in it. This is the easiest way and since around Max 9 it is also relatively safe (in earlier versions of Max, persistent globals weren’t behaving that well, e.g. trying to Merge a scene and canceling out would have still merged the persistent global, potentially polluting or destroying the existing data in the current scene). I often use this approach for data that is not vital, but useful (like sticky UI settings).

You can also dump arbitrary string data in the File Properties of the Max File. File Properties are saved in the header of the file and are accessible to Windows (since they are a standard Microsoft concept) so if you want to check whether a Max file contains certain data without opening the Max file, that’s the best way to go – in other words, not only a script operating on the current scene, but also a script peeking into files on disk can read the data, and even other script languages (e.g. Python, MEL or whatever) could probably access it.

There might be other approaches that I am missing, but this should be quite enough.

As you can see, each approach has pros and cons, so it depends on what your needs are.

thanks bobo! really good and useful overview for me

I think ‘AppData’ is the most interesting for the scripts that i have in mind

that was just what i needed, found some documentation about it in the maxscript help so think i can go further with this.

again thanks

You might not want this anyway, but something to keep in mind is that cloning a node does not clone the appdata settings for that node.

Martijn

Here is a quick test for saving appData in the scene Root:

resetMaxFile #noprompt
setAppData TrackViewNodes 20100803 "Testing 123"
getAppData TrackViewNodes 20100803
saveMaxFile "testrootappdata.max"
resetMaxFile #noprompt
getAppData TrackViewNodes 20100803
loadMaxFile "testrootappdata.max"
getAppData TrackViewNodes 20100803

--OUTPUT:
OK --scene reset
OK --appData written
"Testing 123" --reading appData shows correct value
true --saving Max file
OK --scene reset
undefined --reading appData from new scene contains no data
true --loading the saved scene again
"Testing 123" --reading the appData shows the correct value

ah k thanks for the heads up about that ,and thanks for the quick example, will check it out!