Beispiel #1
0
	def test_objectExistance( self ):
		depnode = nt.createNode( "node", "facade" )
		assert nt.objExists( str( depnode ) ) 

		# TEST DUPLICATION
		duplnode = depnode.duplicate( )
		assert duplnode.isValid( ) 

		copy2 = depnode.duplicate( "name2" )
		assert str( copy2 ) == "name2" 
		# NOTE: currently undo is not opetional

		dagnode = nt.createNode( "parent|node", "mesh" )
		assert nt.objExists( str( dagnode ) ) 

		# must clash with dg node ( in maya, dg nodes will block names of dag node leafs ! )
		self.failUnlessRaises( NameError, nt.createNode, "parent|node|node", "mesh", renameOnClash=False )

		# same clash occours if dag node exists first
		dagnode = nt.createNode( "parent|othernode", "transform" )
		self.failUnlessRaises( NameError, nt.createNode, "othernode", "facade", renameOnClash=False )
Beispiel #2
0
    def test_objectExistance(self):
        depnode = nt.createNode("node", "facade")
        assert nt.objExists(str(depnode)) 

        # TEST DUPLICATION
        duplnode = depnode.duplicate()
        assert duplnode.isValid() 

        copy2 = depnode.duplicate("name2")
        assert str(copy2) == "name2" 
        # NOTE: currently undo is not opetional

        dagnode = nt.createNode("parent|node", "mesh")
        assert nt.objExists(str(dagnode)) 

        # must clash with dg node (in maya, dg nodes will block names of dag node leafs !)
        self.failUnlessRaises(NameError, nt.createNode, "parent|node|node", "mesh", renameOnClash=False)

        # same clash occours if dag node exists first
        dagnode = nt.createNode("parent|othernode", "transform")
        self.failUnlessRaises(NameError, nt.createNode, "othernode", "facade", renameOnClash=False)
Beispiel #3
0
	def test_setOperations( self ):
		"""byroniom.maya.nt.sets: unions, intersections, difference, overloaded ops"""
		memberlist = self._getMemberList( )
		s3 = nt.createNode( "anotherObjectSet", "objectSet" )
		s = nt.ObjectSet()
		s.clear()
		s.addMembers( memberlist )

		side = nt.Node( "side" )
		s2 = nt.createNode( "memberSet2", "objectSet" )
		s2.addMember( side )

		# UNION
		########
		# with set
		sellist = s.union( s2 )
		assert sellist.length() == len( memberlist ) + 1 

		# with sellist - will create temp set
		sellist = s.union( s2.members() )
		assert sellist.length() == len( memberlist ) + 1 
		assert not nt.objExists( "set4" ) 		# tmp set may not exist

		# with multiple object sets
		s.union( [ s2, s3 ] )

		list( s.iterUnion( s2 ) )

		# INTERSECTION
		###############
		fewmembers = memberlist[:3]
		s2.addMembers( fewmembers )

		# add 0 members
		s2.addMembers( list() )

		# with set
		sellist = s.intersection( s2 )
		assert sellist.length() == len( fewmembers ) 

		# with sellist
		sellist = s.intersection( fewmembers )
		assert sellist.length() == len( fewmembers ) 

		# with multi sets
		s3.addMembers( fewmembers )
		sellist = s.intersection( [ s2, s3 ] )
		assert sellist.length() == len( fewmembers ) 

		list( s.iterIntersection( s2 ) )

		# DIFFERENCE
		#############
		# with set
		s2.removeMember( side )
		sellist = s.difference( s2 )
		assert s.members().length() - s2.members().length() == sellist.length() 

		# with objects
		sellist = s.difference( list( s2.iterMembers() ) )
		assert s.members().length() - s2.members().length() == sellist.length() 

		# with sellist
		sellist = s.difference( s2.members() )

		# with multiple sets
		s3.clear()
		s3.addMember( nt.Node( "front" ) )
		sellist = s.difference( [ s2, s3 ] )

		assert len( list( s.iterDifference( [ s2, s3 ] ) ) ) == s.difference( [ s2, s3 ] ).length() 
		assert s.members().length() - s2.members().length() - s3.members().length() == sellist.length() 
