ジャンプ先: 概要. 戻り値. フラグ. Python 例.

概要

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

注: オブジェクトの名前と引数を表す文字列は、カンマで区切る必要があります。これはシノプシスに示されていません。

ls は、取り消し可能、照会不可能、および編集不可能です。

ls コマンドでは、シーン内のオブジェクトの名前(およびオプションでタイプ名)が返されます。

ls は一般的に、名前(ワイルドカードを含む)またはタイプに基づいて、オブジェクトのフィルタ処理または突き合せを行うのに使用します。既定では ls コマンドはシーン内のすべてのオブジェクトと突き合せを行いますが、-selection フラグを一緒に使用すると、選択したオブジェクトをフィルタリングまたはリスト表示することができます。

showType フラグを使用してタイプ名を要求すると、結果はオブジェクト名を挟んだ <object, type> の組み合わせで返されます。

内部ノード(例: itemFilter ノード)は、通常、シーン オブジェクトのみを返すようにフィルタリングされます。ただし、ワイルドカードを使用すると、ワイルドカードに一致するすべてのノードが内部ノードも含めて表示されてしまいます。たとえば、ls * の場合、内部ノードかどうかに関係なくすべてのノードがリスト表示されます。

ノードをリストするときに再帰的ネームスペース検索を指示するには、構文「::」を使用します。たとえば、ls "::pSphere1" は、深度にかかわらず、すべてのネームスペース内の「pSphere1」という名前のオブジェクトと一致します。ls "ns::*" は、ネームスペース「ns」または子ネームスペース内の任意のノードと一致します。

Maya が relativeNames モードにある場合、ls コマンドは現在のネームスペースに関連する名前を返し、ls * は現在のネームスペースからリスト表示します。詳細については、namespace コマンドの -relativeNames フラグを参照してください。

このコマンドは、名前/パスでなくノードの UUID を渡すこともできます。-uuid フラグを指定すると、名前でなく UUID を返すことができます。

戻り値

string[]コマンドの結果

フラグ

