Notifications
Clear all

[Closed] Binding a Script into a Max File

hello,everyone.
As I know,We can use Command Line or \Startup etc. to open max file with a script.
but now,
If I only have a Max file,how can i write a script into it?
yeh,i meaning that a max file including a script.

23 Replies

You can store your script as a string in any object custom attribute or appData. The object can be the root node if you want.
Then you can run it through the ‘execute’ command.

If you need the script to run automatically when the scene is opened, you have to create a persistent callback in your scene.

1 Reply
(@fusionyuan)
Joined: 10 months ago

Posts: 0

thanks aaandres,i got it here
I know how to add CA now,
but i don’t know how to run automatically with callback in this case.do you have time to show me a example plz?

thanks for help. i made it.here is my example.

exampleCA = attributes example
(
	fn CAMES = messagebox "CallBack be added via CA"
	fn CallBackAdd = callbacks.addScript  #filePostOpen  "CAMES()" id:#CAMES persistent:true
	on load do
	(		
		print "loading..."
		::popup = CallBackAdd()
	)
)
custAttributes.add rootNode exampleCA 

Few notes:

:: popup = functionCall() means assign the result of this function to a global variable ‘popup’ – I used that in the original example to make a function global, it doesn’t make sense here

‘on load’ event gets run everytime the file is loaded – you can either do what you want to do while loading the file here OR use the persistent callback – and in that case you’d assign the persistent callback only once, that’s the whole point. If you want to do something simple, you don’t need custom attributes for that and persistent callback will do. Similarly, when you use custom attributes and what you want to do happens during file load, you don’t need the callback.

1 Reply
(@fusionyuan)
Joined: 10 months ago

Posts: 0

thanks for your tips.i know what you mean.
with “on load” event.if i do some action only once everytime file is loaded.unnecessary to use callback.just add them into “on load” make it more simple.
actually,My aim is,i want a max file can’t be render or save. maybe i should use #preRender etc. for checking.
do you have a better way to my aim?

by the way,meshSurface is usefull for me.it’s great.

If you want a file like that, use DWF – max file format is not suitable for that. If someone wants to get the objects from that file, nothing will ever prevent him from merging them to a new scene, if they need the render settings as well, nothing’s easier than saving and loading them in the new scene. Also, for convenience all scene callbacks can be easily removed with callbacks.removeScripts() – and as you’d be using preRender and filePreSave callbacks, this simple command would remove all your protection. If you want a ‘share-safe’ format, the support for such features has to be a part of its specifications.

Btw. glad that you like it

I was thinking about those points you said before.

  1. About merging.in the case before,CA “on load” event. if i add a callback before the Scene objects are accessible.make it exit from merging.is it work?
  2. as i know,remove callbacks need the id name.and “callbacks.show” can lists out the current callback scripts,but if I add a callback( for example clearListener / 1 sec ),then i can’t see the cabllbacks.show result in the listener.in this case,how can i remove a callback script that i don’t know the Id name.
    this case is not mine,i saw other guys do that.
  3. the last.i agree with u that.anyway for this aim can’t stoping a guy who knows maxscripts well.but i just use for some of my client.

here is the max file the guy made.download

no chance.

actually there is one – make the file not readable for max

good idea man!

Did you try it? callbacks.removeScripts() without arguments removes all callbacks. Put it in the macrorecorder in minilistener/maxscript listener and evaluate it, callbacks are gone. Now what will you do? And you don’t need to know maxscript, google will helpfully point you to this info (this thread, for example).

1 Reply
(@fusionyuan)
Joined: 10 months ago

Posts: 0

haha,thanks to tell me the true.

there is another reality without Google.

Page 1 / 2