| On this page |
Pythonビューアハンドル
概要 ¶
Houdini provides a framework for implementing custom viewer handles in Python, offering extensive capabilities to tailor the workflow of your Python states.
-
You can draw, pick, and highlight handle components using either drawable gadgets or drawable 2D.
-
You can extend mouse control using either hou.ViewerHandleDragger or
drawable2d.Dragger2Dspecifically for COP Python handles. -
Houdiniパラメータを使用してパラメータを定義し、特定のパラメータをPythonステートにエクスポートするように選択することができます。
-
hou.GeometryDrawableまたはhou.Drawable2Dを使用してガイドジオメトリを作成することができます。
-
ローレベルでマウス、キーボード、タブレットのイベントに応答することができます。
-
ユーザによるパラメータ設定の操作に応答することができます。
-
独自のコンテキストメニューを表示することができます。
-
様々なコンテキストレベルで実行することができます。
-
変更操作をUndoブロックにまとめることができます。
Viewer Handle Code Generatorを使用することで、様々なサンプルソースからソースコードを作成することができます。 Pythonハンドルソースコードを配置してHoudiniに登録すると、Pythonステートは、ハンドルのバインドを介して一般的な方法でそれらのコードを使用することができます。
Houdiniにビューアハンドルをインストールする方法 ¶
Python handles in Houdini can be implemented either within a Python file module or embedded directly within an HDA. Both methods require a registration callback to install the Python handle in Houdini, similar to the process used for registering Python states.
The registration callback, named createViewerHandleTemplate, defines the structure and behavior of the Python handle. This includes its
handle type name, parameters, gadgets, and more. Houdini uses this information to instantiate Python handle objects as needed by Python states.
For comprehensive details on defining the content of a Python handle, refer to hou.ViewerHandleTemplate.
To expedite the creation of Python handles, you can utilize the Viewer Handle Code Generator. This tool generates the basic handle code along with the necessary registration function. You can access the code generator through the Viewer Handle Browser window or the Handle script tab in the Operator Type Properties window for viewer handles embedded in an HDA.
While manual creation of the code is possible, the code generator accelerates the development process to quickly get your Python handle working without syntax errors.
The registration of Python handles occurs either during Houdini’s startup or through the use of registration APIs such as hou.ui.registerViewerHandle and hou.ui.reloadViewerHandle.
典型的な登録コールバックは以下のようになります:
def createViewerHandleTemplate(): """ このエントリポイントは、ビューアハンドルをHoudiniに登録するのに必須です。 """ handle_type = 'viewer_handle_intro1' handle_label = 'Viewer Handle Intro1' handle_cat = [hou.sopNodeTypeCategory()] template = hou.ViewerHandleTemplate(handle_type, handle_label, handle_cat) template.bindFactory(Handle) # 他のバインドをここで実装します。 return template
Note
PythonハンドルとPythonステートは、Houdini起動時にほぼ同時にインストールされますが、これら2つにおける登録の順番は重要ではありません。 Houdiniでは、PythonステートがPythonハンドルをバインドできるようにそのPythonハンドルが先にインストールされている必要はありません。 この登録の過程では、PythonハンドルパラメータとPythonステートノードパラメータ間のバインド情報のみが収集されます。 これらのバインドは、後でPythonステートが実行された時にHoudiniによって使用され、この登録の過程では、適切な検証が行なわれ、問題があればバインドエラーが起きます。
アセット内にハンドルを埋め込む方法 ¶
以下の手順は、Python ビューアハンドル を埋め込むためのSOPアセットの作成方法について説明しています。
-
Objectレベルで、⇥ Tabメニューから
Geoオブジェクトを作成します。
-
その
geo1ノードをダブルクリックして、ジオメトリネットワークの中に入ります。 -
⇥ TabメニューからSubnetworkノードを作成します。
-
その
subnet1ノードを右クリックして、 Digital Asset → Create New を選択します。 -
Type Name を
handle_demo、 Asset Label をHandle Demo、 Library Path をEmbedded in .hip Fileに設定します。ライブラリの保存先を
Embeddedに設定すると、そのアセットはアセットライブラリではなく現行シーンファイル内に保存されます。 -
Author 、 Branch 、 Version のチェックボックスのチェックを外します。
-
そのアセットのType Propertiesウィンドウが開きます(そのアセットタイプのインスタンスを右クリックして Type Properties を選択)。
-
Interactive|Handle Script タブをクリックします。
-
ハンドルコードを生成するために New… ボタンをクリックします。
-
Samples 項目で Rotate を選択して、 Accept をクリックします。
-
Apply ボタンをクリックして、その新しいハンドルを登録します。
このHandle Scriptエディターには、ジオメトリを軸回転させることができるPythonハンドルのコードが表示されているはずです。
この新しいハンドルは、Viewer Handle Browserペインのツリー内のHandle Demoノード下にリストされているはずです。
この新しいハンドルをテストするには、そのハンドルとバインドさせるビューアステートを作成する必要があります。
-
Interactive|State Script タブをクリックします。
-
ステートコードを生成するために New… ボタンをクリックします。
-
Name フィールドには、 ステートの名前 として
state_rotate_demoと入力します。 -
Samples 項目で Static Handle を選択して、 Accept をクリックします。
-
以下の行を
HANDLE_TYPENAME = "unknown"以下の内容に置換します。
HANDLE_TYPENAME = "handle_demo" -
以下の行を
template.bindHandleStatic( HANDLE_TYPENAME, HANDLE_NAME, [] )以下の内容に置換します。
template.bindHandleStatic( HANDLE_TYPENAME, HANDLE_NAME, [("ry","ry")] ) -
アセット内に
ryという名前のfloatパラメータを追加します。 -
Accept をクリックします。
この新しいstate_rotate_demoステートは、Viewer State Browserペインのツリー内にリストされているはずです。
このstate_rotate_demoノードを展開すると、その新しいhandle_demoエントリが見つかります。
それでは、geo1オブジェクト内にBox SOPを作成してディスプレイフラグを有効にし、そのBoxボックスのRotate Yフィールドにch("../subnet1/ry")を追加してください。
ネットワークエディタ内でHandle demoアセットノードを選択します。マウスをシーンビューア内に移動させてEnterを押します。すると、ハンドルが緑色のリングで表示され、そのリングをドラッグすると、ボックスが回転します。
Houdiniパスからハンドルを読み込む方法 ¶
以下の手順では、Houdini起動時に自動的に登録されるPythonハンドルモジュールの作成方法について説明しています。 This example is valid for all Python handle contexts; however, some samples provided by the Code Generator may not be available in the COP Python handle context, such as the gadget sample shown below.
-
New Pane Tab Type ▸ Inspectors ▸ Viewer Handle Browser メニューからViewer Handle Browserウィンドウを開きます。
-
ブラウザのツールバーのリストメニューから
Sopカテゴリを選択します。 -
File ▸ New Handle… メニューでViewer Handle Code Generatorを開きます。
-
ハンドルの名前 として Name フィールドに
handle_demoと入力します。 -
Samples オプションで
Gadgetを選択して、 Accept をクリックします。
サンプルコードを含んだ新しいPythonハンドルファイルが$HOUDINI_USER_PREF_DIR/viewer_handles/handle_demo.pyとして保存され、Viewer Handle BrowserツリーにHandle demoとしてリストされているはずです。
Gadgetサンプルが生成するコード:
import hou import resourceutils as ru import viewerhandle.utils as hu #使用方法: 何も処理をせずハンドルガジェットを描画するだけの単純なハンドル。 GADGET_PIVOT = "pivot" SCALE = 250.0 class Handle(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) # ハンドルのトランスフォーム操作をサポートするユーティリティクラス。 self.xform_aid = hu.TransformAid(self,kwargs) # ここでは、ガジェットをクラスアトリビュートとして保存します。 # ガジェットはself.handle_gadgets attributeを介していつでも利用可能なので、これは任意です。 color_options = ru.ColorOptions(self.scene_viewer) self.pivot = self.handle_gadgets[GADGET_PIVOT] self.pivot.setParams({"draw_color":color_options.colorFromName("HandlePivotColor")}) # ピボットガジェットにBoxジオメトリを割り当てます。 sops = hou.sopNodeTypeCategory() verb = sops.nodeVerb("box") verb.setParms({"type":1, "scale":0.1, "divrate":(2,2,2)}) pivot = hou.Geometry() verb.execute(pivot, []) self.pivot.setGeometry(pivot) self.pivot.show(True) def onDraw( self, kwargs ): draw_handle = kwargs["draw_handle"] # ピボットガジェットを描画します。 self.pivot.draw(draw_handle) def onDrawSetup(self, kwargs): """ 描画、ピック、ロケート(マウス下の検索)の操作をする前にコールされます。""" # カメラ位置に関係なくスケール係数でピボットガジェットをスケールします。 origin = hou.Vector3() scale = self.handle_context.scaleFactor(origin)*SCALE scales = [scale]*3 xform = self.xform_aid.updateTransform(s=scales) self.pivot.setTransform(xform) def createViewerHandleTemplate(): """ 登録するビューアハンドルテンプレートを作成して返すための必須エントリポイント。""" handle_type = "handle_demo" handle_label = "Handle demo" handle_cat = [hou.sopNodeTypeCategory()] template = hou.ViewerHandleTemplate(handle_type, handle_label, handle_cat) template.bindFactory(Handle) template.bindIcon("MISC_python") # Drawable Gadgetをハンドルにバインドします。 # このガジェットは、基本的にはビューポート内でインタラクティブに操作可能なハンドルコンポーネントを定義する際に使用されるGeometry Drawablesです。 # # このガジェットは、マウス下の位置の特定やピックといった一般的なハンドル操作を実行する際にHoudiniで使用されます。 # # ガジェットインスタンスは、Houdiniで生成され、このデータメンバーを介してHandleオブジェクトで利用可能にします: # self.handle_gadgets: 名前でキーを設定可能なガジェットの辞書。 template.bindGadget( hou.drawableGeometryType.Face, GADGET_PIVOT ) return template
このハンドルをテストするために、以下の手順に従います:
-
Objectレベルで⇥ Tabメニューを使用して
Geoオブジェクトを作成します。
-
その
geo1ノードをダブルクリックしてGeometryネットワークの中に入ります。 -
⇥ Tabメニューを使用してSubnetworkノードを作成します。
-
その
subnet1ノードを右クリックして Digital Asset → Create New を選択します。 -
Type Name を
state_handle_demo、 Asset Label をState Handle Demo、 Library Path をEmbedded in .hip Fileに設定します。このライブラリの保存場所を
Embeddedに設定することで、アセットライブラリではなく現行シーンファイルにアセットが保存されます。 -
Author 、 Branch 、 Version のチェックボックスのチェックを外します。
-
このアセットのType Propertiesウィンドウが開きます(アセットタイプのインスタンスを右クリックして Type Properties を選択)。
-
Interactive|State Script タブをクリックします。
-
New… ボタンをクリックすると、Viewer State Code Generatorダイアログが開きます。
-
Samples オプションで Static Handle を選択して Accept をクリックします。
-
その新しいステートソースコードの中の HANDLE_TYPENAME に“handle_demo”に設定して Accept をクリックします。
-
state handle demoノードを選択して、ビューア内でEnterキーを押します。
これでPythonハンドルデモがアクティブになり、原点にピボットガジェットが表示されているはずです。
ハンドルを実装する方法 ¶
This section details the implementation of Python handles. Creating them from scratch can be challenging and prone to errors. To streamline this process, consider using the Viewer Handle Code Generator. This tool offers a variety of code samples that you can leverage to generate the basic structure of your Python handle.
Implementing a Python handle involves creating a Python class. The following sections provide an overview of the supported class methods.
Note
Houdiniには、viewerhandle.utilsというPythonモジュールが用意されています。
このモジュールには、ビューアハンドルのインストールをサポートしたり、独自のハンドルの実装に役立つドキュメント化された様々なユーティリティ関数/クラスが含まれています。
このモジュールは、$HHP/viewerhandleフォルダに配置されています。
Tip
$HHP環境変数は、Houdiniのインストールディレクトリ内のPythonライブラリを含んだサブディレクトリ($HFS/houdini/pythonX.Ylibs/)を指しています。
特定の機能の実装に関する詳細は、以下のページを参照してください:
Pythonビューアハンドル
3D Python Handles ¶
3D Python handles provide 3D manipulation capabilities and operate within the Scene Viewer. They can be defined in contexts such as SOP, LOP, and OBJ nodes.
Initializer ¶
def __init__(self, **kwargs)
The __init__ method is required to initialize a Python handle class. Houdini calls this method with a kwargs dictionary that is prepopulated with a set of key entries.
Note
You can store the contents of the kwargs dictionary as attributes of the class in __init__. This allows you to access these entries directly
in your code without repeatedly querying the dictionary.
def __init__(self, **kwargs) self.__dict__.update(kwargs) ... def onActivate(self, kwargs): self.log("Handle parameters", self.handle_parms)
handle_name
登録時に設定されるビューアハンドルのタイプ名。
handle_label
登録時に設定されるPythonハンドルのラベル。
handle_instance_name
Pythonハンドルをhou.ViewerStateTemplate.bindHandleまたはhou.ViewerStateTemplate.bindHandleStaticにバインドする時にPythonステートで指定するハンドルインスタンス名。
scene_viewer
Pythonハンドルが実行されているシーンビューアを表現したhou.SceneViewerのインスタンス。
handle_context
アクティブハンドルに関する様々なコンテキスト情報にアクセス可能なコンテキストオブジェクト。
handle_gadgets
hou.ViewerHandleTemplate.bindGadgetで定義されているgadgetオブジェクトの辞書。 ガジェットの名前を辞書キーとして使用することで、そのガジェットオブジェクトを照会することができます。
handle_parms
Pythonハンドルのパタメータ値と設定値を含んだ辞書。 この辞書には、hou.ViewerHandleTemplate.bindParametersとhou.ViewerHandleTemplate.bindSettingsで与えられた情報から収集されます。 パラメータ名または設定名を使用することで、その辞書の値を照会することができます。
2D Python Handles ¶
2D Python handles are designed to operate within the Compositing Viewer and the Scene Viewer.
Initializer ¶
def __init__(self, **kwargs)
For 2D Python handles, the __init__ method is required to initialize the handle class. Houdini will call
this method with a kwargs dictionary containing predefined key entries.
Note
It is often convenient to store the kwargs dictionary entries as attributes of the
handle class. This lets you access them directly as self.attribute_name instead of
repeatedly indexing the dictionary.
Example:
def __init__(self, **kwargs): self.__dict__.update(kwargs) def onActivate(self, kwargs): self.log("Handle parameters", self.handle_parms)
handle_name
The viewer handle type name as set during registration.
handle_label
The Python handle label as set during registration.
handle_instance_name
The unique name of this handle instance, as specified by the Python state when binding the handle using hou.ViewerStateTemplate.bindHandle or hou.ViewerStateTemplate.bindHandleStatic. This is often used to initialize a hou.Handle instance that references this Python handle implementation.
scene_viewer
An instance of hou.CompositorViewer representing the Compositing Viewer in which the handle is running.
handle_context
A hou.ViewerHandleContext object providing access to various contextual information about the active handle. It can be used to define the draw order of drawables, query handle parameters, and access gadgets.
The handle_context is available inside Python Handle callbacks such as onDraw, onMouseEvent, and others, allowing handle implementations to render drawables and respond to user interaction consistently.
handle_parms
A dictionary containing the parameter and setting values of the Python handle. It is populated through hou.ViewerHandleTemplate.bindParameters and hou.ViewerHandleTemplate.bindSettings. Use the parameter or setting name as the key to access its value.
イベントハンドラー ¶
Pythonハンドルイベントに反応できるようにいくつかのハンドルがサポートされています。
これらのイベントハンドラーのほとんどは、そのイベント関連の特定の値を含んだ単一辞書引数(kwargs)を使ってコールされます。
すべてのハンドラーに共通するkwargsエントリを以下に載せています:
handle_context
アクティブハンドルに関する様々な情報にアクセス可能なコンテキストオブジェクト。 このキャッシュは、クラスアトリビュートとしても利用可能です。
handle_parms
Pythonハンドルにバインドされたパラメータと設定を表現した名前を含んだ書き込み可能な辞書。
ui_event
イベントに関する情報(例えばマウスイベントの場合、現行マウス座標やボタンがクリックされたかどうか)を持ったhou.ViewerEventインスタンスを含んでいます。 If the event occurs in a compositor view, this will be a hou.CompositorViewerEvent instance instead.
This table lists all event handlers along with specific kwargs entries if any.
メソッド名 |
説明 |
|---|---|
|
This callback is invoked when a 3D Python handle’s hou.GadgetDrawable or a 2D Python handle’s hou.Drawable2D is located, picked, and dragged. For more information, see mouse handling. |
|
ビューポート内の任意の場所から |
|
Indicates whether the handle supports indirect mouse manipulation. Must return True to enable support, or False otherwise. If this handler is not implemented, Houdini assumes indirect manipulation is not supported. |
|
Computes the distance between the handle and the mouse position. Takes the mouse position as input and returns the distance as a float in screen space. Houdini uses this value to determine which of the active handles in the viewport receives the indirect manipulation event - the closest handle wins. If unimplemented, Houdini assumes the handle does not support mouse indirect handling. Note You do not need to implement this handler for HUD handles; Houdini computes the distance automatically. |
|
マウススクロールが発生した時にコールされます。
hou.UIEventDevice.mouseWheelは、スクロール方向に応じて |
|
キーが押された時にコールされます。 詳細は、キーボードデバイスの読み込みを参照してください。 |
|
キートランジションイベントが発生した時にコールされます。 詳細は、キーボードデバイスの読み込みを参照してください。 |
|
ユーザがコンテキストメニュー項目を選択した時にコールされます。 コンテキストメニューのハンドリングに関しては、Pythonステートのコンテキストメニューを参照してください。
Note このハンドラーは、 |
|
コンテキストメニューが開かれる前にコールされます。 コンテキストメニューの更新を参照してください。
|
|
ハンドルのパラメータまたは設定が変更された時にコールされます。 ハンドルパラメータのハンドリングを参照してください。
|
|
HoudiniがPythonハンドルの再描画を必要とした時にコールされます。 詳細は、ハンドルの描画を参照してください。 このメソッドは以下の時にコールされます:
|
|
Note
|
|
ハンドルがアクティブに設定された時にコールされます。これは以下の時に起こります:
|
|
ハンドルが非アクティブに設定された時にコールされます。これは以下の時に起こります:
|
|
ハンドル設定がHoudiniに読み込まれて処理される準備が整った時にコールされます。
一つの設定が変更される度にコールされる |
Undo対応 ¶
Houdiniは、ハンドルやノードパラメータが変更された時に自動的にUndoスタック上にアイテムを生成します。 とはいえ、独自にUndo対応が必要な場合、hou.undosモジュールとhou.SceneViewerのUndoメソッドを使用することで、 Undo可能なオペレーションをUndoスタック上に1個のエントリにまとめることができます。 詳細は、ステートのUndo対応を参照してください。
Note
Some of the hou.SceneViewer undo methods are not supported in hou.CompositorViewer.
ユーティリティ ¶
Houdiniには、Pythonハンドルの実装に役立つ様々なユーティリティクラスが用意されています。
例えば、ColorOptionsやhou.SceneViewer.hudInfoといったユーティリティは、Houdiniの標準と整合性が合うように設計されており、
これらのユーティリティティを使用することを強く推奨します。
これらのユーティリティの使い方のサンプルは、Pythonハンドルのデモを参照してください。
-
viewerhandle.utils.TransformAid:TransformAidは、Pythonハンドルのトランスフォーム操作を制御します。updateTransformやtoScreenといったメソッドは、ビューポートがワールド空間に設定された時にハンドルのオブジェクトトランスフォームを補完します。Note
While
TransformAidis primarily designed for 3D Python handles and some of its methods might seem applicable to 2D handles, it is recommended to usedrawable2d.Dragger2Dfor handling 2D-specific operations within 2D Python handles instead. -
viewerhandle.utils.DebugAid:Pythonハンドルのデバッグに役立つユーティリティクラス。
-
resourceutils.ColorOptions:Houdiniカラーオプションにアクセスできるユーティリティクラス。 詳細は、Gadget Drawablesを参照してください。
-
resourceutils.DisplayGroup:このクラスは、Drawablesをビューポート内にグループとして表示することができます。 例えば、Houdiniトランスフォームモードキーの
Yと同様に循環形式でハンドルガジェットのグループの表示を切り替えたい場合にこれが役立ちます。 -
drawable2d.Dragger2D:A utility class for interactive mouse-based manipulation of hou.Drawable2D objects in 2D image space. This is primarily used in COP Python handles or states, where user interaction occurs within a normalized model space ranging from
[-1, -1] to [1, 1]. -
drawable2d.Drawable2DGroup:This class covers the drawable grouping functionality for hou.Drawable2D objects.
-
resourceutils.CursorLabel:Use this class to display a text label that follows the cursor’s movement. This can be useful for both 2D and 3D Python handles to provide contextual information. Refer to the
move_tool_demoandcop_state_drawable_demohandle examples for detailed usage. -
resourceutils.DebugMenu:Pythonハンドルコンテキストメニューにデバッグメニューエントリを作成する際にHoudiniで使用されます。 実際にViewer Handle Code Generatorは、これを使用してハンドルのコンテキストメニューを作成しています。
サンプル ¶
Viewer Handle Code Generatorのサンプルだけでなく、サンプルシーンを使用してPythonハンドルを実験することができます。
以下のシーンは、viewer_handle_demoパッケージと一緒に$HFS/package/viewer_handle_demo/scenes下に配布されています。
以下のシーンを使用する前に、Viewer Handle Browserの File|Load Examples メニューをクリックしてそのパッケージをHoudiniに読み込んでください。
Demo Viewer Handle シェルフツールまたはメインメニューバー内の File|Open… メニューからサンプルシーンを読み込むことができます。
3D Python Handles ¶
viewer_handle_intro.hipシーンでは、Pythonハンドルの実装について紹介されており、そのシーンからPythonハンドルの基本機能を学ぶことができます。
move_tool_demo.hipシーンでは、ジオメトリを移動/回転/スケールさせるPythonハンドルのもっと完璧で複雑な実装のサンプルが用意されています。
2D Python Handles ¶
The cop_viewer_handle_demo.hip scene offers an introduction to creating Python handles specifically for COPs. By exploring this example,
you will learn the fundamental features and implementation techniques for COP Python handles.
Pythonハンドルの使い方 ¶
Pythonハンドルとビルトインハンドルの制御で使用するワークフローの違いはほとんどありません。 例えば、ビルトインハンドルだろうとPythonハンドルだろうとどちらを使用しても以下のUI機能をユーザは使用できるはずです:
-
Pythonハンドルを表示する
ボタン。
-
パラメータと設定にアクセスすることができるHandle Parameterダイアログ。
-
Pythonハンドルを持続型として有効化することができるPersistent Handle Editor(COP Pythonハンドルとは互換性がありません)。
-
Draggersのスナップオプションを設定する
ダイアログ(COP Pythonハンドルとは互換性がありません)。。
-
Pythonハンドルのスケールを調整するカメラズーム
。
-
キーフレーム
によるPythonハンドルパラメータのアニメーション。
Note
ただし、Handle Preferenceダイアログは、Houdiniビルトインハンドルの設定を制御するように設計されているので、Pythonハンドル向けに意図されていません。 これらの設定の一部は、良いタイミングで将来Pythonハンドル向けに露出される予定です。
ビューアハンドルを検査する方法 ¶
Houdiniは、登録済みのすべてのPythonハンドルをViewer Handle Browserウィンドウで表示することができます。 このブラウザはViewer State Browserと同様で、ほぼ同じ機能が用意されています:
-
登録済みのハンドルをブラウズするツリー。
-
メッセージをログに出すコンソール。
-
アクティブハンドルのクラスアトリビュートをダンプする様々なオペレーション。
-
Viewer Handle Code Generator。
-
Pythonハンドルの編集と読み込みに対応。
デバッグに関するTips ¶
Pythonハンドルで利用可能なデバッグ機能は、Pythonステートのデバッグ機能とほぼ同じです。 これらの機能について学習したいのであれば、Pythonステートのデバッグに関するTipsの章を参照してください。
DebugAid ¶
ユーティリティクラスのviewerhandle.utils.DebugAidには、Pythonハンドルのデバッグサポートが用意されています。
このユーティリティは、Pythonハンドルブラウザでメッセージをログに出すのに便利ですが、さらにPythonハンドルブラウザで現在利用可能なすべてのログ機能をメソッドとして用意しています:
-
アクティブなPythonハンドルを検査します。
-
コンソールにマーカーを追加します。
-
デバッグトレースを有効化します。
-
ロギングコンソールを有効化します。
-
実行中のPythonハンドルをリロードします。
import traceback from viewerhandle.utils import DebugAid class Handle(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) self.dbg = DebugAid(self) def onEnter(self, kwargs): # ハンドルを検査します。 self.dbg.marker() self.dbg.inspect() # トレースを開始します。 self.dbg.trace() def onMouseEvent(self, kwargs): # マウス位置をログに出します。 ui_event = kwargs["ui_event"] device = ui_event.device() self.dbg.marker() self.dbg.log("Mouse position x=", device.mouseX(), "y=", device.mouseY()) # 現在のPythonコールスタックをログに出します。 self.dbg.log(''.join(traceback.format_stack()))
ハンドルをリロードする方法 ¶
HoudiniからPythonハンドルモジュールをリロードできれば、Pythonハンドルの開発サイクルが向上します。 Pythonハンドルをリロードする方法がいくつか用意されています:
-
ソースコードがHoudiniのViewer Handle Editorで開かれていれば、
Acceptボタンをクリックします。 -
Viewer Handle BrowserペインのFileメニューまたはブラウザツリー内から
Reloadコンテキストメニューを選択します。 -
ハンドルがHDAに埋め込まれている場合は、Python Handleエディタからリロードします。
Note
Pythonハンドルをリロードすると、そのハンドルのインスタンスが使用中であれば、実行中のPythonステートが自動的に抜けます。
デバッグコンテキストメニュー ¶
HOM API ¶
Pythonハンドル関連のHOM APIのいくつかを以下に載せます。
Pythonビューアハンドル