Beispiel #4
0
    def test_childEditing(self):
        base = nt.createNode("basenode", "transform")
        obase = nt.createNode("otherbasenode", "transform")

        trans = nt.createNode("trans", "transform")
        otrans = nt.createNode("parent|trans", "transform")
        mesh = nt.createNode("meshparent|meshshape", "mesh")
        curve = nt.createNode("nurbsparent|ncurve", "nurbsCurve")
        itemlist = [trans, mesh, curve]

        instlist = list()

        # MULTIPLE ADDS
        ####################
        # Returns the same instance - its what the user wants
        for item in itemlist:
            assert item.instanceCount(0) == 1
            inst = base.addInstancedChild(item)
            assert base.addInstancedChild(item) == inst
            assert item.instanceCount(0) == 2
            assert item != inst and inst.isValid() and item.isValid() 

            instlist.append(inst)

            # UNDO TEST
            # undo basemesh
            cmds.undo()
            assert not inst.isValid() and inst.isAlive() 

            cmds.redo()
            assert inst.isValid() and inst.isAlive()
        # END for each object including undo/redo


        # KEEP PARENT FALSE - USE INSTANCES
        # TODO: this test needs a redo - the original purpose got lost when
        # the addChild method has been changed, additionally it needs to be
        # better documented as this instancing stuff is not easily understood if
        # one just sees the code
        for orig,inst in zip(itemlist, instlist):
            assert orig.object() == inst.object() and orig != inst
            ninst = obase.addChild(inst, keepExistingParent=False)
            
            # # duplicate adds are not problem, but it can't be tested as the inst is already invalid
            # assert obase.addChild(inst, keepExistingParent=False) == ninst
            
            assert not inst.isValid()
            assert ninst.isValid() and ninst.isAlive() 
            assert orig.isValid()           # original may not be influenced by that operation

            # undo / redo
            cmds.undo()
            assert orig.isValid()
            assert not ninst.isValid()
            assert inst.isValid()

            cmds.redo()
            assert not inst.isValid() and orig.isValid() and ninst.isValid()
        # END for each instance
        

        # RENAME ON CLASH = False
        self.failUnlessRaises(RuntimeError, obase.addChild, otrans, renameOnClash = False)

        # RENAME ON CLASH = True
        otransname = str(otrans)
        renamedtrans = obase.addChild(otrans, renameOnClash = True)
        assert renamedtrans.isValid() 
        renamedname = str(renamedtrans)
        assert renamedname != otransname 

        cmds.undo()
        assert nt.objExists(otransname) and not nt.objExists(renamedname) 

        cmds.redo()
Beispiel #5
0
 def test_plugin_handling(self):
     mrp = "Mayatomr"
     pp = 'persistence'
     assert not cmds.pluginInfo(mrp, q=1, loaded=1)
     
     assert not hasattr(nt, 'Transmat')
     cmds.loadPlugin(mrp)
     
     # loading a plugin will add the node types
     assert hasattr(nt, 'Transmat')
     assert nt.typ.nodeTypeTree.has_node('transmat')
     tmat = nt.Transmat()    # mr dep node
     tmat.delete()
     
     dll = nt.MapVizShape()  # mr dag node
     assert isinstance(dll, nt.DagNode)
     dll.delete()
     cmds.flushUndo()    # make sure we get rid of the custom data
     
     
     # custom node types are favored and not overwritten by dummies when 
     # loading
     assert nt.StorageNode is mstorage.StorageNode
     
     # custom node types will remain when unloaded
     cmds.unloadPlugin(pp)
     assert not cmds.pluginInfo(pp, q=1, loaded=1) 
     assert hasattr(nt, 'StorageNode')
     
     # unloading a plugin will remove the nodetypes as well as the hierarchy 
     # entries
     # NOTE: on OSX unloading the plugin beautifully crashes maya, probably
     # a memory exception as MR claims to have had a peak memory of 136 GB
     # As a final goal, this test should be fixed to run here, there 
     # probably is some kind of workaround.
     # http://tracking.byronimo.de/view.php?id=144
     mr_testobj = "contour_composite1"
     if sys.platform != 'darwin':
         cmds.unloadPlugin(mrp, force=1)
         
         assert not hasattr(nt, 'Transmat')
         assert not hasattr(nt, 'MapVizShape')
         assert not nt.typ.nodeTypeTree.has_node('transmat')
         assert not nt.typ.nodeTypeTree.has_node('mapVizShape')
     
 
         # plugins required by a scene trigger the database to update as well
         assert not cmds.pluginInfo(mrp, q=1, loaded=1)
         assert not nt.objExists('transmat1')
         needs_mr_scene = get_maya_file('needsMayatomr.ma')
         mrvmaya.Scene.open(needs_mr_scene, force=True)
         assert hasattr(nt, 'Transmat')
         assert not nt.objExists(mr_testobj), "object shouldn't exist if it works"
         
         # try it during reference and import scenarios
         mrvmaya.Scene.new(force=True)
         cmds.unloadPlugin(mrp, force=0)
         assert not hasattr(nt, 'Transmat')
         
         FileReference.create(needs_mr_scene)
         assert hasattr(nt, 'Transmat'), "Should have triggered the callback"
         assert not nt.objExists(mr_testobj), "object shouldn't exist if it works"
         
         # try import
         mrvmaya.Scene.new(force=True)
         cmds.unloadPlugin(mrp, force=0)
         assert not hasattr(nt, 'Transmat')
         
         
         cmds.file(needs_mr_scene, i=True)
         assert hasattr(nt, 'Transmat'), "Should have triggered callback by import"
         assert not nt.objExists(mr_testobj), "object shouldn't exist if it works"
     # END skip this on osx
     
     assert not nt.objExists(mr_testobj)
     cmds.undoInfo(st=0)
     mod = api.MDGModifier()
     mod.createNode('transmat')
     assert not nt.objExists(mr_testobj), "Shouldn't actually create the object even if undo is off"
     cmds.undoInfo(st=1)
     
     # dynamically added types (which will not trigger a plugin changed event)
     # can be wrapped as well
     customMI = get_maya_file('customshader.mi')
     csn = "testCustomShader"
     csnc = "TestCustomShader"
     mrvmaya.Mel.mrFactory('-load',customMI)
     
     # it doesnt exist, but can be wrapped nontheless, then it exists
     assert not hasattr(nt, csnc)
     cs = nt.Node(cmds.createNode(csn))
     assert hasattr(nt, csnc)
