def test_getMayaPathFromUsdPrim_success(self): """Maya scenes can contain multiple proxies. Query each proxy and test they return the correct Maya nodes.""" # These are dynamic prims, so select them to bring into Maya cmds.select(clear=True) cmds.AL_usdmaya_ProxyShapeSelect(self._stageA.proxyName, replace=True, primPath=str( self._stageA.prim.GetPath())) cmds.AL_usdmaya_ProxyShapeSelect(self._stageB.proxyName, append=True, primPath=str( self._stageB.prim.GetPath())) # Created Maya node names will match the originals self.assertTrue(cmds.objExists(self._stageA.poly)) self.assertTrue(cmds.objExists(self._stageB.poly)) # Fetch the Maya node paths that represent each stage's prims resultA = self._stageA.proxy.getMayaPathFromUsdPrim(self._stageA.prim) resultB = self._stageB.proxy.getMayaPathFromUsdPrim(self._stageB.prim) # Expand to long names expectedA = cmds.ls(self._stageA.poly, long=True)[0] expectedB = cmds.ls(self._stageB.poly, long=True)[0] # The paths should match! self.assertEqual(resultA, expectedA) self.assertEqual(resultB, expectedB)
def test_getUsdPrimFromMayaPath_success(self): """Find prim from Maya dag path successfully.""" # Select prim, Maya node(s) created, query path cmds.AL_usdmaya_ProxyShapeSelect(proxy=self._proxyName, primPath="/{}".format(self._sphere)) prim = AL.usdmaya.ProxyShape.getUsdPrimFromMayaPath(self._sphere) self.assertTrue(prim.IsValid())
def test_getMayaPathFromUsdPrim_reopenStaticImport(self): """Saving and reopening a Maya scene with static translated prims should work.""" cmds.AL_usdmaya_ProxyShapeImportPrimPathAsMaya(self._stageA.proxyName, primPath=str(self._stageA.prim.GetPath())) # Save _file = tempfile.NamedTemporaryFile(delete=False, suffix=".ma") with _file: cmds.file(rename=_file.name) cmds.file(save=True, force=True) _file.close() # Re-open cmds.file(_file.name, open=True, force=True) # Refresh data, stage wrapper is out of date _stageC = self.MayaUsdTestData() _stageC.poly = self._stageA.poly _stageC.proxyName = self._stageA.proxyName _stageC.proxy = AL.usdmaya.ProxyShape.getByName(_stageC.proxyName) _stageC.stage = _stageC.proxy.getUsdStage() _stageC.prim = _stageC.stage.GetPrimAtPath("/{}".format(_stageC.poly)) # Test cmds.AL_usdmaya_ProxyShapeSelect(_stageC.proxyName, replace=True, primPath=str(_stageC.prim.GetPath())) self.assertTrue(cmds.objExists(_stageC.poly)) result = _stageC.proxy.getMayaPathFromUsdPrim(_stageC.prim) expected = cmds.ls(_stageC.poly, long=True)[0] self.assertEqual(result, expected) # Cleanup os.remove(_file.name)
def test_getUsdPrimFromMayaPath_duplicateNames(self): """Test short name queries return an invalid prim if duplicates exist in the Maya scene.""" # Create a transform with the same name as sphere cmds.createNode("transform", name=self._sphere) # Select prim, Maya node(s) created cmds.AL_usdmaya_ProxyShapeSelect(proxy=self._proxyName, primPath="/{}".format(self._sphere)) # Two nodes exist in Maya named "sphere", short name queries return with invalid prim _sphereShortName = self._sphere prim = AL.usdmaya.ProxyShape.getUsdPrimFromMayaPath(_sphereShortName) self.assertFalse(prim.IsValid()) # Query long name? Success! _sphereLongName = cmds.ls(self._sphere, type="AL_usdmaya_Transform")[0] prim = AL.usdmaya.ProxyShape.getUsdPrimFromMayaPath(_sphereLongName) self.assertTrue(prim.IsValid())