#NEWLINE# def validateSelection( **keywords ) : #NEWLINE# #INDENT# '\n\tVerify that the current selection is valid and return it.\n\t@param type String corresponding to the object type the selection should filter.\n\t@param msg A custom error message to override in all cases.\n\t@param name A custom object name for default error messages.\n\t@param exact Specifies that an exact number of objects must be selected.\n\t@param min The minimum number of objects that must be selected.\n\t@param max tThe maximum number of objects that may be selected.\n\t' #NEWLINE# selection = '' #NEWLINE# msg = keywords . setdefault ( 'msg' ) #NEWLINE# name = keywords . setdefault ( 'name' , 'object(s)' ) #NEWLINE# try : #NEWLINE# #INDENT# selection = cmds . ls ( sl = True , l = True , type = keywords [ 'type' ] ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# selection = cmds . ls ( sl = True , l = True ) #NEWLINE# #UNINDENT# isException = False #NEWLINE# if ( ( 'exact' in keywords ) and ( len ( selection ) is not keywords [ 'exact' ] ) ) : #NEWLINE# #INDENT# if ( not msg ) : #NEWLINE# #INDENT# msg = ( 'Please select exactly %s %s' % ( keywords [ 'exact' ] , name ) ) #NEWLINE# #UNINDENT# isException = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'min' in keywords ) and ( len ( selection ) < keywords [ 'min' ] ) ) : #NEWLINE# #INDENT# if ( not msg ) : #NEWLINE# #INDENT# msg = ( 'Error: You must select at least %s %s' % ( keywords [ 'min' ] , name ) ) #NEWLINE# #UNINDENT# isException = True #NEWLINE# #UNINDENT# if ( ( 'max' in keywords ) and ( len ( selection ) > keywords [ 'max' ] ) ) : #NEWLINE# #INDENT# if ( not msg ) : #NEWLINE# #INDENT# msg = ( 'Error: You may select no more than %s %s' % ( keywords [ 'max' ] , name ) ) #NEWLINE# #UNINDENT# isException = True #NEWLINE# #UNINDENT# #UNINDENT# if isException : #NEWLINE# #INDENT# raiseExceptionWithMessage ( msg , 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return selection