[Closed] MXS #mtlRefAdded callback question
Hi guys. I’m trying to act on a material after I drag&drop it to another slot.
This is just an example script:
fn replaceMat =
(
mat = callbacks.notificationParam()
slot = medit.GetActiveMtlSlot() – as #mtlRefAdded is called when you drop a material in another slot in the material editorif mat (something something) do
(
tempMaterials = loadTempMaterialLibrary “C:\matLib.mat”
medit.PutMtlToMtlEditor tempMaterials[1] slot
)
)callbacks.addScript #mtlRefAdded “replaceMat()”
this crashes max. I think this happens, because #mtlRefAdded is called several times after dropping a material to the slot, but when I change the material during that operation – something goes south. How can I execute my replacement AFTER all the #mtlRefAdded are finished? Or should I use some other callback event that happens after that? What is the order of events inside 3dsMAX ?
first of all take a look at this example:
callbacks.removescripts id:#my_mat_things
callbacks.addScript #mtlRefAdded "format \"material reference added:%\\n\" (callbacks.notificationParam())" id:#my_mat_things
Bun the code and select any slot in the material editor.
You can see many calls to the #material_reference_add event where nothing really has been added. This means that you cannot trust this event and use it in your case. So you should look at another solution.
But if you need to temporary stop the events calling during callback function execution, you can do it:
fn make_new_material =
(
callbacks.removescripts id:#my_mat_thing
callbacks.removescripts id:#my_mat_thing
slot = medit.getactivemtlslot()
mat0 = meditmaterials[slot]
n0 = mat0.name
n1 = n0 + "_copy"
mat1 = copy mat0
mat1.name = n1
replaceinstances mat0 mat1
format "% << >> %\n\txchanged\n" n0 n1
callbacks.addScript #mtlrefadded "make_new_material()" id:#my_mat_thing
)
callbacks.removescripts id:#my_mat_thing
callbacks.addScript #mtlrefadded "make_new_material()" id:#my_mat_thing