Maxscript scripted plugin instances

Hey guys, I’m trying to fix some problems with my scripted plugin, but this whole instance-vs-class thing going on with them is not exactly easy to work with.
The problem is, I want a general event callback to propagate something to all instances of the plugin. I used nodeEventCallBack first which does the callback on a per-instance level, but this is exactly what causes the problem I’m trying to fix (RTT dialog doesn’t like this method: my plugin clashes with it and causes errors).

So right now I have a general event callback that gets triggered (externally, not in the plugin), it comes up with some values, and needs to set these to every instance of the plugin. I’ve started a global struct that keeps track of every instance, by having them “report” to this object, passing their own reference by using “this”.

Now here’s my problem:

Help states

The this local variable always contains the MAXScript value corresponding to the current instance of the scripted plug-in. This variable provides a guaranteed way of accessing parameters on the new object within plug-in code (in case there are locals or globals with the same name), and it is a way of referencing the plug-in in case you want to store it to a variable.

This doesn’t really seem to work: when I try to access a property of the instance, it always errors and tells me it’s unknown. All I can access are the base class properties (like .name).

Am I doing something wrong? Is there a different way of doing this? It’s a bit difficult for me to figure out the best way to keep track of these instances, as they are created by user-input and there’s no decent callback event for their creation (it’s a material).

Hope to get some advice! Thanks!

Hey, I don’t have any experience with scripted material plugins so the solution might be slightly different, but I’ve run into the same problem making a scripted helper plugin. Within the helper plugin I had to do this to reference the actual helper object and not just the instance of my plugin.

(refs.dependentNodes this)[1]

I remember banging my head on this problem, I can’t remember who told me to use that, but its definitely not an obvious solution :slight_smile:

So to call the name of your material inside the plugin, try this.

((refs.dependentNodes this)[1]).name

If you look up refs.dependents and refs.dependentNodes in the maxscript reference there should be some more infoz.

It is possible that you have to define the property you want to acces in your parameters. Even thought it is an existing property, the plugin still needs to know that this property exists in your own scripted plugin.