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 prefix
cmds.ls("prefix_*")
# Find nodes with suffix
cmds.ls("*_suffix")
# Find nodes of type
cmds.ls(type="locator")
# Find nodes with suffix, that are children at 2nd level of a hierarchy
cmds.ls("|myParent|*|*_suffix", dag=True)
--
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 python_inside_m...@googlegroups.com.
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.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODBFdyk4wKHdNPdNzF_mV%2BstW4AwiRNsjfn_fst4ykB3Q%40mail.gmail.com.
Hey Ben,
That's because your plugin is built in Python. The native commands are implemented against the C API which is much faster. Your native example spends less time in python and more in C which is probably why your seeing those results.
The good news is it's a relatively straight forward port from Python API to C if your interested. I commonly prototype plugins in Python then port myself if I don't need performance right away.
Also if your interested in performance I'd suggest using the profile/cProfile module over time it as it'll help you better understand your code and where the time is spent.
Ian
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkXUjewDNSmaD%2Bzr3%2BZr5Ryg8sPnen5nVKa4q06VwQVRKg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAL6_5Q_Lq60ZCQ3Hi4vz0EaA85nDCEUrSEZL8dzU1iNTaPazkw%40mail.gmail.com.
We commonly roll new features out unoptimized just to see if the art team uses them. Many of the tools they don't even bother to ask to make faster vs getting another tool sooner. Others we spend months optimizing for the best possible iteration. It's very much a case by case basis.
Ian
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUOHgTwjNgN%3DRApagUwF%2BfT_gaQ%2BpSmNeT%2B3yuudw6toQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAL6_5Q9LXL9ibararTHOgHki5Wn_k04BP3QDXiLL_nu-BVFdXQ%40mail.gmail.com.
Hey Ben,
As mentioned, the slowness is because you are comparing a python plugin to a C solution. The part of your code that takes the biggest hit is that while loop. Python is doing so many reflection operations, functions calls, and allocations, which is why loops in python will be the killer.
You don't always have to implement your plugins in C. Only when they have performance bottlenecks. There are plenty of applications where you aren't iterating the scene and doing tons of functions calls and object creation. So best to just profile your code and fine the hotspots. Your options for slow python plugins are either to write the entire plugin in C++ or to just write some speed up utilities for slow operations and call them as exposed commands.
I think I even tried writing a simple ls command using Cython a long time ago to see if it would work, and it did. That means you could write some stuff in Cython
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkU-Fs3-1OHohtUKKOCjqSP1tOCJcYxSiFF4WsGK%3D7KG3g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0mBNiAKDE6MEnNi6gJn7RZCObYY7GsJHAd_rK2YHWQFA%40mail.gmail.com.
It shouldn’t care much about children, but rather look at the graph as a whole.
Here’s an example that works for me, returning an inner child.
cmds.file(new=True, force=True)
cmds.polyCube(name="myCube1")
cmds.polyCube(name="myCube2")
cmds.group(name="myGroup")
assert "myCube2" in cmds.ls("*2")
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkXibqPwPD9%3DBrEeKf7zargxw%2BtvBN-6CYy1ZBfuJm7s0A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBLkEaeBoJG%2Bn_VLchywxkOEmTcGBUw1%2BgS0bYm-OH1eg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkX3NO1yRfdXgVvfcGxxyC0Vah%2By%2B1ahCqfKePe7G0NHWA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCyoCkFc%2BEaVFN60wu%2BE%2BkYZMRsD7gWszsi-z1E0Ayy6g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkX3NO1yRfdXgVvfcGxxyC0Vah%2By%2B1ahCqfKePe7G0NHWA%40mail.gmail.com.