移動先: 概要 戻り値 フラグ Python の例
ls(
[object [object...]]
, [allPaths=boolean], [assemblies=boolean], [cameras=boolean], [dagObjects=boolean], [dependencyNodes=boolean], [exactType=string], [flatten=boolean], [geometry=boolean], [ghost=boolean], [head=int], [hilite=boolean], [intermediateObjects=boolean], [invisible=boolean], [leaf=boolean], [lights=boolean], [live=boolean], [long=boolean], [materials=boolean], [noIntermediate=boolean], [nodeTypes=boolean], [objectsOnly=boolean], [partitions=boolean], [planes=boolean], [preSelectHilite=boolean], [readOnly=boolean], [recursive=boolean], [references=boolean], [renderGlobals=boolean], [renderQualities=boolean], [renderResolutions=boolean], [renderSetups=boolean], [selection=boolean], [sets=boolean], [shapes=boolean], [shortNames=boolean], [showType=boolean], [tail=int], [templated=boolean], [textures=boolean], [transforms=boolean], [type=string], [untemplated=boolean], [visible=boolean])
注意: オブジェクト名や引数を表す文字列はカンマで区切ります。これは概要には示されていません。
ls は「元に戻す」が可能、「照会」が不可能、「編集」が不可能です。
ls
コマンドでは、シーン内のオブジェクトの名前(およびオプションでタイプ名)が返されます。
ls
は一般的に、名前(ワイルドカードを含む)またはタイプに基づいて、オブジェクトのフィルタ処理または突き合せを行うのに使用します。
デフォルトでは ls
コマンドはシーン内のすべてのオブジェクトと突き合せを行いますが、-selection フラグを併用すると、選択したオブジェクトをフィルタリングまたはリスト表示することができます。
-showType フラグを使用してタイプ名を要求すると、タイプ名とオブジェクト名が組み合わさり、結果は <object, type> 値というペアになります。
allPaths, assemblies, cameras, dagObjects, dependencyNodes, exactType, flatten, geometry, ghost, head, hilite, intermediateObjects, invisible, leaf, lights, live, long, materials, noIntermediate, nodeTypes, objectsOnly, partitions, planes, preSelectHilite, readOnly, recursive, references, renderGlobals, renderQualities, renderResolutions, renderSetups, selection, sets, shapes, shortNames, showType, tail, templated, textures, transforms, type, untemplated, visible
: コマンドの作成モードで使用可能なフラグ
|
: コマンドの編集モードで使用可能なフラグ
|
: コマンドの照会モードで使用可能なフラグ
|
: タプルまたはリストとして渡された複数の引数を持てるフラグ
|
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 dag nodes that are read-only (i.e. referenced nodes)
cmds.ls( dag=True, ro=True )
# List all ghosting objects
cmds.ls( ghost=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' )