Cloned material callback

elpie89
Advocate
Advocate

Cloned material callback

elpie89
Advocate
Advocate

Hello I have a custom MaxMAterial and I need to execute some code when the material is cloned

I saw there is a method `on clone orig do`  but I want to retrieve the target and call a C# function on it 

Right now I'm registering to a #mtlRefAdded callback but this is called even when the file is opened 

 

Do you have any idea on how to do it?

Thanks

0 Likes
Reply
750 Views
3 Replies
Replies (3)

denisT.MaxDoctor
Advisor
Advisor

you should use "on clone" anyway. This event handler gives you the original plugin instance and your current one (which receives the event) is the target. You have access to both the source and the target and you can get all the parameters and states of both.

0 Likes

elpie89
Advocate
Advocate

Thanks, I didn't figure out this 

I was debugging printing "this.name" and the result was always the original name

Only printing an actual parameter I realized that "this" is the new cloned material

 

Another question how do we pass material between maxscript and C# ?

I need to call a c# method in maxscript loading a dll 

that is the easy part 

ones I called the method I cannot figure out how to actually pass the material as an object to the C# method 

 

Assembly = dotNetClass "System.Reflection.Assembly"
dllPath = symbolicPaths.getPathValue(1) + "\mydll.dll"
Assembly.loadfrom dllPath
maxScriptManager = dotNetObject "MyNamespace.MaxScriptManager"
maxScriptManager.myMethod(this)
 
so now how should I retrieve "this" that in my case is a material in the C# side? 
Thanks for your help
0 Likes

Serejah
Advocate
Advocate

@elpie89 wrote:
so now how should I retrieve "this" that in my case is a material in the C# side? 

Get the handle from 'this' and pass it to the other side

anim_handle = getHandleByAnim this

 

On c# side you can have it back using this:

GlobalInterface.Instance.Animatable.GetAnimByHandle( (UIntPtr)anim_handle );

 

0 Likes