Go to: Synopsis. Return value. Keywords. Python examples.

Synopsis

hitTest(stringintint)

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

hitTest is NOT undoable, NOT queryable, and NOT editable.

The hitTest command hit-tests a point in the named control and returns a list of items underneath the point. The point is specified in pixels with the origin (0,0) at the top-left corner. This position is compatible with the coordinates provided by a drop-callback. The types of items that may be returned depends upon the specific control; not all controls currently support hit-testing.

Return value

string[]items underneath the hit-point

Keywords

hit, hittest, drag-and-drop

Python examples

import maya.cmds as cmds

#    Let's say that you have the name of a model editor that was
#    created elsewhere.
#
editor = "MyModelEditor"
#    Here's your drop callback:
#
def myModelEditorDropCallback( dragControl,
							   dropControl,
							   msgs,
							   x,
							   y,
							   type ):
	#	Inside the callback we can hit-test the (x,y) drop-point
	#	against the control. This will return a list of DAG objects
	#	underneath the drop-point.
	#
	objects = cmds.hitTest( dropControl, x, y )
	if len( objects ):
		#	The hit-test returned something. You can now do something
		#	with these objects.
		pass
#
#	Attach a drop callback to this model editor.
#
try:
	control = cmds.editor( editor ,query=True, control=True )
	if cmds.control( control, exists=True ):
		cmds.control( control, edit=True, dropCallback=myModelEditorDropCallback )
except RuntimeError:
	pass