Re: designing a self-installed plugin...

Date : Mon, 03 Apr 2006 09:05:17 +1000
To : XSI(at)Softimage.COM
From : Rafe Sacks <rafes(at)al.com.au>
Subject : Re: designing a self-installed plugin...
Title: RafeSignature
This is a bit long winded... let me know if it makes sense...

Strictly from a code design point of view, I like to keep my main code and UI separate. It makes changes easier to implement and it doesn't muddy up the top level code with a bunch of UI vs command line handling. I tend to put all code in objects then treat the menu as a user. In other words, I use the menu callbacks to run a short script which calls external code with the right variables. For example, lets say I have this library

function Library()
{
    this.DoSomething( iHowManyTimes )
    { 
       for ( var i - 0; i < iHowManyTimes; i++ )
       {
           LogMessage( "Doing Something..." );
       }
    }
}

Now lets say the above library is returned by a command called GetLibrary(). Lets also assume your scene property has a parameter called 'HowManyTimes'. The callback looks like this...

MenuCallback_DoSomething()
{
    var oProp = ActiveSceneRoot.Properties( "YourSceneProperty" );
   
    // All UI Work goes here...
    //    Inspect the property siModal
    //    If the user clicks ok, continue on, else quit.

    var iTimes   = oProp.HowManyTimes.Value;
    var oLibrary = GetLibrary();

    oLibrary.DoSomething( iTimes );
}

I find I almost never put code directly in commands these days. Usually, if a command is needed (which tends to only be the case when some special batch mode system is needed - human users should just know how to use my objects  ;-) ), I'll just wrap the object call in the command. It provides a buffer which makes code changes under-the-hood easy without affecting end users (human or otherwise).

________________________________
R A F E   S A C K S
Lead Character TD - Technical
Animal Logic Film
+612  9383 - 4800






Steven Caron wrote:
Hey Everyone,

I have been having trouble deciding how to implement a set of scripts, menus, and properties together as one plug-in. I am hoping someone can share some insight.

i have some custom data/info that i need in the scene so the user can modify these defaults and store those changes to be exported later. so i need a self-installed property. for convenience i would like this property to be put in a menu in the UI so it can be called up easily/intuitively. so i need a self-installed menu. now here i am having trouble...

should i make a command that adds the property to the scene and use menu.AddCommandItem or should i use the menu.AddCallBackItem? AddCallBackItem seems easiest to implement because its just another function i make in the plugin and not actually register it as a command, but i wouldn't be able to call this function anyother way but by pressing the button.

are there any other reasons why one would use one or the other? i am hoping someone with a ton of experience in this area could guide me away from some pitfalls later because i still have probably 10 properties/commands that need menu items associated with them.

thanks

Steven

Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.