-
Notifications
You must be signed in to change notification settings - Fork 4
/
selectInstances.py
50 lines (34 loc) · 1.07 KB
/
selectInstances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from maya import cmds
from maya.api import OpenMaya
def getInstances(path: str):
sel = OpenMaya.MSelectionList()
sel.add(path)
dagPath = sel.getDagPath(0)
objs = []
itDag = OpenMaya.MItDag()
itDag.reset(dagPath, OpenMaya.MItDag.kBreadthFirst)
fnDag = OpenMaya.MFnDagNode()
while not itDag.isDone():
fnDag.setObject(itDag.currentItem())
if fnDag.isInstanced():
mObj = fnDag.parent(0)
p = OpenMaya.MFnDagNode(mObj)
dataParent = p.fullPathName()
dagPath2 = itDag.getPath()
dagPath2.pop(1)
hierarchyParent = dagPath2.fullPathName()
if dataParent != hierarchyParent:
objs.append(hierarchyParent)
itDag.next()
return objs
def main(select=True):
root = cmds.ls(sl=True, fl=True, long=True)
if not root:
cmds.error("Nothing is select, select root group.")
else:
root = root[0]
instances = getInstances(root)
if select:
cmds.select(instances, r=True)
if __name__ == "__main__":
main()