Esempio n. 1
0
	def iter_nodes(self, *args, **kwargs):
		"""
		:return: iterator yielding all selected nodes ( if set by the user )
			as well as all nodes in all selected namespaces
		:param *args: passed to ``Namespace.iterNodes``
		:param **kwargs: passed to ``Namespace.iterNodes``
		:note: *args and **kwargs are passed to ``iterSelectionList`` as good 
		as applicable"""
		iterators = list()
		
		# HANDLE SELECTIONs
		if self.uses_selection():
			# configure the selection list iterator as good as we can
			iterkwargs = dict()
			if args:
				iterkwargs['filterType'] = args[0]
			# END use type filter
			iterkwargs['asNode'] = kwargs.get('asNode', True)
			iterkwargs['handlePlugs'] = False
			
			iterators.append(nt.activeSelectionList().mtoIter(**iterkwargs))
		# END handle selected nodes
		
		# HANDLE NAMESPACES
		for ns in self.selected_namespaces():
			iterators.append(ns.iterNodes(*args, **kwargs))
		# END for each namespace
		
		return chain(*iterators)
Esempio n. 2
0
    def test_convenienceFunctions(self):
        # SELECTION
        ############
        nt.select("persp")
        persp = nt.selection()[0]
        assert persp == nt.Node("persp") 

        # clear selection
        nt.select()
        assert not nt.selection() 
        
        # undo/redo
        cmds.undo()
        assert len(nt.selection()) == 1
        cmds.redo()
        assert len(nt.selection()) == 0

        # select object and selection list
        nt.select(persp)
        assert len(nt.selection()) == 1 
        nt.select(nt.toSelectionList(nt.selection()))
        assert len(nt.selection()) == 1 

        # select mixed
        nt.select(persp, "front")
        assert len(nt.selection()) == 2 


        # GET BY NAME
        ###############
        persp = nt.findByName("pers*")[0]
        assert persp == nt.Node("persp") 
        
        # filter selection
        ##################
        nt.select("persp", "perspShape")
        assert len(nt.selection(api.MFn.kCamera)) == 1
        assert len(list(nt.iterSelection(api.MFn.kCamera))) == 1
        
        sl = nt.activeSelectionList()
        assert len(sl) and isinstance(sl, api.MSelectionList)
Esempio n. 3
0
	def test_convenienceFunctions( self ):
		# SELECTION
		############
		nt.select( "persp" )
		persp = nt.selection()[0]
		assert persp == nt.Node( "persp" ) 

		# clear selection
		nt.select( )
		assert not nt.selection() 
		
		# undo/redo
		cmds.undo()
		assert len(nt.selection()) == 1
		cmds.redo()
		assert len(nt.selection()) == 0

		# select object and selection list
		nt.select( persp )
		assert len( nt.selection( ) ) == 1 
		nt.select( nt.toSelectionList( nt.selection( ) ) )
		assert len( nt.selection( ) ) == 1 

		# select mixed
		nt.select( persp, "front" )
		assert len( nt.selection( ) ) == 2 


		# GET BY NAME
		###############
		persp = nt.findByName( "pers*" )[0]
		assert persp == nt.Node( "persp" ) 
		
		# filter selection
		##################
		nt.select("persp", "perspShape")
		assert len(nt.selection(api.MFn.kCamera)) == 1
		assert len(list(nt.iterSelection(api.MFn.kCamera))) == 1
		
		sl = nt.activeSelectionList()
		assert len(sl) and isinstance(sl, api.MSelectionList)
Esempio n. 4
0
	def test_export_import( self ):
		def iter_dag():
			return nt.iterDgNodes(nt.api.MFn.kDagNode, asNode=0)
			
		ah = AnimationHandle.create()
		ah.set_animation(iter_dag())
		
		# test iter_animation
		managed = len(list(ah.iter_animation(asNode=0)))
		assert managed == len(ah.affectedBy)
		
		# test iter_animtion return types
		assert isinstance(ah.iter_animation().next(), nt.Node)
		assert isinstance(ah.iter_animation(asNode=0).next(), nt.api.MObject) 
		
		# selection is maintained across exports
		slist = nt.toSelectionList(iter_dag())
		nt.select(slist)                           
		
		## EXPORT ##
		filename = ospath.join(tempfile.gettempdir(), "test_export2.ani.ma")
		assert filename == ah.to_file(filename, force=True, type="mayaAscii")
		
		# check if testselection is still alive
		assert len(slist)==len(nt.activeSelectionList())
		
		# AnimationHandle deletes correctly when not referenced
		ahname = ah.name()
		ah.delete()
		assert not ah.isValid()
		
		## IMPORT ##
		# try different namespaces - it should work no matter which namespace
		# is current
		namespaces=(":", "not:in:rootns", "not")
		# dummyAnimationHandle for iteration tests
		dummy=AnimationHandle()
		for namespace in namespaces:
			sns = Namespace.create(namespace)
			sns.setCurrent()
			
			# check return values of from_file and get AnimationHandle
			ahref, ahit = AnimationHandle.from_file(filename)
			assert isinstance(ahref, FileReference)
			
			loaded_ah = ahit.next()
			assert isinstance(loaded_ah, AnimationHandle)
			
			# expecting only one AnimationHandle from iterator (no dummyAnimationHandle)
			# which is in our scene already
			assert len(list(ahit)) == 0
			
			# check if AnimationHandle is the one we saved before
			loaded_ah_ns = loaded_ah.namespace()
			assert loaded_ah_ns + ahname == Namespace.rootpath + loaded_ah.name()
			
			# check if AnimationHandle is from file we wanted
			assert ospath.realpath(filename) == ospath.realpath(loaded_ah.referenceFile())
			
			# stored and loaded managed animCurves are in sync
			assert managed == len(loaded_ah.affectedBy) 
			
			# AnimationHandle deletes correctly when referenced
			loaded_ah.delete()
			assert not loaded_ah.isValid()
		# END test different namespaces
		
		os.remove(filename)