Skip to content

Instantly share code, notes, and snippets.

@nrtkbb
Last active September 10, 2025 15:36
Show Gist options
  • Save nrtkbb/d701d703ea3f1742107a7cf1cc008f53 to your computer and use it in GitHub Desktop.
Save nrtkbb/d701d703ea3f1742107a7cf1cc008f53 to your computer and use it in GitHub Desktop.
MItSelectionList vs Only MSelectionList
import datetime
today = datetime.datetime.today
from maya.api import OpenMaya as om2
from maya import cmds
start = today()
sel_list = om2.MSelectionList()
[sel_list.add(m)
for m in cmds.ls(dag=True)]
sel_it = om2.MItSelectionList(sel_list)
dags = []
i = 0
while not sel_it.isDone():
dag_path = sel_it.getDagPath()
dags.append(dag_path)
sel_it.next()
i += 1
#print(dags)
print(today() - start) # 0:00:00.691000
print(i) # 8721
import datetime
today = datetime.datetime.today
from maya.api import OpenMaya as om2
from maya import cmds
start = today()
sel_list = om2.MSelectionList()
dags = []
i = 0
for mesh in cmds.ls(dag=True):
sel_list.clear()
sel_list.add(mesh)
dag_path = sel_list.getDagPath(0)
dags.append(dag_path)
i += 1
#print(dags)
print(today() - start) # 0:00:00.097000
print(i) # 8721
@bafly
Copy link

bafly commented Sep 10, 2025

Hi! Sorry maybe for dumb question... but why wouldn't we just iterate over MSelectionList.getDagPath(i)?

[sel_list.add(m) for m in cmds.ls(dag=1)]
dags = []
for i in range(sel_list.length()):
    dags.append(sel_list.getDagPath(i))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment