From e5d18157063a81cae91ecea63ba04512c2436cf2 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:17:03 -0400 Subject: [PATCH] EMSUSD-993: When opening a file dependency in the AE, the dialog doesn't open to the location of the file * If we can resolve path to absolute, open the file dialog on that path. * Fix spelling mistakes --- .../ae/usdschemabase/custom_image_control.py | 16 +++++++++++++++- lib/mayaUsd/utils/utilFileSystem.h | 14 +++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/mayaUsd/resources/ae/usdschemabase/custom_image_control.py b/lib/mayaUsd/resources/ae/usdschemabase/custom_image_control.py index 27011d8506..b0aab4d011 100644 --- a/lib/mayaUsd/resources/ae/usdschemabase/custom_image_control.py +++ b/lib/mayaUsd/resources/ae/usdschemabase/custom_image_control.py @@ -29,6 +29,9 @@ import ufe +import os +from pxr import Sdf + try: from PySide2 import QtCore except: @@ -132,8 +135,19 @@ def filenameBrowser(self, callback): ImageCustomControl.fixFileDialogSplitters() + # Determine if we can get an absolute path from the attribute value. + # If we can then try and find the starting directory from that path. + startDir = None + usdAttr = self.prim.GetAttribute(self.attrName) + usdValue = usdAttr.Get() + if isinstance(usdValue, Sdf.AssetPath): + resolvedPath = usdValue.resolvedPath + if os.path.exists(resolvedPath): + # Use forward slashes in path to avoid any problems. Maya accepts them all platforms. + startDir = os.path.abspath(os.path.dirname(resolvedPath)).replace(os.sep, '/') + dialogArgs = { - 'startDir' : mel.eval("""setWorkingDirectory("%s", "image", "sourceImages")""" % workspace), + 'startDir' : startDir if startDir else mel.eval("""setWorkingDirectory("%s", "image", "sourceImages")""" % workspace), 'filter' : mel.eval("buildImageFileFilterList()"), 'caption' : getMayaUsdLibString('kOpenImage'), 'createCallback' : "mayaUsd_ImageFileRelative_UICreate", diff --git a/lib/mayaUsd/utils/utilFileSystem.h b/lib/mayaUsd/utils/utilFileSystem.h index 726027aa86..61c7bee2ae 100644 --- a/lib/mayaUsd/utils/utilFileSystem.h +++ b/lib/mayaUsd/utils/utilFileSystem.h @@ -250,7 +250,7 @@ std::string getNumberSuffix(const std::string& text); MAYAUSD_CORE_PUBLIC std::string increaseNumberSuffix(const std::string& text); -/*! \brief returns the aboluste path relative to the maya file +/*! \brief returns the absolute path relative to the Maya file */ MAYAUSD_CORE_PUBLIC std::string resolveRelativePathWithinMayaContext( @@ -273,10 +273,10 @@ bool pathAppendPath(std::string& a, const std::string& b); /** * Appends `b` to the path `a` and returns a path (by appending two input paths). * - * @param a A string that respresents the first path - * @param b A string that respresents the second path + * @param a A string that represents the first path + * @param b A string that represents the second path * - * @return the two paths joined by a seperator + * @return the two paths joined by a separator */ MAYAUSD_CORE_PUBLIC std::string appendPaths(const std::string& a, const std::string& b); @@ -308,17 +308,17 @@ void pathRemoveExtension(std::string& filePath); MAYAUSD_CORE_PUBLIC std::string pathFindExtension(std::string& filePath); -// Backup a file and restore it if not commited. +// Backup a file and restore it if not committed. class FileBackup { public: FileBackup(const std::string& filename); ~FileBackup(); - // Once commited, the backup will not be put back into the original file. + // Once committed, the backup will not be put back into the original file. void commit(); - // Force restoration of the original file if successfully backed-up, even if commited. + // Force restoration of the original file if successfully backed-up, even if committed. void restore(); // Return the backup file name.