Beispiel #6
0
    def test_wrapDagNode(self):
        mesh = nt.createNode("parent|mesh", "mesh")
        parent = mesh.parent()

        # simple rename
        mesh.rename("fancymesh")


        # simple dupl test
        duplbase = nt.createNode("parent|this|other|duplbase", "mesh")
        transcopy = duplbase.transform().duplicate()
        copy = duplbase.duplicate("parent|this|other|duplcopy")
        assert copy != duplbase 
        assert str(copy) != str(duplbase) 
        assert str(copy) == "|parent|this|other|duplcopy" 

        # TEST ADDITIONAL OPTIONS
        for i in range(1,3):
            ocopy = duplbase.duplicate()
            assert str(ocopy) == str(duplbase) + str(i) 

            ocopy = duplbase.duplicate(newTransform=1)
            assert ocopy.basename() == duplbase.basename() 
            assert str(ocopy.parent()) == str(duplbase.parent()) + str(i + 1) 

            # undo both duplications and redo
            # CRASHES MAYA AFTER REDO
            # and if someone tries to access an object already created
            #cmds.undo()
            #cmds.undo()
            #assert duplbase.isValid() 
            #cmds.redo()
            #cmds.redo()
        # END for each copy


        # simple reparent
        otherparent = nt.createNode("oparent", "transform")
        mesh.reparent(otherparent)

        # REPARENT UNDO TEST
        cmds.undo()
        assert mesh.parent() == parent 
        cmds.redo()
        assert mesh.parent() == otherparent 



        # REPARENT RENAME CLASH
        origmesh = nt.createNode("parent|fancymesh", "mesh")            #  "|parent|fancymesh"
        self.failUnlessRaises(RuntimeError, mesh.reparent, parent , renameOnClash = False)

        # RENAME CLASH DAG NODE
        othermesh = nt.createNode("parent|mesh", "mesh")
        self.failUnlessRaises(RuntimeError, origmesh.rename, "mesh", renameOnClash = False)

        # now it works
        othermesh.rename("mesh", renameOnClash = True)
        assert othermesh.basename() == "mesh" 


        # shape under root
        self.failUnlessRaises(RuntimeError, mesh.reparent, None)

        # REPARENT AGAIN
        # should just work as the endresult is the same
        mesh.reparent(otherparent)  # it will also trigger a new undo event, so undo will react as it should
        mesh.reparent(otherparent)  #  "|otherparent|fancymesh"

        # REPARENT UNDER SELF
        self.failUnlessRaises(RuntimeError, mesh.reparent, mesh)

        # reparent transform to world
        wtrans = nt.createNode("parent2|worldtrans", "transform")
        parent = nt.Node("parent2")
        oparent = nt.createNode("oparent2", "transform")
        wtrans = wtrans.reparent(None)

        wtransnewparent = wtrans.setParent(parent)
        assert wtrans == wtransnewparent
        assert wtransnewparent.instanceCount(1) == 1 
        wtransnewparent.addParent(oparent)
        assert wtransnewparent.instanceCount(1) == 2 
        wtransnewparent.removeParent(oparent)
        assert wtrans.instanceCount(1) == 1 



        # OBJECT NAVIGATION
        #######################
        # TODO: navigate the object properly




        # DUPLICATE (Dag only)
        #########################
        newmesh = mesh.duplicate("|duplparent|duplmesh")
        assert str(newmesh) == "|duplparent|duplmesh" 
        self.failUnlessRaises(RuntimeError, mesh.duplicate, "|duplparent2|doesntexistns:duplmesh",
                                autocreateNamespace = False)
        assert newmesh != mesh 
        instbase = nt.createNode("|duplparent2|newnamespace:instmesh", "transform")
        meshinst = instbase.addInstancedChild(mesh)
        meshinstname = str(meshinst)

        # UNDO DUPLICATE
        #################
        cmds.undo()

        # this object will end up pointing to the same object , as it came from, use string test
        assert not nt.objExists(meshinstname) 
        cmds.redo()
        cmds.undo()
        cmds.redo()
        assert meshinst != mesh 
        assert meshinst.isAlive() and meshinst.isValid() and str(meshinst) == meshinstname 

        # Duplicate TRANSFORM (just a name given)
        # dag paths should be different although object is the same
        mesh = nt.createNode("|parent|mybeautifuluniquemeshname", "mesh")
        meshassert = nt.createNode("|parent|mesh", "mesh")
        meshself = nt.Node("|parent|mybeautifuluniquemeshname")
        assert mesh == meshself 

        # connect it, to track the instance by connection
        persp = nt.Node("persp")
        perspplug = persp.t.mchildByName('tx')
        triplug = meshself.maxTriangles
        perspplug.mconnectTo(triplug)

        # target does exist
        # this is blocking the target instance name with an incorrect type
        nt.createNode("parent|this|mybeautifuluniquemeshname", "transform")
        self.failUnlessRaises(RuntimeError, mesh.duplicate, "|parent|this")

        # if the path is too short ...
        self.failUnlessRaises(NameError, mesh.duplicate, str(mesh.transform()))
        self.failUnlessRaises(NameError, mesh.parent().duplicate, '|')


        meshinstname = mesh.transform().fullChildName("newns:meshinst")
        assert isinstance(meshinst, nt.Mesh) 
