I updated the script too, http://pastebin.com/mb43a9ef (this collaborative service is really cool, I didn't know it)
On Tue, Jul 7, 2009 at 4:34 PM, alessandro pepe <[email protected]> wrote: > ehi Paul, > yes that's not intuitive at all, > after a little reasearch and talking with colleagues we ended up with the > idea that that code is not efficient for 2 reasons: > > 1 - it creates a selection list with ALL the nodes in the scene, which is > kind of slow and unneeded considered that I only need surface nodes. > Furthermore the glob matching seems not to be so quick. > ... AND AFTER that it filters out only the geometries. > It's much better to grab only the geometries since the beginning, and then > filter them using the name filter (regex). > > 2 - there is no need to pass thu a selection list. All i needed is an > iterator, so I could simply use MItDag class which automatically creates an > iterator which works on the whole dag network and can filter in the geometry > only: > > ... > iterate=OM.MItDag (OM.MItDag.kDepthFirst,OM.MFn.kSurface) > objMObject=OM.MObject() > iterate.reset() > while (not iterate.isDone()): > iterate.getPath(objDagPath) > objMObject=iterate.currentItem() > printVerbose (ve,objDagPath.fullPathName()+" > ("+objMObject.apiTypeStr()+")") > iterate.next() > ... > > Alessandro > > > > On Mon, Jul 6, 2009 at 9:02 PM, Paul Molodowitch <[email protected]>wrote: > >> >> It would seem your intuition about getting the transform nodes was >> right: try running this: >> >> http://pastebin.com/f2d0d95a5 >> >> import maya.OpenMaya as OM >> import maya.cmds as cmds >> >> def printGeo(): >> # creates the selection >> geoMSelectionList = OM.MSelectionList() >> OM.MGlobal.getSelectionListByName("*", geoMSelectionList) >> iterate=OM.MItSelectionList(geoMSelectionList,OM.MFn.kSurface) # >> in my selection iteration I want to filter on the kMesh or >> kNurbsSurface >> >> >> # this is the code to print out the selection list and the api >> type of each filtered object in the selection >> fnDagNode=OM.MFnDagNode() >> objMObject=OM.MObject() >> selStrings =[] >> iterate.reset() >> while (not iterate.isDone()): >> iterate.getDependNode(objMObject) >> fnDagNode.setObject(objMObject) >> iterate.getStrings(selStrings) >> print "sel strings:", selStrings >> print(fnDagNode.fullPathName()+" ("+objMObject.apiTypeStr()+")") >> iterate.next() >> >> cmds.file(new=1, f=1) >> cmds.polySphere() >> cmds.sphere() >> >> printGeo() >> >> Even though it returns the same MObject, the selection strings >> indicate one is grabbed from the transform. >> >> According to the docs, it's intended behavior to search below the >> transform when there's a filter: >> >> "If a filter is specified then the children of DAG selection items >> will be searched if the selection item does not match the filter. For >> example, if filter = MFn::kNurbsCurve and a transform is selected then >> the underlying shape for the transform will be in the iteration if it >> is a nurbs curve." >> >> Seems non-intuitive to me too... >> >> - Paul >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
