Re: designing a self-installed plugin...

Date : Mon, 03 Apr 2006 13:56:26 +1000
To : XSI(at)Softimage.COM
From : Rafe Sacks <rafes(at)al.com.au>
Subject : Re: designing a self-installed plugin...
Title: RafeSignature
"Now lets say the above library is returned by a command called GetLibrary()."

The object or Library is returned by a command. The benefit, in this case, becomes obvious when you have a bunch of functions you want access to. Lets say you have 10. That would be 10 commands to register and support. If you made those methods of an object, you only have to register 1 command but you still have access to all the functions. If nothing else, it is an organizational tool. As object-oriented coding gets more advanced however, it becomes very powerful. Especially across large projects.

If the object is in the same file, you can get it using "new". in my example, the object is called "Library" so to get an instance of it, this is the syntax:
var oLibrary = new Library();
Other wise a command has to return it:
function GetLibrary_Execute()
{
    return new Library();
}

var oLibrary = GetLibrary();


If you need an example of a simple object, I'm sure we would be willing to post a few. I just didn't want to hijack your thread any further.

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






Steven Caron wrote:
I think i got it. you write you main code as a function with objects. and use them inside callbacks available to you as self-installed plugins?

how do you gain acess to the objects you wrote? since they aren't registered commands and they are not included in your plugin?

thanks

steven

On 4/2/06, Rafe Sacks <rafes(at)al.com.au> wrote:
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.