absoluteName, allPaths, assemblies, cameras, containerType, containers, dagObjects, defaultNodes, dependencyNodes, exactType, excludeType, flatten, geometry, ghost, head, hilite, intermediateObjects, invisible, leaf, lights, live, lockedNodes, long, materials, modified, noIntermediate, nodeTypes, objectsOnly, orderedSelection, partitions, persistentNodes, planes, preSelectHilite, readOnly, recursive, referencedNodes, references, renderGlobals, renderQualities, renderResolutions, renderSetups, selection, sets, shapes, shortNames, showNamespace, showType, tail, templated, textures, transforms, type, ufeObjects, undeletable, untemplated, uuid, visible
ロング ネーム(ショート ネーム) 引数タイプ プロパティ
absoluteName(an) boolean create
このフラグを showNamespace フラグと一緒に使用することで、コマンドによって返されるネームスペースが絶対ネームスペース フォーマットになるように指定できます。ネームスペースの絶対名は、ルート ネームスペース「:」で始まり、すべての親ネームスペースを含むフル ネームスペース パスです。たとえば、「:ns:ball」は絶対ネームスペース名ですが、「ns:ball」は絶対ネームスペース名ではありません。絶対ネームスペース名は不変であり、現在のネームスペースまたは相対ネームスペース モードの影響を受けません。
allPaths(ap) boolean create
DAG 内にあるノードのすべてのパスがリストされます。このフラグは、-dag も指定した場合、またはオブジェクト名を指定した場合に限って動作します。
assemblies(assemblies) boolean create
最上位レベルのトランスフォーム DAG オブジェクトがリストされます。
cameras(ca) boolean create
カメラのシェイプがリストされます。
containerType(ct) string createmultiuse
指定のユーザ定義タイプを伴うリスト コンテナです。
このフラグは、type または exactType フラグと一緒に使用できません。
containers(con) boolean create
コンテナをリストします。標準コンテナと dagContainers などの別のコンテナ タイプの両方を含みます。
dagObjects(dag) boolean create
すべてのタイプの DAG オブジェクトがリストされます。オブジェクト名引数をコマンドに渡した場合、このフラグでは、指定したオブジェクトの下にすべての DAG オブジェクトがリストされます。
defaultNodes(dn) boolean create
既定のノードを返します。既定のノードとは、Maya が自動的に作成するノードで、シーンとともに保存されないノードです。ただし、ノードのいくつかアトリビュート値は保存することができます。
dependencyNodes(dep) boolean create
ディペンデンシー ノードがリストされます(DAG オブジェクトを含む)。
exactType(et) string createmultiuse
指定したタイプのオブジェクトをすべてリストします。ただし、そのタイプの下層にあるオブジェクトはリストしません。このフラグは、コマンド ラインで複数回使用できます。注: このフラグに渡すタイプは、showType フラグで返されるタイプ名と同じになります。
このフラグは、type または excludeType フラグと一緒に使用できません。
excludeType(ext) string createmultiuse
指定したタイプではないすべてのオブジェクトがリストされます。このフラグは、コマンド ラインで複数回使用できます。注: このフラグに渡すタイプは、showType フラグで返されるタイプ名と同じになります。
このフラグは、type または exactType フラグと一緒に使用できません。
flatten(fl) boolean create
返されるオブジェクトのリストを平らにし、それぞれのコンポーネントを個別に識別できるようにします。
geometry(g) boolean create
ジオメトリ DAG オブジェクトがリストされます。
ghost(gh) boolean create
ゴースト化オブジェクトがリストされます。
head(hd) int create
項目のリストの先頭から返される要素の最大数を指定します。注: それぞれの type フラグでは、最大でこの数の項目が返されます。複数の type フラグを指定すると、返される項目の数は、指定した値より多くなります。
hilite(hl) boolean create
コンポーネント選択で現在ハイライトされているオブジェクトがリストされます。
intermediateObjects(io) boolean create
中間 DAG ノードのみがリストされます。
invisible(iv) boolean create
表示されない DAG ノードのみがリストされます。
leaf(lf) boolean create
DAG のすべてのリーフ ノードがリストされます。このフラグはモディファイアなので、-dag フラグと一緒に使用する必要があります。
lights(lt) boolean create
ライトのシェイプがリストされます。
live(lv) boolean create
現在ライブにしているオブジェクトがリストされます。
lockedNodes(ln) boolean create
ロックされたノードを返します。これらのノードは削除も名前の変更もできません。ただし、ステータスは変更できます。
long(l) boolean create
DAG オブジェクトのフル パス名が返されます。既定では、最も短い固有の名前を返します。
materials(mat) boolean create
マテリアルまたはシェーディング グループがリストされます。
modified(mod) boolean create
このフラグを設定した場合、最後の保存後に変更されたノードのみが返されます。
noIntermediate(ni) boolean create
中間以外の DAG ノードのみがリストされます。
nodeTypes(nt) boolean create
登録されているすべてのノード タイプがリストされます。
objectsOnly(o) boolean create
設定すると、オブジェクト名のみが返され、コンポーネントやアトリビュートは無視されます。
orderedSelection(os) boolean create
オブジェクトとコンポーネントを現在の選択順でリスト表示します。このフラグは、selectPref コマンドの -tso/trackSelectionOrder フラグの値に依存します。そのフラグが有効になっていなければ、このフラグは -sl/selection フラグと同じものを返します。
partitions(pr) boolean create
パーティションがリストされます。
persistentNodes(pn) boolean create
永続ノードを返します。これは「file」 > 「new」の後の Maya セッションでも存続するノードです。ファイル > 新規でリセットされない特殊なクラスの既定のノードがあります。たとえば、itemFilter ノード、selectionListOperator ノードです。
planes(pl) boolean create
コンストラクション プレーンのシェイプがリストされます。
preSelectHilite(psh) boolean create
プリ選択で現在ハイライトされているコンポーネントがリストされます。
readOnly(ro) boolean create
参照されたノードを返します。参照されたノードは読み取り専用です。注: 廃止されました。「-referencedNodes」を使用してください。
recursive(r) boolean create
true に設定すると、このコマンドはすべてのネームスペースから合致する名前を探します。false に設定すると、要求されたネームスペースだけから探します(たとえば「:」を含む名前を指定すると、「ns1:pSphere1」)。
referencedNodes(rn) boolean create
参照されたノードを返します。参照されたノードは読み取り専用です。
references(rf) boolean create
ファイルに関連するリファレンスをリストします。sharedReferenceNode や不明リファレンス ノードなどの特別なリファレンス ノードは除外します。
renderGlobals(rg) boolean create
レンダー グローバルがリストされます。
renderQualities(rq) boolean create
指定したレンダー画質がリストされます。
renderResolutions(rr) boolean create
レンダー解像度がリストされます。
renderSetups(rs) boolean create
-renderGlobals のエイリアス。
selection(sl) boolean create
現在選択しているオブジェクトがリストされます。
sets(set) boolean create
セットがリストされます。
shapes(s) boolean create
シェイプ オブジェクトがリストされます。
shortNames(sn) boolean create
アトリビュートのショート ネームが返されます。既定では、アトリビュートのロング ネームが返されます。
showNamespace(sns) boolean create
オブジェクト名の後に各オブジェクトのネームスペースを表示します。
このフラグは showType フラグと一緒に使用することはできません。
showType(st) boolean create
オブジェクト名の後にタイプがリストされます。
tail(tl) int create
項目のリストの末尾から返される要素の最大数を指定します。注: それぞれの type フラグでは、最大でこの数の項目が返されます。複数の type フラグを指定すると、返される項目の数は、指定した値より多くなります
templated(tm) boolean create
テンプレート化 DAG ノードのみがリストされます。
textures(tex) boolean create
テクスチャがリストされます。
transforms(tr) boolean create
トランスフォーム オブジェクトがリストされます。
type(typ) string createmultiuse
指定したタイプのすべてのオブジェクトがリストされます。このフラグは、コマンド ラインで複数回使用できます。注: このフラグに渡すタイプは、showType フラグで返されるタイプ名と同じになります。注: Maya での一部の選択項目は、特定オブジェクト/データ タイプが関連しないので、このフラグでリストすると「untyped」が返されます。
このフラグは、exactType または excludeType フラグと一緒に使用できません。
ufeObjects(ufe) boolean create
-sl/selection フラグと一緒に使用すると、ネイティブの Maya オブジェクトだけでなく、UFE インタフェースによって定義されているオブジェクトも返されます。
undeletable(ud) boolean create
削除できないノード(ロックされたノードを含む)を返します。削除できないノードは名前の変更もできません。
untemplated(ut) boolean create
テンプレート化が解除された DAG ノードのみがリストされます。
uuid(uid) boolean create
ノード名の代わりに ノードの UUID を返します。「UUID パス」がないことにご注意ください。このフラグと -long フラグなどを組み合わせた場合、ノード UUID のパスは形成されません。
visible(v) boolean create
可視 DAG ノードのみがリストされます。

