イベントとは

 
 
 

Softimage では、新しいシーンの作成、フレームのレンダリング、キー入力などユーザの操作によってイベントが実行されます。 たとえば、ユーザが新しいシーンを作成すると、OnBeginNewScene および OnEndNewScene イベントがトリガされます。

イベントを処理する特殊な関数を記述して Softimage にイベント ハンドラとして登録することができます。 イベントがトリガされるたびに、そのイベント用に登録されているイベント ハンドラが呼び出されます。

たとえば、次は、特定のタイプ(ファイル形式/拡張子)に一致するファイルがシーンにドロップされた際に、カスタム ファイル読み込み機能を起動する方法を示します。 これは、適切なファイル拡張子が検知された場合に、ドラッグ アンド ドロップ イベントを使用してカスタム読み込み機能を呼び出すというしくみです(下の siOnDragAndDropEvent_OnEvent コールバックを参照)。

Python の例: 自己インストールによるドラッグ アンド ドロップ イベント ハンドラ

# 
# 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 Perl's or 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