This project is read-only.

Calling class plugin x from plugin y

Dec 9, 2010 at 4:47 PM

We have a plugin that can do some processing on a shape file to return another shape in plugin x.  I would like to use that functionality in plugin y without linking in the entire codebase of x into the codebase of y.

Is such a thing possible?

Which also raises a plug-in depedency issue.  Will the system automatically try to figure that out?


Aaron Parks

Dec 9, 2010 at 5:32 PM

The AppManager should have a list of the plugins.  So basically getting a handle for your plugin is not a problem per say.  But the standard plugin interface probably does not have the definition on it for your specific method call or property that you want to invoke.  Say for instance  you want to invoke a method like "string result = ReadXML(string filename)".  The usual way to handle this is to add a reference in plugin x so that x knows what y is.  That way X can cast your IPlugin or whatever into a specific instance of an XMLReaderPlugin.  If you don't want to do that, and you have an instance of the object, you can use a bit of reflection hokeyness:

Using System.Reflection;

Type t = myPlugin.GetType();

MethodInfo m = t.GetMethod("ReadXML", BindingFlags.Instance | BindingFlags.Public);

object[] params = new object[] { "filename" };

object return = m.Invoke(params);

string result = (string)return;

The easier alternative is to create a shared interface, IReadXML where the method is defined in the common interface.  Both projects have a reference to the interface definition, but that definition is external to either project itself.  Then you can just use casting like:

IReadXML reader = myPlugin as IReadXML;

if(reader != null)


   string result = reader.ReadXML("filename");




Dec 9, 2010 at 8:42 PM



Is there a way for me to programatically activate a plugin?


Aaron Parks

RTI international.

Dec 9, 2010 at 9:17 PM

This was not possible up till now because I was only passing loaded plugins in with the plugin args.  Now I also pass in the AppManager.  The fix is as of a8670a8925ec

With a direct link to the AppManager you can activate and deactivate plugins now with that.





Dec 20, 2010 at 8:51 AM

A little off topic but how about auto loading plugins?

Dec 20, 2010 at 8:16 PM

My thought might be that we save a user setting like an application setting or something that controls which plugins are on or off so that the user can control this by default, rather than the plugin author.  I think there is a feature request for this that has been in the system for a long time, and I haven't prioritized it because we had so much important stuff going on.