フラグはコマンドの作成モードで表示できます フラグはコマンドの編集モードで表示できます
フラグはコマンドの照会モードで表示できます フラグに複数の引数を指定し、タプルまたはリストとして渡すことができます。

Python 例

import maya.cmds as cmds

# Create some objects to operate on and select them all.
# Note that there are two objects named circle1;
cmds.circle( n='circle1' )
cmds.group()
cmds.circle( n='circle1' )
cmds.sphere( n='sphere1' )
cmds.group()
cmds.instance()
cmds.select( ado=True )

# list all objects
cmds.ls()

# List all selected objects
cmds.ls( selection=True )

# List all hilited objects
cmds.ls( hilite=True )

# List last selected object
cmds.ls( selection=True, tail=1 )

# List all objects named "sphere1". Note that since sphere1 is
# instanced, the command below lists only the first instance.
cmds.ls( 'sphere1' )

# To list all instances of sphere1, use the -ap/allPaths flag.
cmds.ls( 'sphere1', ap=True )

# List all selected objects named "group*"
cmds.ls( 'group*', sl=True )

# List all geometry, lights and cameras in the DAG.
cmds.ls( geometry=True, lights=True, cameras=True )

# List all shapes in the dag.
cmds.ls( shapes=True )

# 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:
cmds.select(cmds.ls(sl=True))

# 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:
allObjects = cmds.ls(l=True)
for obj in allObjects:
   if cmds.nodeType(obj) == 'surfaceShape':
     print obj

# 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 = cmds.ls(type='surfaceShape')
for obj in allObjects:
    print obj

# List all geometry shapes and their types
cmds.ls( type='geometryShape', showType=True )

