Aha! I knew I was missing something with ls! Thanks for the heads up I have been looking for this for ages. Still, was good to actually jump into the API :)
On 3 April 2016 at 15:09, Marcus Ottosson <[email protected]> wrote: > I know the goal isn’t to solve this particular problem, but to learn more > about the API. But in case you didn’t already know, ls with wildcard can > do some of this for you. > > # Find nodes with prefixcmds.ls("prefix_*") > # Find nodes with suffixcmds.ls("*_suffix") > # Find nodes of typecmds.ls(type="locator") > # Find nodes with suffix, that are children at 2nd level of a > hierarchycmds.ls("|myParent|*|*_suffix", dag=True) > > On 3 April 2016 at 11:54, Benjam901 <[email protected]> wrote: > > 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 >> <https://groups.google.com/d/msgid/python_inside_maya/66fc6191-2361-4c99-b954-ea8550863ba2%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > *Marcus Ottosson* > [email protected] > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rnrBzWARs1c/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODBFdyk4wKHdNPdNzF_mV%2BstW4AwiRNsjfn_fst4ykB3Q%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODBFdyk4wKHdNPdNzF_mV%2BstW4AwiRNsjfn_fst4ykB3Q%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Tel - +46 76245 92 90 (Sweden) LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b -- 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/CAM2ybkXUjewDNSmaD%2Bzr3%2BZr5Ryg8sPnen5nVKa4q06VwQVRKg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