Beispiel #7
0
    def test_createNodes(self):
        names = ["hello","bla|world","this|world|here","that|this|world|here"]
        nsnames = ["a:hello","blab|b:world","c:this|b:world","d:that|c:this|b:world|a:b:c:d:here"]
        types = ["facade", "nurbsCurve", "nurbsSurface", "subdiv"]

        # SIMPLE CREATION: Paths + nested namespaces
        for i in range(len(names)):
            ntype = types[i]
            newnode = nt.createNode(names[i], ntype)
            assert isinstance(newnode, getattr(nt, capitalize(ntype))) 
            assert newnode.isValid() and newnode.isAlive() 

            # test undo
            cmds.undo()
            assert not newnode.isValid() and newnode.isAlive() 
            cmds.redo()
            assert newnode.isValid() and newnode.isAlive() 

            newnsnode = nt.createNode(nsnames[i], ntype)
            assert isinstance(newnsnode, getattr(nt, capitalize(ntype))) 
            assert newnsnode.isValid() and newnsnode.isAlive() 

            # test undo
            cmds.undo()
            assert not newnsnode.isValid() and newnsnode.isAlive() 
            cmds.redo()
            assert newnsnode.isValid() and newnsnode.isAlive() 
        # END for each created object

        # EMPTY NAME and ROOT
        self.failUnlessRaises(RuntimeError, nt.createNode, '|', "facade")
        self.failUnlessRaises(RuntimeError, nt.createNode, '', "facade")


        # CHECK DIFFERENT ROOT TYPES
        depnode = nt.createNode("blablub", "facade")
        self.failUnlessRaises(NameError, nt.createNode, "|blablub|:this", "transform", renameOnClash = False)

        # DIFFERENT TYPES AT END OF PATH
        nt.createNode("this|mesh", "mesh")
        self.failUnlessRaises(NameError, nt.createNode, "this|mesh", "nurbsSurface", forceNewLeaf = False)

        # renameOnClash  - it fails if the dep node exists first
        nt.createNode("node", "facade")
        self.failUnlessRaises(NameError, nt.createNode, "this|that|node", "mesh", renameOnClash = False)

        # obj exists should match dg nodes with dag node like path (as they occupy the same
        # namespace after all
        assert nt.objExists("|node") 

        # it also clashes if the dg node is created after a  dag node with the same name
        nt.createNode("that|nodename", "mesh")
        self.failUnlessRaises(NameError, nt.createNode, "nodename", "facade", renameOnClash = False)


        # it should be fine to have the same name in several dag levels though !
        newmesh = nt.createNode("parent|nodename", "transform")
        newmesh1 = nt.createNode("parent|nodename|nodename", "mesh")
        newmesh2 = nt.createNode("otherparent|nodename|nodename", "mesh")
        assert newmesh != newmesh1 
        assert newmesh1 != newmesh2 

        # FORCE NEW
        ##############
        oset = nt.createNode("objset", "objectSet", forceNewLeaf = False)
        newoset = nt.createNode("objset", "objectSet", forceNewLeaf = True)
        assert oset != newoset 

        # would expect same set to be returned
        sameoset = nt.createNode("objset", "objectSet", forceNewLeaf = False)
        assert sameoset == oset 

        # force new and dag paths
        newmesh3 = nt.createNode("otherparent|nodename|nodename", "mesh", forceNewLeaf = True)
        assert newmesh3 != newmesh2 
Beispiel #8
0
	def test_childEditing( self ):
		base = nt.createNode( "basenode", "transform" )
		obase = nt.createNode( "otherbasenode", "transform" )

		trans = nt.createNode( "trans", "transform" )
		otrans = nt.createNode( "parent|trans", "transform" )
		mesh = nt.createNode( "meshparent|meshshape", "mesh" )
		curve = nt.createNode( "nurbsparent|ncurve", "nurbsCurve" )
		itemlist = [ trans, mesh, curve ]

		instlist = []

		# MULTIPLE ADDS
		####################
		# Returns the same instance - its what the user wants
		for item in itemlist:
			baseiteminst = base.addInstancedChild( item )
			base.addInstancedChild( item )
			assert item != baseiteminst and baseiteminst.isValid() and item.isValid() 

			instlist.append( baseiteminst )

			# UNDO TEST
			# undo basemesh
			cmds.undo()
			cmds.undo()
			assert not baseiteminst.isValid() and baseiteminst.isAlive() 

			cmds.redo()
			assert baseiteminst.isValid() and baseiteminst.isAlive() 
		# END for each object including undo/redo


		# KEEP PARENT FALSE - USE INSTANCES
		# TODO: this test needs a redo - the original purpose got lost when
		# the addChild method has been changed, additionally it needs to be
		# better documented as this instancing stuff is not easily understood if
		# one just sees the code
		for orig,inst in zip( itemlist, instlist ):
			inst = obase.addChild( inst, keepExistingParent=False )
			obase.addChild( inst, keepExistingParent=False )	 # duplicate adds are not problem

			assert inst.isValid() and inst.isAlive() 
			assert orig.isValid() 			# original may not be influenced by that operation

			# undo / redo
			cmds.undo()
			#cmds.undo()	# just one undo counts
			assert inst.isValid() and orig.isValid() 

			cmds.redo()
		# END for each instance

		# RENAME ON CLASH = False
		self.failUnlessRaises( RuntimeError, obase.addChild, otrans, renameOnClash = False )

		# RENAME ON CLASH = True
		otransname = str( otrans )
		renamedtrans = obase.addChild( otrans, renameOnClash = True )
		assert renamedtrans.isValid() 
		renamedname = str( renamedtrans )
		assert renamedname != otransname 

		cmds.undo( )
		assert nt.objExists( otransname ) and not nt.objExists( renamedname ) 

		cmds.redo()
