Very often, you will want to make a script that only works on certain kinds of objects and the objects that already exist before the user invokes your script. In this case, you'll want to be able to not only determine what object(s) are currently selected but also to verify that the selected object(s) are of the appropriate type. In this example, we'll be creating a script that will verify that the currently selected object is, in fact, an instance of polygonal geometry and altering the user if it isn't.
Create a new script and add the following code:
import maya.cmds as cmds def currentSelectionPolygonal(obj): shapeNode = cmds.listRelatives(obj, shapes=True) nodeType = cmds.nodeType(shapeNode) if nodeType == "mesh": return True return False def checkSelection(): selectedObjs = cmds.ls(selection=True) if (len(selectedObjs) < 1): cmds.error('Please select an object') lastSelected...