2010
06.14
06.14
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() api.MGlobal.getActiveSelectionList(sel) #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) else: api.MGlobal.selectFromScreen(x, y, api.MGlobal.kReplaceList) objects = api.MSelectionList() api.MGlobal.getActiveSelectionList(objects) #restore selection api.MGlobal.setActiveSelectionList(sel, api.MGlobal.kReplaceList) #return the objects as strings fromScreen = [] objects.getSelectionStrings(fromScreen) return fromScreen print selectFromScreenApi(0, 0) print selectFromScreenApi(0, 0, 4096, 4096)