Yea, it was introduced after Maya 2012. Marco is right though, it is even
faster:
import maya.api.OpenMaya as om2
start = time.time()
search = "nurbsSphereShape*"
sel = om2.MGlobal.getSelectionListByName(search)
depFn = om2.MFnDependencyNode()
for i in xrange(sel.length()):
mObj = sel.getDependNode(i)
depNode = depFn.setObject(mObj)
depNode.findPlug("castsShadows", True).setBool(True)
end = time.time()-start
print ('api2.0 = %s' % end)
# api2.0 = 0.123915910721
On Aug 5, 2012, at 7:31 PM, Matt Estela wrote:
> We're locked to maya2011, API2.0 is a 2012 thing right?
>
>
> On Monday, August 6, 2012, Marco D'Ambros wrote:
> the first question is:
>
> did you use the api 2.0 or the "normal one"?
> the new api suppose to be faster ( almost 3 times more ).
> --------------------------------
> Marco D'Ambros
> phone : (+61) (0) 435809628
> web : www.marcodambros.com
> mail : [email protected]
>
>
>
> On Mon, Aug 6, 2012 at 11:00 AM, Justin Israel <[email protected]> wrote:
> Ah, I figured it out. The 'add' method using a wildcard on a MSelectionList
> is super slow. If you use MGlobal to fill the list for you, it apparently
> does it more efficiently:
>
>
> start = time.time()
>
> search = "nurbsSphereShape*"
> sel = om.MSelectionList()
> om.MGlobal.getSelectionListByName(search, sel)
> iter = om.MItSelectionList(sel)
> depFn = om.MFnDependencyNode()
> mObj = om.MObject()
>
> while not iter.isDone():
> iter.getDependNode( mObj )
> depFn.setObject(mObj)
> depFn.findPlug("castsShadows").setBool(True)
> iter.next()
>
> end = time.time()-start
> print ('api = %s' % end)
> # api = 0.212560892105
>
>
>
> On Aug 5, 2012, at 5:36 PM, Justin Israel wrote:
>
>> This is an interesting approach:
>>
>> start = time.time()
>>
>> cmds.select('nurbsSphereShape*')
>> size = len(cmds.ls(sl=True))
>> cmds.setAttr(".castsShadows", *(1 for _ in xrange(size)))
>>
>> end = time.time()-start
>> print end
>> # 0.243406057358
>>
>> ... Though an extra slow down happens if you have to deselect.
>>
>>
>> On Aug 5, 2012, at 5:17 PM, Matt Estela wrote:
>>
>>> (cc my reply to the group)
>>>
>>>
>>>
>>> On Mon, Aug 6, 2012 at 9:16 AM, Matt Estela <[email protected]> wrote:
>>> Yeah, again it was a contrived example, in production lighters will
>>> definitely be using whatever bizarro wildcards they can muster.
>>>
>>> As you say it appears to be a core limitation of wildcards, will have to
>>> rethink how we let lighters define object selections. In this case maybe we
>>> just can't let lighters use wildcards, instead they'll have to pre-define
>>> it using sets. Or possibly pre-filtering to specific object types, and
>>> running list comprehensions on that.
>>>
>>> Hmm, houdini's smart bundles would come in handy here... (dynamic sets
>>> based on wildcards, they run surprisingly fast)
>>>
>>> Thanks again for the help Justin, you saved me several days worth of
>>> research. :)
>>>
>>>
>>>
>>>
>>> On Mon, Aug 6, 2012 at 5:15 AM, Justin Israel <[email protected]>
>>> wrote:
>>> Ya, in some cases you can't beat the python commands module if you are only
>>> doing a single command. Most of the work is happening behind the scenes in
>>> C++. The wildcard searches just appear to be beasty no matter what.
>>>
>>> But considering you didn't need a wildcard pattern, and instead just want
>>> to say "Apply to all nurbsSurface objects under this root:
>>>
>>> #
>>> # cmds
>>> #
>>> start = time.time()
>>> sel =cmds.listRelatives('|set', ad=True, type="nurbsSurface")
>>> for each in sel:
>>> cmds.setAttr("{0}.castsShadows".format(each), 1)
>>> end = time.time()-start
>>> print ('cmds = %s' % end)
>>> # ** cmds = 0.290652990341 **
>>>
>>> #
>>> # api
>>> #
>>> start = time.time()
>>>
>>> sel = om.MSelectionList()
>>> dagFn = om.MFnDagNode()
>>> mObj = om.MObject()
>>> dagIt = om.MItDag()
>>>
>>> sel.add("|set")
>>> sel.getDependNode(0, mObj)
>>> dagIt.traverseUnderWorld(True)
>>> dagIt.reset(mObj, dagIt.kDepthFirst, om.MFn.kNurbsSurface)
>>>
>>> while not dagIt.isDone():
>>> curr = dagIt.currentItem()
>>> dagFn.setObject(curr)
>>> dagFn.findPlug("castsShadows").setBool(False)
>>> dagIt.next()
>
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe