pymel.core.general.sets

sets(*args, **kwargs)

This command is used to create a set, query some state of a set, or perform operations to update the membership of a set. A set is a logical grouping of an arbitrary collection of objects, attributes, or components of objects. Sets are dependency nodes. Connections from objects to a set define membership in the set. Sets are used throughout Maya in a multitude of ways. They are used to define an association of material properties to objects, to define an association of lights to objects, to define a bookmark or named collection of objects, to define a character, and to define the components to be deformed by some deformation operation. Sets can be connected to any number of partitions. A partition is a node which enforces mutual exclusivity amoung the sets in the partition. That is, if an object is in a set which is in a partition, that object cannot be a member of any other set that is in the partition. Without any flags, the setscommand will create a set with a default name of set#(where # is an integer). If no items are specified on the command line, the currently selected items are added to the set. The -em/empty flag can be used to create an empty set and not have the selected items added to the set. Sets can be created to have certain restrictions on membership. There can be renderablesets which only allow renderable objects (such as nurbs geometry or polymesh faces) to be members of the set. There can also be vertex (or control point), edit point, edge, or face sets which only allow those types of components to be members of a set. Note that for these sets, if an object with a valid type of component is to be added to a set, the components of the object are added to the set instead. Sets can have an associated color which is only of use when creating vertex sets. The color can be one of the eight user defined colors defined in the color preferences. This color can be used, for example to distinguish which vertices are being deformed by a particular deformation. Objects, components, or attributes can be added to a set using one of three flags. The -add/addElement flag will add the objects to a set as long as this won’t break any mutual exclusivity constraints. If there are any items which can’t be added, the command will fail. The -in/include flag will only add those items which can be added and warn of those which can’t. The -fe/forceElement flag will add all the items to the set but will also remove any of those items that are in any other set which is in the same partition as the set. There are several operations on sets that can be performed with the setscommand. Membership can be queried. Tests for whether an item is in a set or whether two sets share the same item can be performed. Also, the union, intersection and difference of sets can be performed which returns a list of members of the sets which are a result of the operation.

Modifications
  • resolved confusing syntax: operating set is always the first and only arg:

    >>> from pymel.core import *
    >>> f=newFile(f=1) #start clean
    >>>
    >>> shdr, sg = createSurfaceShader( 'blinn' )
    >>> shdr
    nt.Blinn(u'blinn1')
    >>> sg
    nt.ShadingEngine(u'blinn1SG')
    >>> s,h = polySphere()
    >>> s
    nt.Transform(u'pSphere1')
    >>> sets( sg, forceElement=s ) # add the sphere
    nt.ShadingEngine(u'blinn1SG')
    >>> sets( sg, q=1)  # check members
    [nt.Mesh(u'pSphereShape1')]
    >>> sets( sg, remove=s )
    nt.ShadingEngine(u'blinn1SG')
    >>> sets( sg, q=1)
    []
    
  • returns wrapped classes

Flags:

Long Name / Short Name Argument Types Properties
addElement / add PyNode ../../../_images/edit.gif
  Adds the list of items to the given set. If some of the items cannot be added to the set because they are in another set which is in the same partition as the set to edit, the command will fail.
afterFilters / af bool ../../../_images/edit.gif
  Default state is false. This flag is valid in edit mode only. This flag is for use on sets that are acted on by deformers such as sculpt, lattice, blendShape. The default edit mode is to edit the membership of the group acted on by the deformer. If you want to edit the group but not change the membership of the deformer, set the flag to true.
clear / cl PyNode ../../../_images/edit.gif
  An operation which removes all items from the given set making the set empty.
color / co int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
  Defines the hilite color of the set. Must be a value in range [-1, 7] (one of the user defined colors). -1 marks the color has being undefined and therefore not having any affect. Only the vertices of a vertex set will be displayed in this color.
copy / cp PyNode ../../../_images/create.gif
  Copies the members of the given set to a new set. This flag is for use in creation mode only.
edges / eg bool ../../../_images/create.gif ../../../_images/query.gif
  Indicates the new set can contain edges only. This flag is for use in creation or query mode only. The default value is false.
editPoints / ep bool ../../../_images/create.gif ../../../_images/query.gif
  Indicates the new set can contain editPoints only. This flag is for use in creation or query mode only. The default value is false.
empty / em bool ../../../_images/create.gif
  Indicates that the set to be created should be empty. That is, it ignores any arguments identifying objects to be added to the set. This flag is only valid for operations that create a new set.
facets / fc bool ../../../_images/create.gif ../../../_images/query.gif
  Indicates the new set can contain facets only. This flag is for use in creation or query mode only. The default value is false.
flatten / fl PyNode ../../../_images/edit.gif
  An operation that flattens the structure of the given set. That is, any sets contained by the given set will be replaced by its members so that the set no longer contains other sets but contains the other sets’ members.
