On this page | |
Inheritance |
|
Overview ¶
A hou.ViewerHandleContext
holds the state related to the running viewer handle. A Viewer handle
context holds the information about the viewer handle gadgets (see hou.GadgetContext) and about
the viewer handle itself, such as the parms states.
Methods ¶
isParameterEnabled(parm_name)
→ bool
parm_name
Returns True
if a given parm name is enabled. The returned
value is typically used in the handle implementation for enabling
or disabling (hide) the functionality that may depend on this parm.
scaleFactor(ref_position)
→ double
This method returns a scale factor that can be used to maintain a fixed scale size of the handle gadgets
when zooming in or out. scaleFactor
is normally used in onDrawSetup.
ref_position
A reference position (related to the handle) used for computing the scale factor. This could be the handle’s pivot position (if one exists) or any other relevant position. If omitted, the reference position is (0,0,0).
scaleValue()
→ double
Returns the handle scale preference value. The handle scale is computed
proportionally to the current viewport size and can be used to scale up handle gadgets to a preferred size.
You would normally call scaleValue
from onDrawSetup.
handleScaleValue(ref_position=None)
→ double
Returns the computed scaling factor for the current handle within the active Houdini viewport. Although Houdini automatically scales drawables to maintain a consistent display size across different zoom levels, this value is crucial for COP Python handle implementations. It allows for adjusting the display size of drawables, particularly to compensate for the handle’s own scaling when interactively dragging elements.
ref_position
A reference position (related to the handle) used for computing the scale value. This is likely a drawable position or any other relevant position. If omitted, the reference position is (0,0,0).
This code snippet demonstrates how to use handleScaleValue()
in a COP python handle.
import hou import drawable2d as d2d MY_LINE_DRAWABLE = "line" MY_MARKER_DRAWABLE = "marker" TX = "tx" TY = "ty" def __init__(self, **kwargs): self.__dict__.update(kwargs) self._line = None self._marker = None # handle dragger self._dragger = d2d.Dragger2D(self.scene_viewer) def onActivate(self, kwargs): # Drawables creation omitted for brievity pass def onMouseEvent(self, kwargs): """ Drags a marker position and update the line point #2 with the new position. """ ui_event = kwargs["ui_event"] reason = ui_event.reason() if reason == hou.uiEventReason.Changed: # End the current drag operation on mouse up self._dragger.endDrag() return True if not self._dragger.update(kwargs, self._marker): return False drawable_name = self.handle_context.name() consumed = True if reason == hou.uiEventReason.Start: if drawable_name == MY_MARKER_DRAWABLE: self._dragger.startDrag(p1=self.handle_parms[TX], p2=self.handle_parms[TY], transform_mode=d2d.Drawable2D.TransformMode.PARAMS) elif reason in [hou.uiEventReason.Active, hou.uiEventReason.Changed]: if drawable_name == MY_MARKER_DRAWABLE: # Drag the drawable self._dragger.dragXY() # Change the drawable positions dx, dy = self._dragger.delta() delta = hou.Vector3(dx,dy,0) # Adjust the delta with the handle scaling factor handle_scale = self.handle_context.handleScaleValue(delta) delta /= handle_scale dx = delta[0] dy = delta[1] su.addToDrawablePos(self._marker, dx, dy) su.addToDrawablePoint(self._line, 1, dx, dy) return consumed ...
objectWorldTransform()
→ `hou.Matrix4
Returns the world space transform of the handle’s parent object.
objectLocalTransform()
→ `hou.Matrix4
Returns the local space transform of the handle’s parent object.
Methods from hou.GadgetContext ¶
name()
→ string
Returns the name of the active drawable. A drawable is active when it is picked or when the mouse moves over its visuals (located).
label()
→ string
The active drawable label name.
gadget()
→ string
Similar to name().
gadgetLabel()
→ string
Similar to label().
component1()
→ int
A component id of the active gadget geometry. The id refers to either a polygon, a polygon vertex or the start point of a line geometry. Returns -1 if no gadget is active.
Note
This method does not apply to hou.Drawable2D objects.
component2()
→ int
A component id of the active gadget geometry. The returned id typically identifies the end point of a line geometry. Returns -1 if no line geometry is picked or located, or no gadget is active.
Note
This method does not apply to hou.Drawable2D objects.
isDrawing()
→ bool
Returns True if the handle is in a drawing state which means no drawable is being picked or located.
isPicking()
→ bool
Returns True if any drawable is being picked.
isLocating()
→ bool
Returns True if any drawable is being located.
isLocated(drawable_name)
→ bool
Returns True if a given drawable is located.
drawable_name
Name of the drawable to test.
isPicked(drawable_name)
→ bool
Returns True if a given drawable is picked.
drawable_name
Name of the drawable to test.
See also |