Esempio n. 1
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)
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_user_interface( self ):
		if cmds.about( batch=1 ):
			return
		
		Scene.open(fixture_path('1still3moving.ma'), force=1)
		
		exp_file = self._set_export_file()
		
		# show UI
		awin = AnimIO_UI().show()
		ectrl = awin.main.exportctrl
		
		# TEST EXPORT 
		# nothing selected in UI - failure
		ectrl.nodeselector.set_uses_selection(False)
		ectrl.nodeselector.set_uses_selection(False)
		self.failUnlessRaises(ValueError, ectrl._on_export, None)
		assert not exp_file.isfile()
		

		# should use selected nodes, but there is no one selected in the scene
		ectrl.nodeselector.set_uses_selection(True)
		ectrl.nodeselector.set_uses_selection(True)
		self.failUnlessRaises(ValueError, ectrl._on_export, None)
		assert not exp_file.isfile()
		
		
		# something with keys is selected
		nt.select('coneAnimated')
		ectrl._on_export(None)
		assert exp_file.isfile()
		cone_anim_file = exp_file
		
		# TODO: reapply it to the same item without animation
		# for simplicity we just
		
		
		# TEST NAMESPACES
		Scene.open(fixture_path('3moving3namespaces.ma'), force=1)
		assert Scene.name() == fixture_path('3moving3namespaces.ma')
		
		# nodeselector should have 4 namespaces now, but no one is selected
		assert len(ectrl.nodeselector.selected_namespaces()) == 0
		
		# but it displays them
		assert ectrl.nodeselector.p_numberOfItems == 4	 # 3 ns + 1 sel nodes
		
		# select namespaces, retrieve them
		all_ns = RootNamespace.children()
		ectrl.nodeselector.select_namespaces(all_ns)
		assert all_ns == ectrl.nodeselector.selected_namespaces()
		assert ectrl.nodeselector.uses_selection()
		
		# export to namespaces
		exp_file = self._set_export_file()
		ectrl._on_export(None)
		assert exp_file.isfile()
		
		
		# TODO: reimport the file with namespaces, test filters and converters
		cmds.fileDialog = self._orig_fileDialog
		cone_anim_file.remove()