forceElement / fe PyNode ../../../_images/edit.gif
  For use in edit mode only. Forces addition of the items to the set. If the items are in another set which is in the same partition as the given set, the items will be removed from the other set in order to keep the sets in the partition mutually exclusive with respect to membership.
include / include PyNode ../../../_images/edit.gif
  Adds the list of items to the given set. If some of the items cannot be added to the set, a warning will be issued. This is a less strict version of the -add/addElement operation.
intersection / int PyNode ../../../_images/create.gif
  An operation that returns a list of items which are members of all the sets in the list.
isIntersecting / ii PyNode ../../../_images/create.gif
  An operation which tests whether the sets in the list have common members.
isMember / im PyNode ../../../_images/create.gif
  An operation which tests whether all the given items are members of the given set.
layer / l bool ../../../_images/create.gif
  OBSOLETE. DO NOT USE.
name / n unicode ../../../_images/create.gif
  Assigns string as the name for a new set. This flag is only valid for operations that create a new set.
noSurfaceShader / nss bool ../../../_images/create.gif
  If set is renderable, do not connect it to the default surface shader. Flag has no meaning or effect for non renderable sets. This flag is for use in creation mode only. The default value is false.
noWarnings / nw bool ../../../_images/create.gif
  Indicates that warning messages should not be reported such as when trying to add an invalid item to a set. (used by UI)
nodesOnly / no bool ../../../_images/query.gif
  This flag is usable with the -q/query flag but is ignored if used with another queryable flags. This flag modifies the results of the set membership query such that when there are attributes (e.g. sphere1.tx) or components of nodes included in the set, only the nodes will be listed. Each node will only be listed once, even if more than one attribute or component of the node exists in the set.
remove / rm PyNode ../../../_images/edit.gif
  Removes the list of items from the given set.
renderable / r bool ../../../_images/create.gif ../../../_images/query.gif
  This flag indicates that a special type of set should be created. This type of set (shadingEngine as opposed to objectSet) has certain restrictions on its membership in that it can only contain renderable elements such as lights and geometry. These sets are referred to as shading groups and are automatically connected to the renderPartitionnode when created (to ensure mutual exclusivity of the set’s members with the other sets in the partition). This flag is for use in creation or query mode only. The default value is false which means a normal set is created.
size / s bool ../../../_images/query.gif
  Use the size flag to query the length of the set.
split / sp PyNode ../../../_images/create.gif
  Produces a new set with the list of items and removes each item in the list of items from the given set.
subtract / sub PyNode ../../../_images/create.gif
  An operation between two sets which returns the members of the first set that are not in the second set.
text / t unicode ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
  Defines an annotation string to be stored with the set.
union / un PyNode ../../../_images/create.gif
  An operation that returns a list of all the members of all sets listed.
vertices / v bool ../../../_images/create.gif ../../../_images/query.gif
  Indicates the new set can contain vertices only. This flag is for use in creation or query mode only. The default value is false. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.sets

Example:

import pymel.core as pm

# create some objects
pm.sphere( n="sphere1" )
# Result: [nt.Transform(u'sphere1'), nt.MakeNurbSphere(u'makeNurbSphere1')] #
pm.cone( n="cone1" )
# Result: [nt.Transform(u'cone1'), nt.MakeNurbCone(u'makeNurbCone1')] #

# create a set with whatever is currently active
pm.select( 'sphere1' )
newSet1 = pm.sets()
pm.select( 'cone1' )
newSet2 = pm.sets()

# Query the members of a set
pm.sets( newSet1, q=True )
# Result: [nt.Transform(u'sphere1')] #

# create a set which contains two sets
pm.sets( newSet1, newSet2, n="setOfSets" )
# Result: nt.ObjectSet(u'setOfSets') #

# To select a set, the -noExpand flag must be used. Otherwise
# the members of a set are selected instead.
pm.select( newSet1, noExpand=True )
pm.ls( selection=True )
# Result: [nt.ObjectSet(u'set1')] #

# Select the members of a set
pm.select( newSet1 )
pm.ls( selection=True )
# Result: [nt.Transform(u'sphere1')] #

# Create a vertex set named ballVertices. This will contain
# all the vertices of the sphere.
pm.sets( 'sphere1', n="ballVertices", v=1 )
# Result: nt.ObjectSet(u'ballVertices') #
pm.select( 'ballVertices' )

# Return the union of two sets
pm.sets( newSet2, un=newSet1 )
# Result: [nt.Transform(u'cone1'), nt.Transform(u'sphere1')] #

# Test whether a list of sets have common members
pm.sets( 'ballVertices',ii=newSet1)
# Result: False #

# Test whether the sphere is a member of the set
pm.sets('sphere1',im=newSet1)

# Remove the sphere from a set
pm.sets( 'sphere1', rm=newSet1 )

# Test again whether the sphere is a member of the set
pm.sets( 'sphere1', im=newSet1 )