Plugin.UserData

導入

v6.01

説明

Plugin オブジェクト内部のVariantデータを設定したり、戻したりします。Softimage では、データのコンテンツや意味によって制限されることはありません。簡単なタイプ、Array、オブジェクトリファレンスなどの広範なデータを保存できます。追加されると、Softimage が実行されている間、またはプラグインを手動でアンロードするまでの間、データはアクティブな状態になります。ユーザデータは継承されません。

注:Plugin.UserDataは、通常はプラグインモジュールでローカルでアクセスできる値や、他のプラグインによってグローバルにアクセスできる値を格納するために使用されます。スクリプトプラグインの場合は、プラグインモジュールで定義されているグローバル変数を使用する代わりに、Plugin.UserDataを使用することを強くお勧めします。このことは、プラグインがマルチスレッドで実行されるレンダリングオペレーションのコンテキストで特に重要です。プラグインが別のスレッドで実行される場合は、実行中のスクリプトエンジンのコピーが作成され、もう一度プラグインファイルが解析されます。このプラグインファイルは、プラグイン実装で参照されるプラグイングローバル変数を再初期化します。一方、Plugin.UserDataを使用すると、スレッド間の整合性を保つことができます。

Python の例

# How to access a plug-in user data
from win32com.client.dynamic import Dispatch 
# Optional global variable to speed up data access
g_userdata = None
def GetUserData():
        if ( g_userdata == None ):
                # Dictionary not defined yet
                # Get the plug-in object storing the dictionary
                myPlugin = Application.Plugins("My plugin");
                if ( myPlugin.UserData == None ):               
                        # Dictionary not defined yet, create it and add some object
                        dict = Dispatch( "Scripting.Dictionary" )
                        dict[ 'SurfPos' ] = XSIMath.CreateVector3()
                        dict[ 'OutPos' ] = XSIMath.CreateVector3()
                        # Store the new dictionary in the plug-in
                        myPlugin.UserData = dict
                # Cache the dictionary in this module for fast access
                g_userdata = myPlugin.UserData
        return g_userdata

関連項目

XSIApplication.UnloadPlugin PluginRegistrar.UserData