Beispiel #9
0
	def test_wrapDagNode( self ):
		mesh = nt.createNode( "parent|mesh", "mesh" )
		parent = mesh.parent( )

		# simple rename
		mesh.rename( "fancymesh" )


		# simple dupl test
		duplbase = nt.createNode( "parent|this|other|duplbase", "mesh" )
		transcopy = duplbase.transform( ).duplicate()
		copy = duplbase.duplicate( "parent|this|other|duplcopy" )
		assert copy != duplbase 
		assert str( copy ) != str( duplbase ) 
		assert str( copy ) == "|parent|this|other|duplcopy" 

		# TEST ADDITIONAL OPTIONS
		for i in range( 1,3 ):
			ocopy = duplbase.duplicate(  )
			assert str( ocopy ) == str( duplbase ) + str( i ) 

			ocopy = duplbase.duplicate( newTransform=1 )
			assert ocopy.basename( ) == duplbase.basename() 
			assert str( ocopy.parent() ) == str( duplbase.parent() ) + str( i + 1 ) 

			# undo both duplications and redo
			# CRASHES MAYA AFTER REDO
			# and if someone tries to access an object already created
			#cmds.undo()
			#cmds.undo()
			#assert duplbase.isValid() 
			#cmds.redo()
			#cmds.redo()
		# END for each copy


		# simple reparent
		otherparent = nt.createNode( "oparent", "transform" )
		mesh.reparent( otherparent )

		# REPARENT UNDO TEST
		cmds.undo()
		assert mesh.parent() == parent 
		cmds.redo()
		assert mesh.parent() == otherparent 



		# REPARENT RENAME CLASH
		origmesh = nt.createNode( "parent|fancymesh", "mesh" )			#  "|parent|fancymesh"
		self.failUnlessRaises( RuntimeError, mesh.reparent, parent , renameOnClash = False )

		# RENAME CLASH DAG NODE
		othermesh = nt.createNode( "parent|mesh", "mesh" )
		self.failUnlessRaises( RuntimeError, origmesh.rename, "mesh", renameOnClash = False )

		# now it works
		othermesh.rename( "mesh", renameOnClash = True )
		assert othermesh.basename( ) == "mesh" 


		# shape under root
		self.failUnlessRaises( RuntimeError, mesh.reparent, None )

		# REPARENT AGAIN
		# should just work as the endresult is the same
		mesh.reparent( otherparent )	# it will also trigger a new undo event, so undo will react as it should
		mesh.reparent( otherparent )	#  "|otherparent|fancymesh"

		# REPARENT UNDER SELF
		self.failUnlessRaises( RuntimeError, mesh.reparent, mesh )

		# reparent transform to world
		wtrans = nt.createNode( "parent2|worldtrans", "transform" )
		parent = nt.Node( "parent2" )
		oparent = nt.createNode( "oparent2", "transform" )
		wtrans = wtrans.reparent( None )

		wtransnewparent = wtrans.setParent( parent )
		assert wtrans == wtransnewparent
		assert wtransnewparent.instanceCount( 1 ) == 1 
		wtransnewparent.addParent( oparent )
		assert wtransnewparent.instanceCount( 1 ) == 2 
		wtransnewparent.removeParent( oparent )
		assert wtrans.instanceCount( 1 ) == 1 



		# OBJECT NAVIGATION
		#######################
		# TODO: navigate the object properly




		# DUPLICATE ( Dag only )
		#########################
		newmesh = mesh.duplicate( "|duplparent|duplmesh" )
		assert str( newmesh ) == "|duplparent|duplmesh" 
		self.failUnlessRaises( RuntimeError, mesh.duplicate, "|duplparent2|doesntexistns:duplmesh",
							  	autocreateNamespace = False )
		assert newmesh != mesh 
		instbase = nt.createNode( "|duplparent2|newnamespace:instmesh", "transform" )
		meshinst = instbase.addInstancedChild( mesh )
		meshinstname = str( meshinst )

		# UNDO DUPLICATE
		#################
		cmds.undo()

		# this object will end up pointing to the same object , as it came from, use string test
		assert not nt.objExists( meshinstname ) 
		cmds.redo()
		cmds.undo()
		cmds.redo()
		assert meshinst != mesh 
		assert meshinst.isAlive() and meshinst.isValid() and str( meshinst ) == meshinstname 

		# Duplicate TRANSFORM ( just a name given )
		# dag paths should be different although object is the same
		mesh = nt.createNode( "|parent|mybeautifuluniquemeshname", "mesh" )
		meshassert = nt.createNode( "|parent|mesh", "mesh" )
		meshself = nt.Node( "|parent|mybeautifuluniquemeshname" )
		assert mesh == meshself 

		# connect it, to track the instance by connection
		persp = nt.Node( "persp" )
		perspplug = persp.t.mchildByName('tx')
		triplug = meshself.maxTriangles
		perspplug.mconnectTo(triplug)

		# target does exist
		# this is blocking the target instance name with an incorrect type
		nt.createNode( "parent|this|mybeautifuluniquemeshname", "transform" )
		self.failUnlessRaises( RuntimeError, mesh.duplicate, "|parent|this" )

		# if the path is too short ...
		self.failUnlessRaises( NameError, mesh.duplicate, str( mesh.transform() ) )
		self.failUnlessRaises( NameError, mesh.parent().duplicate, '|' )


		meshinstname = mesh.transform().fullChildName( "newns:meshinst" )
		assert isinstance( meshinst, nt.Mesh ) 
