Go to: Synopsis. Return value. Flags. MEL examples.

Synopsis

ls [-allPaths] [-assemblies] [-cameras] [-containers] [-dagObjects] [-dependencyNodes] [-exactType string] [-flatten] [-geometry] [-ghost] [-head int] [-hilite] [-intermediateObjects] [-invisible] [-leaf] [-lights] [-live] [-lockedNodes] [-long] [-materials] [-noIntermediate] [-nodeTypes] [-objectsOnly] [-partitions] [-persistentNodes] [-planes] [-preSelectHilite] [-readOnly] [-recursive boolean] [-referencedNodes] [-references] [-renderGlobals] [-renderQualities] [-renderResolutions] [-renderSetups] [-selection] [-sets] [-shapes] [-shortNames] [-showType] [-tail int] [-templated] [-textures] [-transforms] [-type string] [-undeletable] [-untemplated] [-visible] [object [object...]]

ls is undoable, NOT queryable, and NOT editable.

The ls command returns the names (and optionally the type names) of objects in the scene. The most common use of ls is to filter or match objects based on their name (using wildcards) or based on their type. By default ls will match any object in the scene but it can also be used to filter or list the selected objects when used in conjunction with the -selection flag. If type names are requested, using the -showType flag, they will be interleaved with object names so the result will be pairs of <object, type> values. Internal nodes (for example itemFilter nodes) are typically filtered so that only scene objects are returned. However, using a wildcard will cause all the nodes matching the wild card to show up, including internal nodes. For example, ls * will list all nodes whether internal or not. When Maya is in relativeNames mode, the ls command will return names relative to the current namespace and ls * will list from the the current namespace. For more details, please refer to the -relativeNames flag of the namespace command.

Return value

string[]

Flags

allPaths, assemblies, cameras, containers, dagObjects, dependencyNodes, exactType, flatten, geometry, ghost, head, hilite, intermediateObjects, invisible, leaf, lights, live, lockedNodes, long, materials, noIntermediate, nodeTypes, objectsOnly, partitions, persistentNodes, planes, preSelectHilite, readOnly, recursive, referencedNodes, references, renderGlobals, renderQualities, renderResolutions, renderSetups, selection, sets, shapes, shortNames, showType, tail, templated, textures, transforms, type, undeletable, untemplated, visible
Long name (short name) Argument types Properties
-long(-l) create
Return full path names for Dag objects. By default the shortest unique name is returned.
-shortNames(-sn) create
Return short attribute names. By default long attribute names are returned.
-head(-hd) int create
This flag specifies the maximum number of elements to be returned from the beginning of the list of items. Note: each type flag will return at most this many items so if multiple type flags are specified then the number of items returned can be greater than this amount.
-tail(-tl) int create
This flag specifies the maximum number of elements to be returned from the end of the list of items. Note: each type flag will return at most this many items so if multiple type flags are specified then the number of items returned can be greater than this amount
-type(-typ) string createmultiuse
List all objects of the specified type. This flag can appear multiple times on the command line. Note: the type passed to this flag is the same type name returned from the -showType flag. Note: some selection items in Maya do not have a specific object/data type associated with them and will return "untyped" when listed with this flag.
This flag cannot be used in conjunction with the -exactType flag.
-exactType(-et) string createmultiuse
List all objects of the specified type, but not objects that are descendents of that type. This flag can appear multiple times on the command line. Note: the type passed to this flag is the same type name returned from the -showType flag.
This flag cannot be used in conjunction with the -type flag.
-showType(-st) create
List the type of each object after its name.
-objectsOnly(-o) create
When this flag is set only object names will be returned and components/attributes will be ignored.
-selection(-sl) create
List objects that are currently selected.
-live(-lv) create
List objects that are currently live.
-hilite(-hl) create
List objects that are currently hilited for component selection.
-preSelectHilite(-psh) create
List components that are currently hilited for pre-selection.
-geometry(-g) create
List geometric Dag objects.
-dependencyNodes(-dep) create
List dependency nodes. (including Dag objects)
-dagObjects(-dag) create
List Dag objects of any type. If object name arguments are passed to the command then this flag will list all Dag objects below the specified object(s).
-leaf(-lf) create
List all leaf nodes in Dag. This flag is a modifier and must be used in conjunction with the -dag flag.
-assemblies(-as) create
List top level transform Dag objects
-allPaths(-ap) create
List all paths to nodes in DAG. This flag only works if -dag is also specified or if an object name is supplied.
-transforms(-tr) create
List transform objects.
-shapes(-s) create
List shape objects.
-lights(-lt) create
List light shapes.
-cameras(-ca) create
List camera shapes.
-planes(-pl) create
List construction plane shapes.
-partitions(-pr) create
List partitions.
-sets(-set) create
List sets.
-textures(-tex) create
List textures.
-materials(-mat) create
List materials or shading groups.
-renderQualities(-rq) create
List named render qualities.
-renderResolutions(-rr) create
List render resolutions.
-renderGlobals(-rg) create
List render globals.
-renderSetups(-rs) create
Alias for -renderGlobals.
-nodeTypes(-nt) create
Lists all registered node types.
-readOnly(-ro) create
Returns referenced nodes. Referenced nodes are read only. NOTE: Obsolete. Please use "-referencedNodes".
-referencedNodes(-rn) create
Returns referenced nodes. Referenced nodes are read only.
-undeletable(-ud) create
Returns nodes that cannot be deleted (which includes locked nodes). These nodes also cannot be renamed.
-lockedNodes(-ln) create
Returns locked nodes, which cannot be deleted or renamed. However, their status may change.
-persistentNodes(-pn) create
Returns persistent nodes, which are nodes that stay in the Maya session after a file > new.
-flatten(-fl) create
Flattens the returned list of objects so that each component is identified individually.
-visible(-v) create
List only visible dag nodes.
-invisible(-iv) create
List only invisible dag nodes.
-intermediateObjects(-io) create
List only intermediate dag nodes.
-noIntermediate(-ni) create
List only non intermediate dag nodes.
-templated(-tm) create
List only templated dag nodes.
-untemplated(-ut) create
List only un-templated dag nodes.
-ghost(-gh) create
List ghosting objects.
-recursive(-r) boolean create
When set to true, this command will look for name matches in all namespaces. When set to false, this command will only look for matches in namespaces that are requested (e.g. by specifying a name containing the ':'... "ns1:pSphere1").
-references(-rf) create
List references associated with files. Excludes special reference nodes such as the sharedReferenceNode and unknown reference nodes.
-containers(-con) create
List containers. Includes both standard containers as well as other types of containers such as dagContainers.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can be used more than once in a command.

