I suggest using //Mel string $vertices[] = `filterExpand -sm 31`; for querying the selected vertices instead. You never know if the user might select something else which should not be selected for the script. filterExpand 31 ensures you get only selected vertices, see the docs for which number is used for other components.