From e74b940a5dc8a192668d98609cc7710569f85f27 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Thu, 30 Nov 2023 08:51:46 -0500 Subject: [PATCH] EMSUSD-647 fix copying the proxy shape node When Maya copies a Maya node, it actually export the selected nodes into a temporary file. When the node is a MayaUSD node, this export automatically prompt the user to save the dirty USD files. To avoid this, we now detect that we are exporting due to a copy operation and force saving the USD layer into the Maya scene file. --- lib/mayaUsd/nodes/layerManager.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/mayaUsd/nodes/layerManager.cpp b/lib/mayaUsd/nodes/layerManager.cpp index ae524852a8..1e76a5feee 100644 --- a/lib/mayaUsd/nodes/layerManager.cpp +++ b/lib/mayaUsd/nodes/layerManager.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -194,6 +195,14 @@ bool isCrashing() #endif } +bool isCopyingSceneNodes() +{ + // When Maya is copy nodes, it exports them and sets this environment + // variable during the export to let exporters know it is cutting or + // copying nodes in a temporary Maya scene file. + return PXR_NS::ArchHasEnv("MAYA_CUT_COPY_EXPORT"); +} + constexpr auto kSaveOptionUICmd = "usdFileSaveOptions(true);"; } // namespace @@ -412,9 +421,11 @@ void LayerDatabase::prepareForWriteCheck(bool* retCode, bool isExport) int dialogResult = true; - if (MGlobal::kInteractive == MGlobal::mayaState() && !isCrashing() - && LayerDatabase::instance().saveInteractionRequired()) { - MGlobal::executeCommand(kSaveOptionUICmd, dialogResult); + if (!isCopyingSceneNodes()) { + if (MGlobal::kInteractive == MGlobal::mayaState() && !isCrashing() + && LayerDatabase::instance().saveInteractionRequired()) { + MGlobal::executeCommand(kSaveOptionUICmd, dialogResult); + } } if (dialogResult) { @@ -619,10 +630,10 @@ bool LayerDatabase::saveUsd(bool isExport) auto opt = MayaUsd::utils::serializeUsdEditsLocationOption(); if (MayaUsd::utils::kIgnoreUSDEdits != opt) { - // When Maya is crashing, we don't want to save the the USD file to avoid - // overwriting them with possibly unwanted data. Instead, we will save the - // USD data inside the temporary crash recovery Maya file. - if (isCrashing()) { + // When Maya is crashing or copying/cutting scene nodes, we don't want to + // save the the USD file to avoid overwriting them with possibly unwanted + // data. Instead, we will save the USD data inside the temporary crash recovery Maya file. + if (isCrashing() || isCopyingSceneNodes()) { result = kPartiallyCompleted; opt = MayaUsd::utils::kSaveToMayaSceneFile; } else if (_batchSaveDelegate && _proxiesToSave.size() > 0) {