hey gerard,
nice to see you at the pub the other day :)
here's some API code for looking for custom attrs called "tags" and then
looking for a string inside that. it's a bunch faster than maya cmds. adapt
as necessary. it's filtering on transform nodes currently, but you could
change that for your node type you want to target.
import time
import maya.api.OpenMaya as om2
def findByTag(inTag):
coll = []
sel = om2.MGlobal.getSelectionListByName('*')
depFn = om2.MFnDependencyNode()
xformType = om2.MTypeId(0x5846524d)
for i in xrange(sel.length()):
mObj = sel.getDependNode(i)
depNode = depFn.setObject(mObj)
if depNode.typeId == xformType:
if depNode.hasAttribute('tags'):
plug = depNode.findPlug("tags", False)
result = plug.asString()
if result:
tags = result.split(',')
if inTag in tags:
coll.append(depNode.name())
return coll
ts = time.time()
coll = findByTag('blah')
te = time.time()
print coll
#cmds.select(coll)
print 'api2 %2.4f sec' % (te - ts)
print len(coll)
cheers,
chrisg
On 12 March 2015 at 12:38, Gerard v <[email protected]> wrote:
Hi all.
>
> I am trying to determine the most efficient way to search for nodes
> (transforms) of specified types (eg transform of a curve) under a hierarchy
> (lets call it 'top_node') that have a specific custom (string) attribute.
> When potentially dealing with a large number of nodes speed becomes a
> factor.
>
>
>
--
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/CAPoKtNfn1sCAivOYEw5NQ2kFpWGzdQVYZcfP8FXBrm53_mm%3DOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.