【MayaPython】Is()命令行运用

简介:

示例:

首先导入头文件

import maya.cmds as cmds
  • 列出所有对象
# 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 )
  • 列出所有名为“sphere1”的对象。注意,由于sphere1是实例化的,下面的命令只列出第一个实例。
# List all objects named "sphere1". Note that since sphere1 is
# instanced, the command below lists only the first instance.
cmds.ls( 'sphere1' )
  • 列出所有Sphere1的实例,使用全路径标签
# To list all instances of sphere1, use the -ap/allPaths flag.
cmds.ls( 'sphere1', ap=True )
  • 列出所有选中的对象所命名的“group*”
# 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 )
  • 需要注意的一点是,在列出没有任何过滤器的节点时,最好总是使用-L/Long flgg。这是因为可能有两个具有相同名称的节点(在本例中为circlel)。Ls将列出场景中所有对象的名称,具有相同名称的对象需要一个限定路径名来唯一标识对象。一个命令选择所有对象,例如“select is”将失败,因为对象查找无法解析要查找的是哪个“circler”对象。要选择所有对象,您需要以下步骤:
cmds.select(cmds.ls(sl=True))
  • 当我们尝试在一个列表中查找一种特殊的对象类型时,一种方法是获取所有的对象然后再使用nodetype命令去筛选列表。示例:
# 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
  • 这里的问题是“nodetype”返回大多数的类型,在这个案例中“surfaceShape”是nurbsSurface的基本类型,因此不会打印任何内容。针对这个问题,这里的 -typ/type标签应该用于列出特定类型的对象,如:``
# 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 )
  • 列出DAG中所有叶节点的所有路径
# 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 )
  • 列出所有ghosting对象
# 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.namespae( 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 modified 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']

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335