Self-installable plugins otherwise known as callback heaven

February 27th, 2005 by Patrick Boucher - Viewed 2916 times - Popularity: 5%




Property Pages

As stated earlier, self-installable plugins can define PPGs without the need of SPDL. Again, callbacks come to the rescue! Remember this line from the XSILoadPlugin function?

in_reg.RegisterProperty("PB_RenderProp");

Well, it’’s use is to tell XSI that the plugin being registered implements a PPG called PB_RenderProp. Then, like our custom command, the second layer of callbacks comes into play to define and initialize this custom PPG.

function PB_RenderProp_Define(io_Context) {
var oProp;
oProp = io_Context.Source;
// Get the start, end and current frames for the parameter creation
var oPlayCtrl = Application.ActiveProject.Properties.Find("PlayControl");
var curFrame = oPlayCtrl.Parameters.Item("Current").Value;
var startFrame = oPlayCtrl.Parameters.Item("In").Value;
var endFrame = oPlayCtrl.Parameters.Item("Out").Value;
oProp.AddParameter2("UseFrmSeq",siBool,false,null,null,null,null,0,siPersistable);
oProp.AddParameter2("StartFrm", siInt4, curFrame, null, null, startFrame, endFrame, 0, siPersistable);
oProp.AddParameter2("EndFrm", siInt4, curFrame, null, null, startFrame, endFrame, 0, siPersistable);
fs = oProp.AddParameter2("FrmSeq",siString,"",null,null,null,null,0,siPersistable);
fs.ReadOnly = true;
}


function PB_RenderProp_DefineLayout(io_Context) {
var oLayout, oItem;
oLayout = io_Context.Source;
oLayout.Clear();
oLayout.AddItem("UseFrmSeq", "Use Frame Sequence");
oLayout.AddItem("StartFrm", "Start Frame");
oLayout.AddItem("EndFrm", "End Frame");
oLayout.AddItem("FrmSeq", "Frame Sequence");
}

These two callbacks define the property itself and the layout of the property. This is what is effectively replacing SPDL for me in my plugins. This programatic access to custom property layout also means that you can alter UI layout during the life of a PPG if you desire to do so. The weirder stuff you can do the happier I am, that’’s the way my brain works. ;)

And when you have to take action after a UI action the third layer of callbacks comes into play. This is the same layer you most probably allready know from the SPDL logic block.

function PB_RenderProp_UseFrmSeq_OnChanged() {
var isOn = PPG.UseFrmSeq.Value;
PPG.StartFrm.ReadOnly = isOn;
PPG.EndFrm.ReadOnly = isOn;
PPG.FrmSeq.ReadOnly = !isOn;
}

In this case, according to a checkbox boolean toggle, items are made readonly or not as to alter the UI and make it obvious what functionality you are using.

There is one thing I would like to bring your attention to. Did you notice that the PPG variable is not declared anywhere in the preceding block? That’’s because it isn”t. It’’s given to you free of charge and no questions asked. While it is very generous of the XSI scripting engine to do so, I would have prefered the UI element the function is responding to be given to the function through an argument and from there through some sort of parent property, access to the PPG be provided. I prefer explicit to implicit. While we”re at it I probably would have had UI callbacks be manually registered instead of dynamically expected but that’’s me.

Knowing your callbacks

Writing a self-installable plugin is all about knowing your callbacks. Once you have defined the cutom elements that your plugin is going to be using in these callbacks the code looks just as if you were writing object model code inside the XSI script editor in a fire and forget script. Unlike the fire and forget script, your plugin is available automatically when XSI loads, it’’s easilly manageable and easily distributable. Add a bit of menu integration and it’’s like your plugin has always belonged in the XSI interface!

As further reading I do suggest you search for ”Self-installing Plug-ins” in the XSI SDK docs. These pages are very well written and are very easy to understand.

See you later!

Pages: 1 2 3

Leave a Reply