Beispiel #10
0
	def test_createNodes( self ):
		names = ["hello","bla|world","this|world|here","that|this|world|here" ]
		nsnames = ["a:hello","blab|b:world","c:this|b:world","d:that|c:this|b:world|a:b:c:d:here"]
		types = [ "facade", "nurbsCurve", "nurbsSurface", "subdiv" ]

		# SIMPLE CREATION: Paths + nested namespaces
		for i in range( len( names ) ):
			ntype = types[i]
			newnode = nt.createNode( names[i], ntype )
			assert isinstance( newnode, getattr( nt, capitalize( ntype ) ) ) 
			assert newnode.isValid() and newnode.isAlive() 

			# test undo
			cmds.undo()
			assert not newnode.isValid() and newnode.isAlive() 
			cmds.redo()
			assert newnode.isValid() and newnode.isAlive() 

			newnsnode = nt.createNode( nsnames[i], ntype )
			assert isinstance( newnsnode, getattr( nt, capitalize( ntype ) ) ) 
			assert newnsnode.isValid() and newnsnode.isAlive() 

			# test undo
			cmds.undo()
			assert not newnsnode.isValid() and newnsnode.isAlive() 
			cmds.redo()
			assert newnsnode.isValid() and newnsnode.isAlive() 
		# END for each created object

		# EMPTY NAME and ROOT
		self.failUnlessRaises( RuntimeError, nt.createNode, '|', "facade" )
		self.failUnlessRaises( RuntimeError, nt.createNode, '', "facade" )


		# CHECK DIFFERENT ROOT TYPES
		depnode = nt.createNode( "blablub", "facade" )
		self.failUnlessRaises( NameError, nt.createNode, "|blablub|:this", "transform", renameOnClash = False )

		# DIFFERENT TYPES AT END OF PATH
		nt.createNode( "this|mesh", "mesh" )
		self.failUnlessRaises( NameError, nt.createNode, "this|mesh", "nurbsSurface", forceNewLeaf = False )

		# renameOnClash  - it fails if the dep node exists first
		nt.createNode( "node", "facade" )
		self.failUnlessRaises( NameError, nt.createNode, "this|that|node", "mesh", renameOnClash = False )

		# obj exists should match dg nodes with dag node like path ( as they occupy the same
		# namespace after all
		assert nt.objExists( "|node" ) 

		# it also clashes if the dg node is created after a  dag node with the same name
		nt.createNode( "that|nodename", "mesh" )
		self.failUnlessRaises( NameError, nt.createNode, "nodename", "facade", renameOnClash = False )


		# it should be fine to have the same name in several dag levels though !
		newmesh = nt.createNode( "parent|nodename", "transform" )
		newmesh1 = nt.createNode( "parent|nodename|nodename", "mesh" )
		newmesh2 = nt.createNode( "otherparent|nodename|nodename", "mesh" )
		assert newmesh != newmesh1 
		assert newmesh1 != newmesh2 

		# FORCE NEW
		##############
		oset = nt.createNode( "objset", "objectSet", forceNewLeaf = False )
		newoset = nt.createNode( "objset", "objectSet", forceNewLeaf = True )
		assert oset != newoset 

		# would expect same set to be returned
		sameoset = nt.createNode( "objset", "objectSet", forceNewLeaf = False )
		assert sameoset == oset 

		# force new and dag paths
		newmesh3 = nt.createNode( "otherparent|nodename|nodename", "mesh", forceNewLeaf = True )
		assert newmesh3 != newmesh2 
