In Softimage, user actions such as creating new scenes, rendering frames, and pressing keys trigger events. For example, when a user creates a new scene, the OnBeginNewScene and OnEndNewScene events are triggered.
You can write special functions to handle events, and register these functions with Softimage as event handlers. Whenever an event is triggered, Softimage calls the event handlers registered for that event.
For example, the following demonstrates how to launch a custom file importer when a file matching a specific type (file format/extension) is dropped in the scene. This is done by using a drag and drop event to call the custom importer command when the correct file extension is detected (see the siOnDragAndDropEvent_OnEvent callback below):
# # Drag and drop events are intentionally disabled by default for performance, so the # drag portion of the event gives you the opportunity to enable drop detection while # the drop portion is where you can perform the desired action on the item. # import win32com.client from win32com.client import constants as c # to use Softimage enums and constants import re # for regular expressions # Registration def XSILoadPlugin( in_reg ): in_reg.Author = "SDK Doc" in_reg.Name = "ImportBooFile Plug-in" in_reg.RegisterCommand("ImportBoo","ImportBoo") in_reg.RegisterEvent("siOnDragAndDropEvent",c.siOnDragAndDrop) return 1 # Set up custom importer command def ImportBoo_Init( in_ctxt ): oCmd = in_ctxt.Source oCmd.ReturnValue = 1 oArgs = oCmd.Arguments oArgs.Add("in_filename",c.siArgumentInput) return 1 # Implementation of the importer def ImportBoo_Execute( in_filename ): Application.LogMessage( "Importing " + in_filename ) # # This is where you either implement the importer or call the implementation # return 1 # Callback for the siOnDragAndDropEvent event. The important thing to remember is that # the drag and drop event is a two-stage action: dragging and dropping. When the item # is being dragged, you can check to see whether it is something you want to pay # attention to after it's dropped (ie., if it's the right kind of file). If it is, you # enable the DragSourceSupported attribute so that when the file is actually dropped, # the siSourceDropAction is fired and you can call the importer. def siOnDragAndDropEvent_OnEvent( in_ctxt ): action = in_ctxt.GetAttribute("DragAndDropAction") file = in_ctxt.GetAttribute("DragSource") if ( action == c.siSourceDragAction ) : # When the file is dragged, check to see if it's got the right extension pattrn = re.compile( "\.boo$", re.I ) # equivalent to JScript's /\.boo$/i if ( pattrn.search(file) ) : # Enable the drop action via the DragSourceSupported # context attribute if it's got the right extension in_ctxt.SetAttribute( "DragSourceSupported", 1 ) else : # Otherwise disable the drop action in_ctxt.SetAttribute( "DragSourceSupported", 0 ) else : # action == c.siSourceDropAction # When file is , dropped, run your custom importer command ImportBoo_Execute( file ) return 1 # Output: # INFO : Importing <user_location>\Application\Plugins\test.boo
You can also see the Project Selector example that shows how to use the change project event (siOnChangeProject). This example is located in the examples folder of the Softimage SDK installation directory.
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License