def _toValidSetOpInput( cls, objects, sets_are_members = False ): """Method creating valid input for the union/intersection or difference methods :note: it may return a temporary set that will delete itself once the wrapper object is being destroyed :param sets_are_members: see `union` :note: set """ if isinstance( objects, (tuple, list) ): # MOBJECTARRAY OF SETS if not objects: # emty list, return empty mobject array return api.MObjectArray( ) if not sets_are_members and isinstance( objects[ 0 ], ObjectSet ): objarray = api.MObjectArray( ) for setNode in objects: objarray.append( setNode._apiobj ) return objarray else: # create selection list from nodes and use a tmpSet sellist = nt.toSelectionList( objects ) return cls._TmpSet( sellist ) # END list handling # still here, handle a single object singleobj = objects if isinstance( singleobj, api.MSelectionList ): # Selection List ? return cls._TmpSet( singleobj ) if not sets_are_members and isinstance( singleobj, ObjectSet ): # Single Object Set ? return singleobj.object() if isinstance( singleobj, cls._TmpSet ): # single set object return singleobj.setobj if isinstance( singleobj, api.MObject ) and singleobj.hasFn( api.MFn.kSet ): # MObject object set ? return singleobj # assume best for MObject arrays - usually we pass it in ourselves if isinstance( singleobj, api.MObjectArray ): return singleobj # Can be Node, MDagPath or plug or MObject ( not set ) return cls._toValidSetOpInput( ( singleobj, ), sets_are_members = sets_are_members ) # will create a tmpset then raise TypeError( "Type InputObjects for set operation ( %r ) was not recognized" % objects )
def _addRemoveMembers( self, members, mode, ignore_failure ): """Add or remove the members to the set :param mode: kRemove or kAdd or kAddForce""" sellist = nt.toSelectionList( members ) # handles 'member is SelectionList' case ! lsellist = sellist.length() if not lsellist: return self # if there is only one member, use our single member function # as it will be faster when checking for partition constraints if lsellist == 1: return self._addRemoveMember( it.iterSelectionList( sellist, asNode = 0 ).next(), api.MObject(), mode, ignore_failure ) # prepare operation mfninst = self._mfncls( self._apiobj ) doitfunc = mfninst.addMembers undoitfunc = mfninst.removeMembers # swap functions if we remove the node if mode == ObjectSet.kRemove: tmp = undoitfunc undoitfunc = doitfunc doitfunc = tmp # IMPORTANT: If one member of sellist is not in the set, the operation # will *silently* ( WTF ??) fail. Hence we have to make sure that # we only even remotely think about trying to remove items which are # actually in the set ! sellist = self.intersection(sellist) # END function swapping op = undo.GenericOperation() op.setDoitCmd( doitfunc, sellist ) op.setUndoitCmd( undoitfunc, sellist ) op.doIt() return self._checkMemberAddResult( sellist, None, mode, ignore_failure, False )
def findAnimation( cls, iter_nodes, asNode=True ): """ :return: list-compatible object containing animation curves attached to the nodes in the given object. :param iter_nodes: MSelection list or list of MObjects or Nodes containing whose animation you would like to retrieve. :param asNode: If True, the animation curves will be wrapped, or MObjects otherwise ( to gain performance )""" selection_list = base.toSelectionList(iter_nodes) anim_plugs = api.MPlugArray() apianim.MAnimUtil.findAnimatedPlugs(selection_list, anim_plugs, False) # it will append to this array ! objs = api.MObjectArray() for anim_plug in anim_plugs: apianim.MAnimUtil.findAnimation(anim_plug, objs) # END for each animated plug if asNode: return map(base.NodeFromObj, objs) else: return objs
def findAnimation(cls, iter_nodes, asNode=True): """ :return: list-compatible object containing animation curves attached to the nodes in the given object. :param iter_nodes: MSelection list or list of MObjects or Nodes containing whose animation you would like to retrieve. :param asNode: If True, the animation curves will be wrapped, or MObjects otherwise ( to gain performance )""" selection_list = base.toSelectionList(iter_nodes) anim_plugs = api.MPlugArray() apianim.MAnimUtil.findAnimatedPlugs(selection_list, anim_plugs, False) # it will append to this array ! objs = api.MObjectArray() for anim_plug in anim_plugs: apianim.MAnimUtil.findAnimation(anim_plug, objs) # END for each animated plug if asNode: return map(base.NodeFromObj, objs) else: return objs
def mfromList(iter_items, **kwargs): """ :return: MSelectionList as initialized from the given iterable of Nodes, MObjects, MDagPaths, MPlugs or strings :param kwargs: passed to `base.toSelectionList`""" return base.toSelectionList(iter_items, **kwargs)
def mfromList( iter_items, **kwargs ): """ :return: MSelectionList as initialized from the given iterable of Nodes, MObjects, MDagPaths, MPlugs or strings :param kwargs: passed to `base.toSelectionList`""" return base.toSelectionList(iter_items, **kwargs)