Skip to content

Commit

Permalink
EMSUSD-1718 improve prefs window handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrebai-adsk committed Oct 15, 2024
1 parent 0e2a69b commit ce29fc9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/mayaUsd/fileio/jobs/readJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,34 @@ void UsdMaya_ReadJob::_ConvertUpAxisAndUnitsByChangingMayaPrefs(
{
bool success = true;

// Close preference window if needed.
{
static const char* closePrefsCmd
= "global string $gPreferenceWindow;\n"
"if (`window -query -exists $gPreferenceWindow`) {\n"
" if (`window -query -visible $gPreferenceWindow`) {\n"
" string $title = getMayaUsdLibString(\"kAboutToChangePrefsTitle\");\n"
" string $body = getMayaUsdLibString(\"kAboutToChangePrefs\");\n"
" string $ok = getMayaUsdLibString(\"kSavePrefsChange\");\n"
" string $cancel = getMayaUsdLibString(\"kDiscardPrefsChange\");\n"
" string $result = `confirmDialog -title $title -message $body\n"
" -button $ok -button $cancel\n"
" -defaultButton $ok\n"
" -cancelButton $cancel`;\n"
" if ($result == $ok) {\n"
" savePrefsChanges;\n"
" }\n"
" else {\n"
" cancelPrefsChanges;\n"
" }\n"
" }\n"
"}\n";

if (!MGlobal::executeCommand(closePrefsCmd)) {
MGlobal::displayWarning("Failed to close the Maya preferences windows.");
}
}

// Set up-axis preferences if needed.
if (conversion.needUpAxisConversion) {
const bool rotateView = true;
Expand All @@ -756,15 +784,7 @@ void UsdMaya_ReadJob::_ConvertUpAxisAndUnitsByChangingMayaPrefs(
} else {
const MString mayaUnitText = UsdMayaUtil::ConvertMDistanceUnitToText(mayaUnit);
MString changeUnitsCmd;
changeUnitsCmd.format(
"global string $gPreferenceWindow;\n"
"if (`window -query -exists $gPreferenceWindow`) {\n"
" if (`window -query -visible $gPreferenceWindow`) {\n"
" window -edit -visible off $gPreferenceWindow;\n"
" }\n"
"}\n"
"currentUnit -linear ^1s;",
mayaUnitText);
changeUnitsCmd.format("currentUnit -linear ^1s;", mayaUnitText);

// Note: we *must* execute the units change on-idle because the import process
// saves and restores all units! If we change it now, the change would be lost.
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/resources/scripts/mayaUsdLibRegisterStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def mayaUsdLibRegisterStrings():
register("kStageConversionUnknownMethod", "Unknown stage conversion method: %s")
register("kStageConversionSuccessful", "Mismatching axis/unit have been converted for accurate scale.")

# readJob.cpp
register("kAboutToChangePrefs", "The USD import is about to change the Maya preferences.\n" +
"Save your changes in the preferences window?")
register("kAboutToChangePrefsTitle", "Save Preferences")
register("kSavePrefsChange", "Save Preferences")
register("kDiscardPrefsChange", "Discard Preferences")


def registerPluginResource(pluginId, stringId, resourceStr):
'''See registerPluginResource.mel in Maya.
Expand Down

0 comments on commit ce29fc9

Please sign in to comment.