diff --git a/lib/mayaUsd/utils/utilSerialization.cpp b/lib/mayaUsd/utils/utilSerialization.cpp index 0800cb8895..d41b1dbf1e 100644 --- a/lib/mayaUsd/utils/utilSerialization.cpp +++ b/lib/mayaUsd/utils/utilSerialization.cpp @@ -289,15 +289,8 @@ SdfLayerRefPtr saveAnonymousLayer( return nullptr; } - std::string filePath(path); - const std::string& extension = SdfFileFormat::GetFileExtension(filePath); - const std::string defaultExt(UsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText()); - const std::string usdCrateExt(UsdMayaTranslatorTokens->UsdFileExtensionCrate.GetText()); - const std::string usdASCIIExt(UsdMayaTranslatorTokens->UsdFileExtensionASCII.GetText()); - if (extension != defaultExt && extension != usdCrateExt && extension != usdASCIIExt) { - filePath.append("."); - filePath.append(defaultExt.c_str()); - } + std::string filePath(path); + ensureUSDFileExtension(filePath); saveLayerWithFormat(anonLayer, filePath, formatArg); @@ -313,6 +306,18 @@ SdfLayerRefPtr saveAnonymousLayer( return newLayer; } +void ensureUSDFileExtension(std::string& filePath) +{ + const std::string& extension = SdfFileFormat::GetFileExtension(filePath); + const std::string defaultExt(UsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText()); + const std::string usdCrateExt(UsdMayaTranslatorTokens->UsdFileExtensionCrate.GetText()); + const std::string usdASCIIExt(UsdMayaTranslatorTokens->UsdFileExtensionASCII.GetText()); + if (extension != defaultExt && extension != usdCrateExt && extension != usdASCIIExt) { + filePath.append("."); + filePath.append(defaultExt.c_str()); + } +} + void getLayersToSaveFromProxy(const std::string& proxyPath, stageLayersToSave& layersInfo) { auto stage = UsdMayaUtil::GetStageByProxyName(proxyPath); diff --git a/lib/mayaUsd/utils/utilSerialization.h b/lib/mayaUsd/utils/utilSerialization.h index 1d093cfabe..02930a7032 100644 --- a/lib/mayaUsd/utils/utilSerialization.h +++ b/lib/mayaUsd/utils/utilSerialization.h @@ -114,7 +114,12 @@ PXR_NS::SdfLayerRefPtr saveAnonymousLayer( LayerParent parent, std::string formatArg = ""); -/*! \brief Check the sublayer stack of the stage looking for any anonymnous +/*! \brief Ensures that the filepath contains a valid USD extension. + */ +MAYAUSD_CORE_PUBLIC +void ensureUSDFileExtension(std::string& filePath); + +/*! \brief Check the sublayer stack of the stage looking for any anonymous layers that will need to be saved. */ MAYAUSD_CORE_PUBLIC diff --git a/lib/usd/ui/layerEditor/layerTreeItem.cpp b/lib/usd/ui/layerEditor/layerTreeItem.cpp index 2166658114..ecb7fb57d7 100644 --- a/lib/usd/ui/layerEditor/layerTreeItem.cpp +++ b/lib/usd/ui/layerEditor/layerTreeItem.cpp @@ -363,7 +363,10 @@ void LayerTreeItem::saveAnonymousLayer() std::string fileName; if (sessionState->saveLayerUI(nullptr, &fileName)) { - // the path we has is an absolute path + + MayaUsd::utils::ensureUSDFileExtension(fileName); + + // the path we have is an absolute path const QString dialogTitle = StringResources::getAsQString(StringResources::kSaveLayer); std::string formatTag = MayaUsd::utils::usdFormatArgOption(); if (saveSubLayer(dialogTitle, parentLayerItem(), layer(), fileName, formatTag)) {