Callback system between .NET plugin

#1

Hello guys,
I need to communicate between to .NET plugin.
For instance, I have the max2babylon plugin that needs to raise a callback passing a list of textures used by the exporter.

Another plugin needs to register to this callback, but that is where I’m stuck.
Any idea?

#2

Heya,
I’m just copy and pasting some example code I have lying around. I hope it still works :slight_smile:

More on the topic:
http://blog.duber.cz/3ds-max/using-net-controls-in-net-forms-in-maxscript
http://helephant.com/2004/11/03/raising-custom-events-in-c/

code for the C# dll:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace maxEvent
{
    public class Class1
    {
        public event EventHandler myEvent;

        protected virtual void onMyEvent(EventArgs e)
        {
            if (myEvent != null)
                myEvent(this, e);
        }

        public void testFunction()
        {
            MessageBox.Show("test");
            onMyEvent(EventArgs.Empty);
        }
    }
}

And the MXS part:

dllPath = @"C:\\maxEvent.dll"
// this script starts a .NET form.
// when the form is displayed it generates an event.
// the event will trigger the handleEvent MXS function.

fn handleEvent _args=(
	print "exec1"
)

Assembly = dotNetClass "System.Reflection.Assembly" 
Assembly.loadfrom dllPath
form = dotnetobject "maxEvent.Class1"

dotNet.addEventHandler form "myEvent" handleEvent

form.testFunction()
#3

Actually there is no maxscript in my case, but thanks anyway
I managed to raise a callback from the first plugin and register the second plugin to that callback

GlobalInterface.Instance.BroadcastNotification(SystemNotificationCode.PreExport, filePaths);

in the second plugin I grab the callback with

IGlobal global = Autodesk.Max.GlobalInterface.Instance;
IInterface18 ip = global.COREInterface18;
if (!callbackRegistered)
{
     this.fileSaveHandler = new GlobalDelegates.Delegate5(this.Global_PreFileSave);
     GlobalInterface.Instance.RegisterNotification(this.fileSaveHandler, null,SystemNotificationCode.PreExport);
     callbackRegistered = true;
 }

Now the problem is that i need to retrieve an object between these two plugins