MEL examples

// create some objects to operate on and select them all.
// Note that there are two objects named circle1;
circle -n circle1; group; circle -n circle1;
sphere -n sphere1; group; instance;
select -ado;

// list all objects
ls;

// List all selected objects
ls -selection;

// List all hilited objects
ls -hilite;

// List last selected object
ls -selection -tail 1;

// List all objects named "sphere1". Note that since sphere1 is
// instanced, the command below lists only the first instance.
ls sphere1;

// To list all instances of sphere1, use the -ap/allPaths flag.
ls -ap sphere1;

// List all selected objects named "group*"
ls -sl "group*";

// List all geometry, lights and cameras in the DAG.
ls -geometry -lights -cameras;

// List all shapes in the dag.
ls -shapes;

// One thing to note is that it is better to always use the
// -l/long flag when listing nodes without any filter. This is
// because there may be two nodes with the same name (in this
// example, circle1). 'ls' will list the names of all the objects
// in the scene. Objects with the same name need a qualified
// path name which uniquely identifies the object. A command
// to select all objects such as "select `ls`" will fail because
// the object lookup can't resolve which "circle1" object is
// intended. To select all objects, you need the following:
// select `ls -l`;

// When trying to find a list of all objects of a specific
// type, one approach might be to list all objects and then
// use the nodeType command to then filter the list. As in:
// string  $allObjects[];
// string  $obj;
// $allObjects = `ls -l`;
// for ( $obj in $allObjects ) {
//     if ( `nodeType $obj` == "surfaceShape" ) {
//         print ($obj + "\n");
//     }
// }
//
// The problem with this is that 'nodeType' returns the
// most derived type of the node. In this example, "surfaceShape"
// is a base type for nurbsSurface so nothing will be printed.
// To do this properly, the -typ/type flag should be used
// to list objects of a specific type as in:
// $allObjects = `ls -type surfaceShape`;
// for ( $obj in $allObjects ) {
//     print ($obj + "\n");
// }

// List all geometry shapes and their types
ls -type geometryShape -showType;

// List all paths to all leaf nodes in the DAG
ls -dag -lf -ap;

// List all nodes below the selected node
ls -dag -ap -sl;

// List all dag nodes that are read-only (i.e. referenced nodes)
ls -dag -ro;

// List all ghosting objects
ls -ghost;

// List reference nodes associated with specific files
ls -references;

// List all reference nodes, including unknown and shared reference
// nodes
ls -type reference;