Possible to store MaxScript in a .MAX file?


Is it possible to store a MaxScript into a 3dsMax file so that one wouldn’t need to have a separate .MS file?



Depends on the script, too. For example this script of mine will save its part at the rootNode in the form of custom attributes and its settings into appData. If I would write something like that again, it’d be quite different and I’d shove everything into the CA. You can use and abuse so many things… which reminds me, it also depends whether you want to use that just yourself/in an environment you can control and where you can impose certain rules or if it has to work for everyone everywhere. For some things, persistent variables may be perfect - and when you define your datastructures beforehands (let’s say you define some structs in a file inside the stdscripts folder), you can save structured data there with no issues.


What is the advantage of CA over appdata?


@Swordslayer, at least I know it can be done.

Could you please write me a little example, say a script that pops up a notification when I type eg “popup”, and have that code saved in the Max-file, either that the script does it or that you tell me where to store it


appData are just that, some data in a string form, while CA can store lots of stuff - to name just few:

[li]functions (that you can call from persistent callbacks - so to be consistent with the question at hand, you can have a dialog pop-up on filePostOpen)
[/li][li]rollouts and their UI thingies
[/li][li]maxObjects - want to reference a controller? store some mesh (existing or with createInstance Editable_mesh or TriMesh with RefTargContainer)?
[/li][li]and of course materials, textureMaps, bitmaps, assets, colors, points, matrices and so on

@Haider of Sweden: hijacking the keyboard input doesn’t really qualify as a little example…



No hijacking here. I mean the maxscrtipt mini-listener in the lower left corner. Eg I write “popup” to call the function that pops up something


Oh, that’s simple enough :slight_smile:

exampleCA = attributes example
	fn popupFn = format "Hey man!

	on load do ::popup = popupFn
custAttributes.add rootNode exampleCA

Although most of the time I’d prefer not making it global and simply use rootNode.example.popupFn() instead of popup()


I am currently not sitting on a Max computer.
However I am assuming that the “on load” means when the Max document is loaded

Also, this is stored in the Max file?


Yes, and yes - that’s the whole point.


I came a little late for this discussion but I am reading about how to load a script when a file is being loaded and trying to understand how is the best way.

In the case of just a UI rollout with up to 3 buttons… should I save that script on some specific folder or I can only story it as CA inside the scene. That means it does not link to a *ms file. ?

I am trying this example but I got it not working. I just copied pasted this script on a empty scene, evaluated the script - max listener says “true”, and I saved the scene. I expected to see “hey man” whenever I opened that scene again, no?



Sorry for not saying thank you back then, @Swordslayer! :flushed:

@bontempos - once you execute this code and save the file, you got this function stored in the file. I found it a little hard to see the result (unless you open the listener window) so I switched out “format” to “messageBox” to get something more visual.

@Swordslayer - I dont know what I did exactly, I might have run this code snippet multple times or so, but when I opened the file, I got multiple dialogue boxes popping up. From my understanding, the code is not intended to autorun, but rather waiting for you to run it.

  • What might have happened?
  • How can I autorun something, eg a welcome instruction message?
  • Where can I see the stored rootNode?


because every instance of the ‘example’ CA fires this message on load. That means you have more than one instance.
you can check it:



Sorry, I am using this computer remotely in a small screen and accidentally deleted previous post.
Contents might still be available but I am not sure how to unflag deleted post.

I am still not able to make the script to run automatically when scene opens.


@bontempos The code snippet was showing 1. How to store maxscript in a file. 2. How to load the script to be ready to run by typing a command. If you want it to just run when a file loads you can do the following.

exampleCA = attributes example
	fn popupFn = messageBox "Hey man!

	on load do popupFn()

custAttributes.add rootNode exampleCA