diff --git a/lib/mayaUsd/ufe/Utils.cpp b/lib/mayaUsd/ufe/Utils.cpp index f918c7994a..b5675d99e7 100644 --- a/lib/mayaUsd/ufe/Utils.cpp +++ b/lib/mayaUsd/ufe/Utils.cpp @@ -162,13 +162,13 @@ std::string uniqueChildNameMayaStandard(const PXR_NS::UsdPrim& usdParent, const std::string childBaseName; std::pair largestMatching("", -1); - for (const auto child : allChildrenNames) { + for (const auto& child : allChildrenNames) { // While iterating thru all the children look for ones that match // the base name of the input. When we find one check its numerical // suffix and store the greatest one. splitNumericalSuffix(child.GetString(), childBaseName, suffix); if (baseName == childBaseName) { - int suffixValue = std::stoi(suffix); + int suffixValue = !suffix.empty() ? std::stoi(suffix) : 0; if (suffixValue > largestMatching.second) { largestMatching = std::make_pair(child, suffixValue); } diff --git a/lib/usdUfe/python/wrapUtils.cpp b/lib/usdUfe/python/wrapUtils.cpp index 7c7c795f02..a965b630d6 100644 --- a/lib/usdUfe/python/wrapUtils.cpp +++ b/lib/usdUfe/python/wrapUtils.cpp @@ -57,7 +57,10 @@ std::string _usdPathToUfePathSegment( std::string _uniqueName(const std::vector& existingNames, std::string srcName) { - PXR_NS::TfToken::HashSet existingNamesSet(existingNames.begin(), existingNames.end()); + PXR_NS::TfToken::HashSet existingNamesSet; + for (const auto& n : existingNames) { + existingNamesSet.insert(PXR_NS::TfToken(n)); + } return UsdUfe::uniqueName(existingNamesSet, srcName); } @@ -77,6 +80,11 @@ int _ufePathToInstanceIndex(const std::string& ufePathString) return UsdUfe::ufePathToInstanceIndex(Ufe::PathString::path(ufePathString)); } +bool _isEditTargetLayerModifiable(const PXR_NS::UsdStageWeakPtr stage) +{ + return UsdUfe::isEditTargetLayerModifiable(stage); +} + PXR_NS::UsdTimeCode _getTime(const std::string& pathStr) { const Ufe::Path path = Ufe::PathString::path(pathStr); @@ -106,7 +114,7 @@ void wrapUtils() def("stripInstanceIndexFromUfePath", _stripInstanceIndexFromUfePath, (arg("ufePathString"))); def("ufePathToPrim", _ufePathToPrim); def("ufePathToInstanceIndex", _ufePathToInstanceIndex); - def("isEditTargetLayerModifiable", UsdUfe::isEditTargetLayerModifiable); + def("isEditTargetLayerModifiable", _isEditTargetLayerModifiable); def("getTime", _getTime); def("isAttributeEditAllowed", _isAttributeEditAllowed); } diff --git a/test/lib/ufe/testContextOps.py b/test/lib/ufe/testContextOps.py index b983970ba9..dc7a660a66 100644 --- a/test/lib/ufe/testContextOps.py +++ b/test/lib/ufe/testContextOps.py @@ -919,13 +919,15 @@ def createMaterial(proxyShape): assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath)) # Case 6: A non-scope object named "mtl" exists and a scope named "mtl2" exists. - # The new material should get created in a new scope named "mtl1". + # The new material should get created in a new scope named "mtl3". + # This follows normal Maya naming standard where it increments the largest numerical + # suffix (even if there are gaps). proxyShape = createProxyShape() proxyShapePath = ufe.PathString.string(proxyShape.path()) addNewPrim(proxyShape, "Def", materialsScopeName) addNewPrim(proxyShape, "Scope", materialsScopeName + "2") createMaterial(proxyShape) - expectedPath = proxyShapePath + ",/" + materialsScopeName + "1/" + materialName + expectedPath = proxyShapePath + ",/" + materialsScopeName + "3/" + materialName assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath)) # Case 7: A non-scope object named "mtl" exists and a scope named "mtlBingBong" exists. @@ -948,8 +950,11 @@ def createMaterial(proxyShape): for scopeNamePostfix in scopeNamePostfixes: addNewPrim(proxyShape, "Scope", materialsScopeName + scopeNamePostfix) + # Again here follow the normal Maya naming standard which increments the largest + # numerical suffix (1337). createMaterial(proxyShape) - expectedPath = proxyShapePath + ",/" + materialsScopeName + "1/" + materialName + expectedPath = proxyShapePath + ",/" + materialsScopeName + "1338/" + materialName + print(expectedPath) assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath)) # Case 9: Multiple non-scope object named "mtl", "mtl1", ..., "mtl3" exists and multiple @@ -967,7 +972,7 @@ def createMaterial(proxyShape): addNewPrim(proxyShape, "Scope", materialsScopeName + scopeNamePostfix) createMaterial(proxyShape) - expectedPath = proxyShapePath + ",/" + materialsScopeName + "4/" + materialName + expectedPath = proxyShapePath + ",/" + materialsScopeName + "1338/" + materialName assert ufe.Hierarchy.createItem(ufe.PathString.path(expectedPath)) # Case 10: Multiple non-scope object named "mtl", "mtl1", ..., "mtl3" exists and multiple