Skip to content

Commit

Permalink
Merge pull request #2861 from Autodesk/vlasovi/MAYA-127459
Browse files Browse the repository at this point in the history
MAYA-127459 - Create an autotest for USD root layer having a relative path
  • Loading branch information
seando-adsk authored Feb 16, 2023
2 parents 8f6e24d + 29cb9a2 commit e248e90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mayaUsd/python/wrapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ void wrapUtil()
.def("getDictionaryFromEncodedOptions", getDictionaryFromEncodedOptions)
.def(
"getPathRelativeToMayaSceneFile",
&UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile);
UsdMayaUtilFileSystem::getPathRelativeToMayaSceneFile)
.staticmethod("getPathRelativeToMayaSceneFile");
}
16 changes: 16 additions & 0 deletions test/lib/testMayaUsdCreateStageCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ 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
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'
# as it opens a file dialog to choose the scene. So instead
# we can call what it does once the file is choose.
Expand All @@ -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.assertEqual(filePathAttrRel, 'top_layer.usda')

# Restore mayaUsd_MakePathRelativeToSceneFile
cmds.optionVar(iv=('mayaUsd_MakePathRelativeToSceneFile', 0))
20 changes: 20 additions & 0 deletions test/lib/testMayaUsdLayerEditorCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import unittest
import tempfile
import testUtils
from os import path
from maya import cmds, mel
import mayaUsd_createStageWithNewLayer
Expand Down Expand Up @@ -557,3 +558,22 @@ 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
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')

0 comments on commit e248e90

Please sign in to comment.