# List all paths to all leaf nodes in the DAG
cmds.ls( dag=True, lf=True, ap=True )

# List all nodes below the selected node
cmds.ls( dag=True, ap=True, sl=True )

# List all ghosting objects
cmds.ls( ghost=True )

# List all dag nodes that are read-only (i.e. referenced nodes)
cmds.ls( dag=True, ro=True )

# List reference nodes associated with specific files
cmds.ls( references=True )

# List all reference nodes, including unknown and shared reference nodes
cmds.ls( type='reference' )

# Select some components and then get the list in both selected and numeric order
obj1 = cmds.polySphere( sx=20, sy=20 )
cmds.select( clear=True )

cmds.selectPref( trackSelectionOrder=1 )

cmds.select( obj1[0]+".f[100]" )
cmds.select( (obj1[0]+".f[50:55]"), add=True )
cmds.select( (obj1[0]+".f[0]"), add=True )
cmds.select( (obj1[0]+".f[56:60]"), add=True )

# Regular -selection flag returns the components in compacted numeric order.
cmds.ls( selection=True )
# Result:_ [u'pSphere1.f[0]', u'pSphere1.f[50:60]', u'pSphere1.f[100]'] #

# -orderedSelection flag returns the components in the order that we selected them.
cmds.ls( orderedSelection=True )
# Result:_ [u'pSphere1.f[100]', u'pSphere1.f[50:55]', u'pSphere1.f[0]', u'pSphere1.f[56:60]'] #

# Turn off tracking when we are done
cmds.selectPref( trackSelectionOrder=0 )

# Init some namespace
cmds.namespace( add="A:B:C" )

# add object into namespace
cmds.namespace( set=":A:B" )
cmds.polySphere( name="obj1" )
cmds.namespace( set=":A:B:C" )
cmds.polySphere( name="obj1" )
cmds.polySphere( name="obj2" )


# The current Namespace is ":A:B:C" and relative mode is off
# List all objects and their namespace in the scene
# If the object is in the root namespace, then return root ":"
# Note that the results shown below have been elided (...) for documentation purposes.
cmds.ls( showNamespace=True )
# Result: [u'time1', u':', u'sequenceManager1', u':', u'renderPartition', u':', (...), u'A:B:obj1', u'A:B', u'A:B:C:obj1', u'A:B:C', u'A:B:C:obj2', u'A:B:C'] #

cmds.select( ":A:B:obj1", r=True )
cmds.select( ":A:B:C:obj2", add=True)


# List namespace of all objects named "obj1"
cmds.ls( "obj1", showNamespace=True, recursive=True )
# Result: [u'A:B:obj1', u'A:B', u'A:B:C:obj1', u'A:B:C'] #

# List both name and namespace of each selected object
cmds.ls( showNamespace=True, selection=True )
# Result: [u'A:B:obj1', u'A:B', u'A:B:C:obj2', u'A:B:C'] #

# Set current namespace
cmds.namespace( set=":A:B" )

# Enable relative mode
cmds.namespace( relativeNames=True )

# Now the current namespace is ":A:B" and relative mode is on
# Note that the name of the current namespace is "" in relative mode
# List both name and namespace of each selected objects
cmds.ls( showNamespace=True, selection=True )
# Result: [u'obj1', u'', u'C:obj2', u'C'] #

# Make a new scene, modify the transform of the camera perspective, play with the timeline and modify the camera's shape
cmds.file(force=True, new=True)
cmds.setAttr('persp.translateX', 10)
cmds.currentTime(8)
cmds.setAttr('perspShape.horizontalFilmAperture', 16)

# List all modified objects of type camera and type time
allObjects=cmds.ls(type=['camera','time'], modified=True)
print allObjects
# Result: [u'perspShape', u'time1']

cmds.ls(modified=True)
# Result: [u'persp', u'perspShape', u'time1']

cmds.ls(modified=True, excludeType='camera')
# Result: [u'persp', u'time1']

# Return a node's UUID
cmds.ls( 'sphere1', uuid=True )
# Result: [u'ECE85CCC-438D-8113-0236-39A6917DE484']

# Find a node by UUID
cmds.ls( 'ECE85CCC-438D-8113-0236-39A6917DE484' )
# Result: [u'group2|sphere1']