From 11bb63d5a5d50186406e9c6754839a20299325b6 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 09:57:15 -0500 Subject: [PATCH 1/6] Adding two autotests for loading/saving of USD stage as relative to Maya scene file --- test/lib/testMayaUsdCreateStageCommands.py | 16 ++++++++++++++++ test/lib/testMayaUsdLayerEditorCommands.py | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/test/lib/testMayaUsdCreateStageCommands.py b/test/lib/testMayaUsdCreateStageCommands.py index 901a207aa5..cc90ed4183 100644 --- a/test/lib/testMayaUsdCreateStageCommands.py +++ b/test/lib/testMayaUsdCreateStageCommands.py @@ -17,6 +17,7 @@ # import os +import mayaUtils import platform import unittest @@ -53,6 +54,10 @@ def testCreateStageWithNewLayer(self): self.assertTrue(cmds.isConnected('time1.outTime', shapeNode+'.time')) def testCreateStageFromFile(self): + # Open top_layer.ma and make sure to have USD stage paths as absolute + mayaUtils.openTopLayerScene() + cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0)) + # We cannot directly call the 'mayaUsdCreateStageFromFile' # as it opens a file dialog to choose the scene. So instead # we can call what it does once the file is choose. @@ -72,3 +77,14 @@ def testCreateStageFromFile(self): # Verify that the shape node is connected to time. self.assertTrue(cmds.isConnected('time1.outTime', shapeNode+'.time')) + + # Now switch to having USD stage paths as relative to Maya scene file + cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 1)) + + # Create the same stage and verify that now it's open as relative + shapeNodeRel = mel.eval('mayaUsd_createStageFromFilePath(\"'+ballFilePath+'\")') + filePathAttrRel = cmds.getAttr(shapeNodeRel+'.filePath') + self.assertTrue(self.samefile(filePathAttrRel, 'top_layer.usda')) + + # Restore mayaUsd_MakePathRelativeToSceneFile + cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0)) \ No newline at end of file diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index b1317d1847..8a56682d5e 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -18,10 +18,12 @@ import unittest import tempfile +import testUtils from os import path from maya import cmds, mel import mayaUsd_createStageWithNewLayer import mayaUsd +import mayaUtils from pxr import Sdf, Usd CLEAR = "-clear" @@ -557,3 +559,21 @@ def addFileBakedLayerByPath(parentLayer): testMuteLayerImpl(addAnonymousLayer) testMuteLayerImpl(addFileBakedLayer) testMuteLayerImpl(addFileBakedLayerByPath) + + def testPathRelativeToMayaSceneFile(self): + # Function mayaUsdLib.Util.getPathRelativeToMayaSceneFile is used during + # USD root layer saving/loading, and since we cannot test the full workflow + # as it opens a file dialog and requires user input, we make sure to test + # the function itself here. + + ballFilePath = path.normpath(testUtils.getTestScene('ballset', 'StandaloneScene', 'top_layer.usda')).replace('\\', '/') + + # Without Maya scene file, the absolute path is returned + cmds.file(newFile=True, force=True) + filePathAbs = mayaUsd.lib.Util.getPathRelativeToMayaSceneFile(ballFilePath) + self.assertEqual(filePathAbs, ballFilePath) + + # With Maya scene file, the relative path is returned + mayaUtils.openTopLayerScene() + filePathRel = mayaUsd.lib.Util.getPathRelativeToMayaSceneFile(ballFilePath) + self.assertEqual(filePathRel, 'top_layer.usda') From 08dfa89baecca7e55a32e343924a2e47bb3442d7 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 11:02:38 -0500 Subject: [PATCH 2/6] Trying to fix preflight build for older Mayas --- test/lib/testMayaUsdCreateStageCommands.py | 4 ++-- test/lib/testMayaUsdLayerEditorCommands.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/testMayaUsdCreateStageCommands.py b/test/lib/testMayaUsdCreateStageCommands.py index cc90ed4183..bf7a95d9ac 100644 --- a/test/lib/testMayaUsdCreateStageCommands.py +++ b/test/lib/testMayaUsdCreateStageCommands.py @@ -17,7 +17,7 @@ # import os -import mayaUtils +from mayaUtils import openTopLayerScene import platform import unittest @@ -55,7 +55,7 @@ def testCreateStageWithNewLayer(self): def testCreateStageFromFile(self): # Open top_layer.ma and make sure to have USD stage paths as absolute - mayaUtils.openTopLayerScene() + openTopLayerScene() cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0)) # We cannot directly call the 'mayaUsdCreateStageFromFile' diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index 8a56682d5e..0e56af80d5 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -23,7 +23,7 @@ from maya import cmds, mel import mayaUsd_createStageWithNewLayer import mayaUsd -import mayaUtils +from mayaUtils import openTopLayerScene from pxr import Sdf, Usd CLEAR = "-clear" @@ -574,6 +574,6 @@ def testPathRelativeToMayaSceneFile(self): self.assertEqual(filePathAbs, ballFilePath) # With Maya scene file, the relative path is returned - mayaUtils.openTopLayerScene() + openTopLayerScene() filePathRel = mayaUsd.lib.Util.getPathRelativeToMayaSceneFile(ballFilePath) self.assertEqual(filePathRel, 'top_layer.usda') From 95c2d88f27c37769ece17f48119fbf6debb59921 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 11:54:35 -0500 Subject: [PATCH 3/6] One more fix for preflight --- test/lib/testMayaUsdCreateStageCommands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/testMayaUsdCreateStageCommands.py b/test/lib/testMayaUsdCreateStageCommands.py index bf7a95d9ac..2b49c3c55d 100644 --- a/test/lib/testMayaUsdCreateStageCommands.py +++ b/test/lib/testMayaUsdCreateStageCommands.py @@ -84,7 +84,7 @@ def testCreateStageFromFile(self): # Create the same stage and verify that now it's open as relative shapeNodeRel = mel.eval('mayaUsd_createStageFromFilePath(\"'+ballFilePath+'\")') filePathAttrRel = cmds.getAttr(shapeNodeRel+'.filePath') - self.assertTrue(self.samefile(filePathAttrRel, 'top_layer.usda')) + self.assertEqual(filePathAttrRel, 'top_layer.usda') # Restore mayaUsd_MakePathRelativeToSceneFile cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0)) \ No newline at end of file From e043af662df766d9043908a7407bf7f5d974a5db Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 12:56:04 -0500 Subject: [PATCH 4/6] Trying to fix another preflight failure --- lib/mayaUsd/python/wrapUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mayaUsd/python/wrapUtil.cpp b/lib/mayaUsd/python/wrapUtil.cpp index fe613cd937..7d4e807ac7 100644 --- a/lib/mayaUsd/python/wrapUtil.cpp +++ b/lib/mayaUsd/python/wrapUtil.cpp @@ -55,5 +55,5 @@ void wrapUtil() .def("getDictionaryFromEncodedOptions", getDictionaryFromEncodedOptions) .def( "getPathRelativeToMayaSceneFile", - &UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile); + UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile); } From 93f21d1dc5cbea178e987e6fb49863916d2285e6 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 13:24:39 -0500 Subject: [PATCH 5/6] Fixing build for Maya versions without UFE --- test/lib/testMayaUsdCreateStageCommands.py | 4 ++-- test/lib/testMayaUsdLayerEditorCommands.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/testMayaUsdCreateStageCommands.py b/test/lib/testMayaUsdCreateStageCommands.py index 2b49c3c55d..ae6df68303 100644 --- a/test/lib/testMayaUsdCreateStageCommands.py +++ b/test/lib/testMayaUsdCreateStageCommands.py @@ -17,7 +17,6 @@ # import os -from mayaUtils import openTopLayerScene import platform import unittest @@ -55,7 +54,8 @@ def testCreateStageWithNewLayer(self): def testCreateStageFromFile(self): # Open top_layer.ma and make sure to have USD stage paths as absolute - openTopLayerScene() + mayaSceneFilePath = testUtils.getTestScene("ballset", "StandaloneScene", "top_layer.ma") + cmds.file(mayaSceneFilePath, force=True, open=True) cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0)) # We cannot directly call the 'mayaUsdCreateStageFromFile' diff --git a/test/lib/testMayaUsdLayerEditorCommands.py b/test/lib/testMayaUsdLayerEditorCommands.py index 0e56af80d5..8b6c8b67f7 100644 --- a/test/lib/testMayaUsdLayerEditorCommands.py +++ b/test/lib/testMayaUsdLayerEditorCommands.py @@ -23,7 +23,6 @@ from maya import cmds, mel import mayaUsd_createStageWithNewLayer import mayaUsd -from mayaUtils import openTopLayerScene from pxr import Sdf, Usd CLEAR = "-clear" @@ -574,6 +573,7 @@ def testPathRelativeToMayaSceneFile(self): self.assertEqual(filePathAbs, ballFilePath) # With Maya scene file, the relative path is returned - openTopLayerScene() + mayaSceneFilePath = testUtils.getTestScene("ballset", "StandaloneScene", "top_layer.ma") + cmds.file(mayaSceneFilePath, force=True, open=True) filePathRel = mayaUsd.lib.Util.getPathRelativeToMayaSceneFile(ballFilePath) self.assertEqual(filePathRel, 'top_layer.usda') From 29cb9a2290a419a86d8e565ca5897fb7a24538fe Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 2 Feb 2023 14:09:18 -0500 Subject: [PATCH 6/6] Fixing python2-specific errors --- lib/mayaUsd/python/wrapUtil.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mayaUsd/python/wrapUtil.cpp b/lib/mayaUsd/python/wrapUtil.cpp index 7d4e807ac7..bc5a284b3f 100644 --- a/lib/mayaUsd/python/wrapUtil.cpp +++ b/lib/mayaUsd/python/wrapUtil.cpp @@ -55,5 +55,6 @@ void wrapUtil() .def("getDictionaryFromEncodedOptions", getDictionaryFromEncodedOptions) .def( "getPathRelativeToMayaSceneFile", - UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile); + UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile) + .staticmethod("getPathRelativeToMayaSceneFile"); }