Self-installable plugins otherwise known as callback heaven
February 27th, 2005 by Patrick Boucher - Viewed 3661 times - Popularity: 6% [?]Let’’s take a look
Here is the first callback, XSILoadPlugin, from PB_Render.
function XSILoadPlugin(in_reg) {
in_reg.Author = "Patrick Boucher";
in_reg.Name = "PB_RenderPlugin";
in_reg.Major = 1;
in_reg.Minor = 1;
in_reg.Email = "pboucher@xsi-blog.com";
in_reg.RegisterProperty("PB_RenderProp");
in_reg.RegisterCommand("PB_RenderCurrentFrame", "PB_RenderCurrentFrame");
in_reg.RegisterCommand("PB_RenderFrameSelection", "PB_RenderFrameSelection");
in_reg.RegisterMenu(siMenuTbRenderRenderID, "PB_RenderMenu", false, false);
return true;
}
The XSILoadPlugin callback is used to define the custom objects that your plugin implements. It is also a place where you can give XSI some information about your plugin, information that, among other things, will be available in the Plugin manager.
The argument “in_reg” is a PluginRegistrar object that is created by XSI and handed to you so you can register your plugin’’s custom components into XSI. So now you see the full loop of the callback. XSI calls into your file and, with the provided arguments and objects, you go back into XSI to do some real work.
in_reg.RegisterProperty("PB_RenderProp");
in_reg.RegisterCommand("PB_RenderCurrentFrame", "PB_RenderCurrentFrame");
in_reg.RegisterCommand("PB_RenderFrameSelection", "PB_RenderFrameSelection");
in_reg.RegisterMenu(siMenuTbRenderRenderID, "PB_RenderMenu", false, false);
These lines tell XSI that a PPG, two custom commands and a menu are being defined by our plugin. Without this information XSI would be at a loss as to what to do next. It would not know how to get at your defined elements.
This is when the second level of callbacks kicks in to define and initialize your custom items. Let’’s take a look at the PB_RenderCurrentFrame custom command.
function PB_RenderCurrentFrame_Init(in_context) {
var oCmd = in_context.Source;
oCmd.SetFlag(siNoLogging, false);
}
function PB_RenderCurrentFrame_Execute() {
// Get current frame
var oPlayCtrl = Application.ActiveProject.Properties.Find("PlayControl");
var curFrame = oPlayCtrl.Parameters.Item("Current").Value;
// Render the current frame
var oStart = startRender();
doRender(curFrame , curFrame);
stopRender(oStart);
}
These are two callback that XSI expects to find after the registration of the custom command. Notice how they are called. XSI expects to find the script name of your registered item with the ”_Init” or ”_Execute” suffix. Thus is the pattern you have to follow for the custom command.
The MyScriptNameOfCommand_Init function is called once when your command is born inside XSI. Its in_context argument is an object of type Context that gives you acces to the created command object through the Source property. Hats off to the Softimage crew who thought about future growth issues when writing this plugin callback system. The Context object can change in future XSI versions to add some more functionnality and past versions of plugins won”t be broken because the callback definition will not have changed! How cool is that? … Wow, is my geeky side showing here or what?
The MyScriptNameOfCommand_Execute function is called when something in XSI (a button, a scripting command) actually activates the custom command. Then something is actually done: in this case, the current frame of the sequence is rendered.
Popularity: 6% [?]



