Hello all,
I have been digging into the Maya API dungeons recently to get myself up to
speed and familiar with the Maya API.
I have found myself recently digging through hierarchies to get all nodes
of a prefix or of type. I find myself constantly using:
for i in pm.listRelatives(object):
if i.startswith('prefix'):
do stuff...
So I decided to write myself a small plugin for a learning task that does
this for you.
Plugin: https://gist.github.com/ben-hearn-sb/cc5b0ebc5de41fc1f1c937e5b3f3359d
The only problem is the speed of the plugin, I put the plugin and the
original for i in relatives in 2 functions and used timeit in the maya
script editor.
The normal list relatives function was faster which seriously confused me
because I am sure that the API is supposed to be much faster at processing
information, I have a feeling I have some serious inefficiencies in my
plugin so any tips would go a long way to help me out!
Here is the Maya script editor testing:
import maya.cmds as cmds
getObjPluginPath = "path to get_objects_under_node.py"
cmds.loadPlugin(getObjPluginPath)
sel = cmds.ls(sl=True)
def pluginWay():
for s in sel:
cmds.getObjsUnderNode(s, fn='c_')
def normalWay():
for s in sel:
myList = []
for i in cmds.listRelatives(s, ad=True, fullPath=True):
if i.startswith('c_'):
myList.append(i)
#print myList
import timeit
timeit.Timer(pluginWay).timeit(number=500)
timeit.Timer(normalWay).timeit(number=500)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/66fc6191-2361-4c99-b954-ea8550863ba2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.