thanks for clarifying. do MObjectHandles have a properly implemented __eq__ and __ne__? i've come across some bogus ones on api classes ( MDagPath.__ne__ was one offender, if i remember correctly )
-chad On Aug 18, 2009, at 9:29 PM, Dean Edmonds wrote: > > On Sun, Aug 16, 2009 at 23:45, Chad Dombrova<[email protected]> wrote: >> >> MObjectHandle.hashCode() or pymel.nodetypes.DependNode.__hash__() >> >> keep in mind this unique id is only valid while the scene is open. >> close it and reopen and all the id's will change. however, with some >> clever usage of dictionaries and callbacks i'm sure something more >> persistent could be managed. > > Two MObjectHandles which refer to the same internal object are > guaranteed to return the same hash code, but that code is not > guaranteed to be unique. As the name implies, it is a hash code and > there may be multiple objects which return the same code. > > The purpose of the hashCode() method is to make it possible for > MObjectHandles to be used in Python dictionaries. When an object is > looked up in a dictionary, Python first uses the value returned by the > object's __hash__() method to quickly narrow down the range of > choices, then it steps through each of the objects which have the same > hash code, doing a more in-depth comparison to find the one which > matches the object being looked up. By reimplementing MObjectHandle's > __hash__() method to use hashCode() you can create MObjectHandles > which work as dictionary keys. > > -- > -deane > > > --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