Beispiel #11
0
    def test_setOperations(self):
        """byroniom.maya.nt.sets: unions, intersections, difference, overloaded ops"""
        memberlist = self._getMemberList()
        s3 = nt.createNode("anotherObjectSet", "objectSet")
        s = nt.ObjectSet()
        s.clear()
        s.addMembers(memberlist)

        side = nt.Node("side")
        s2 = nt.createNode("memberSet2", "objectSet")
        s2.addMember(side)

        # UNION
        ########
        # with set
        sellist = s.union(s2)
        assert sellist.length() == len(memberlist) + 1

        # with sellist - will create temp set
        sellist = s.union(s2.members())
        assert sellist.length() == len(memberlist) + 1
        assert not nt.objExists("set4")  # tmp set may not exist

        # with multiple object sets
        s.union([s2, s3])

        list(s.iterUnion(s2))

        # INTERSECTION
        ###############
        fewmembers = memberlist[:3]
        s2.addMembers(fewmembers)

        # add 0 members
        s2.addMembers(list())

        # with set
        sellist = s.intersection(s2)
        assert sellist.length() == len(fewmembers)

        # with sellist
        sellist = s.intersection(fewmembers)
        assert sellist.length() == len(fewmembers)

        # with multi sets
        s3.addMembers(fewmembers)
        sellist = s.intersection([s2, s3])
        assert sellist.length() == len(fewmembers)

        list(s.iterIntersection(s2))

        # DIFFERENCE
        #############
        # with set
        s2.removeMember(side)
        sellist = s.difference(s2)
        assert s.members().length() - s2.members().length() == sellist.length()

        # with objects
        sellist = s.difference(list(s2.iterMembers()))
        assert s.members().length() - s2.members().length() == sellist.length()

        # with sellist
        sellist = s.difference(s2.members())

        # with multiple sets
        s3.clear()
        s3.addMember(nt.Node("front"))
        sellist = s.difference([s2, s3])

        assert len(list(s.iterDifference([s2,
                                          s3]))) == s.difference([s2, s3
                                                                  ]).length()
        assert s.members().length() - s2.members().length() - s3.members(
        ).length() == sellist.length()