pymel.core.general.select

select(*args, **kwargs)

This command is used to put objects onto or off of the active list. If none of the five flags [-add, -af, -r, -d, -tgl] are specified, the default is to replace the objects on the active list with the given list of objects. When selecting a set as in select set1, the behaviour is for all the members of the set to become selected instead of the set itself. If you want to select a set, the -ne/noExpandflag must be used. With the advent of namespaces, selection by name may be confusing. To clarify, without a qualified namespace, name lookup is limited to objects in the root namespace :. There are really two parts of a name: the namespace and the name itself which is unique within the namespace. If you want to select objects in a specific namespace, you need to include the namespace separator :. For example, ‘select -r foo*’ is trying to look for an object with the fooprefix in the root namespace. It is not trying to look for all objects in the namespace with the fooprefix. If you want to select all objects in a namespace (foo), use ‘select foo:*’. Note: When the application starts up, there are several dependency nodes created by the system which must exist. These objects are not deletable but are selectable. All objects (dag and dependency nodes) in the scene can be obtained using the lscommand without any arguments. When using the -all, adn/allDependencyNodesor -ado/allDagObjectsflags, only the deletable objects are selected. The non deletable object can still be selected by explicitly specifying their name as in select time1;.

Modifications:
  • passing an empty list no longer causes an error.

    instead, the selection is cleared if the selection mod is replace (the default); otherwise, it does nothing

Flags:

Long Name / Short Name Argument Types Properties
add / add bool ../../../_images/create.gif
  Indicates that the specified items should be added to the active list without removing existing items from the active list.
addFirst / af bool ../../../_images/create.gif
  Indicates that the specified items should be added to the front of the active list without removing existing items from the active list.
all / all bool ../../../_images/create.gif
  Indicates that all deletable root level dag objects and all deletable non-dag dependency nodes should be selected.
allDagObjects / ado bool ../../../_images/create.gif
  Indicates that all deletable root level dag objects should be selected.
allDependencyNodes / adn bool ../../../_images/create.gif
  Indicates that all deletable dependency nodes including all deletable dag objects should be selected.
clear / cl bool ../../../_images/create.gif
  Clears the active list. This is more efficient than select -d;. Also select -d;will not remove sets from the active list unless the -neflag is also specified.
containerCentric / cc bool ../../../_images/create.gif
  Specifies that the same selection rules as apply to selection in the main viewport will also be applied to the select command. In particular, if the specified objects are members of a black-boxed container and are not published as nodes, Maya will not select them. Instead, their first parent valid for selection will be selected.
deselect / d bool ../../../_images/create.gif
  Indicates that the specified items should be removed from the active list if they are on the active list.
hierarchy / hi bool ../../../_images/create.gif
  Indicates that all children, grandchildren, ... of the specified dag objects should also be selected.
noExpand / ne bool ../../../_images/create.gif
  Indicates that any set which is among the specified items should not be expanded to its list of members. This allows sets to be selected as opposed to the members of sets which is the default behaviour.
replace / r bool ../../../_images/create.gif
  Indicates that the specified items should replace the existing items on the active list.
symmetry / sym bool ../../../_images/create.gif
  Specifies that components should be selected symmetrically using the current symmetricModelling command settings. If symmetric modeling is not enabled then this flag has no effect.
symmetrySide / sys int ../../../_images/create.gif
  Indicates that components involved in the current symmetry object should be selected, according to the supplied parameter. Valid values for the parameter are: -1 : Select components in the unsymmetrical region. 0 : Select components on the symmetry seam. 1 : Select components on side 1. 2 : Select components on side 2. If symmetric modeling is not enabled then this flag has no effect. Note: currently only works for topological symmetry.
toggle / tgl bool ../../../_images/create.gif
  Indicates that those items on the given list which are on the active list should be removed from the active list and those items on the given list which are not on the active list should be added to the active list.
visible / vis bool ../../../_images/create.gif
  Indicates that of the specified items only those that are visible should be affected. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.select

Example:

import pymel.core as pm

# create some objects and add them to a set
pm.sphere( n='sphere1' )
# Result: [nt.Transform(u'sphere1'), nt.MakeNurbSphere(u'makeNurbSphere1')] #
pm.sphere( n='sphere2' )
# Result: [nt.Transform(u'sphere2'), nt.MakeNurbSphere(u'makeNurbSphere2')] #
pm.sets( 'sphere1', 'sphere2', n='set1' )
# Result: nt.ObjectSet(u'set1') #

# select all dag objects and all dependency nodes
pm.select( all=True )

# clear the active list
pm.select( clear=True )

# select sphere2 only if it is visible
pm.select( 'sphere2', visible=True )

# select a couple of objects regardless of visibilty
pm.select( 'sphere1', r=True )
pm.select( 'sphere2', add=True )

# remove one of the spheres from the active list (using toggle)
pm.select( 'sphere1', tgl=True )

# remove the other sphere from the active list
pm.select( 'sphere2', d=True )

# the following selects all the members of set1
pm.select( 'set1' )

# this selects set1 itself
pm.select( 'set1', ne=True )


# Some examples selecting with namespaces:

# create a namespace and an object in the namespace
pm.namespace( add='foo' )
# Result: u'foo' #
pm.namespace( set='foo' )
# Result: u'foo' #
pm.sphere( n='bar' )
# Result: [nt.Transform(u'foo:bar'), nt.MakeNurbSphere(u'foo:makeNurbSphere1')] #

# 'select bar' will not select "bar" unless bar is in the
# root namespace. You need to qualify the name with the
# namespace (shown below).
pm.select( 'foo:bar' )

# select all the objects in a namespace
pm.select( 'foo:*' )