Something I whipped up to get the selection from the screen using the Maya API in python, just returns the selection as a list of dag path’s.

Maya’s API selecFromScreen is great, except for the fact that for what I needed, I only wanted a list of object from the screen, not to actually select them.

import maya.OpenMaya as api

def selectFromScreenApi(x, y, x_rect=None, y_rect=None):
	#get current selection
	sel = api.MSelectionList()
	#select from screen
	args = [x, y]
	if x_rect!=None and y_rect!=None:
		api.MGlobal.selectFromScreen(x, y, x_rect, y_rect, api.MGlobal.kReplaceList)
		api.MGlobal.selectFromScreen(x, y, api.MGlobal.kReplaceList)
	objects = api.MSelectionList()
	#restore selection
	api.MGlobal.setActiveSelectionList(sel, api.MGlobal.kReplaceList)
	#return the objects as strings
	fromScreen = []
	return fromScreen

print selectFromScreenApi(0, 0)
print selectFromScreenApi(0, 0, 4096, 4096)

You must be logged in to post a comment.