diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py index 9b2a0f0..ec77211 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py @@ -1,5 +1,26 @@ import os +from typing import List +def try_paths(paths: List[str], file: str): + if os.path.isabs(file): + return file if os.path.exists(file) else False + + tried = [] + for path in paths: + newPath = os.path.join(path, file) + if os.path.exists(newPath): + return newPath + else: + tried.append(newPath) + + raise FileNotFoundError("Tried paths: \n" + "\n".join(tried)) + # return False + HOME_DIR = os.path.expanduser("~") -ROOT_DIR = os.path.join(HOME_DIR, "DAZ 3D", "Bridges", "Daz To Maya") -EXPORT_DIR = os.path.join(ROOT_DIR, "Exports") + +ROOT_DIRS = [ + os.path.join(HOME_DIR, "DAZ 3D", "Bridges", "Daz To Maya"), + os.path.join(HOME_DIR, "Documents", "DAZ 3D", "Bridges", "Daz To Maya"), +] + +EXPORT_DIRS = [ os.path.join(dir, "Exports") for dir in ROOT_DIRS ] diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py index 015872e..8eebb96 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py @@ -36,11 +36,11 @@ # no delete morph, editer for user... - -d2m_logo = os.path.abspath("../icons/d2m_import_logo.png") -d2m_banner = os.path.abspath("../icons/d2m_banner.png") -d2m_help_icon = os.path.abspath("../icons/d2m_help_icon.png") -txtConf = os.path.abspath("../scripts/d2m.cfg") +DIRNAME = os.path.dirname(os.path.abspath(__file__)) +d2m_logo = os.path.join(DIRNAME, "../icons/d2m_import_logo.png") +d2m_banner = os.path.join(DIRNAME, "../icons/d2m_banner.png") +d2m_help_icon = os.path.join(DIRNAME, "../icons/d2m_help_icon.png") +txtConf = os.path.join(DIRNAME, "../scripts/d2m.cfg") scale_menu_value = "Automatic" @@ -2368,19 +2368,19 @@ def import_fbx(daz_file_path): if scale_menu_value == "x0.01 (smaller)": # FORCE cm Correct Unit....... CHELO mel.eval('FBXImportConvertUnitString m') - + daz_file_path = daz_file_path.replace('\\', '/') + import_cmd = "FBXImport -f \"" + daz_file_path + "\"" mel.eval(import_cmd) def auto_import_daz(): - # Importing only first figure for now - daz_file_path = os.path.abspath(Definitions.EXPORT_DIR + "\FIG\FIG0\B_FIG.fbx") + daz_file_path = Definitions.try_paths(Definitions.EXPORT_DIRS, os.path.join("FIG", "FIG0", "B_FIG.fbx")) # exit if file not found - if os.path.exists(daz_file_path) == False: + if not daz_file_path: open_import_not_found_window() return diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/dazmaterials.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/dazmaterials.py index 8565cb6..7b01fd2 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/dazmaterials.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/dazmaterials.py @@ -3,7 +3,7 @@ import pymel.core as pm import maya.cmds as cmds -from Definitions import EXPORT_DIR +from Definitions import EXPORT_DIRS, try_paths from DtuLoader import DtuLoader from TextureLib import texture_library, texture_maps @@ -20,7 +20,7 @@ def load_materials(self): """ Load materials from Dtu file """ - dtu_path = os.path.abspath(EXPORT_DIR + "\FIG\FIG0") + dtu_path = try_paths(EXPORT_DIRS, os.path.join("FIG", "FIG0")) dtu_loader = DtuLoader(dtu_path) mats = dtu_loader.get_materials_list() for mat in mats: