From 0c1e6aa59ede98b63ad2faa568be0b98de56107e Mon Sep 17 00:00:00 2001 From: Janusz Dziurzynski Date: Sun, 28 Nov 2021 17:28:51 -0500 Subject: [PATCH 1/4] Fix d2m.py path resolution --- Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py index 015872e..c9affb2 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" From 4132e91576f1c1eaee11e3c8fcdd14051afd7013 Mon Sep 17 00:00:00 2001 From: Janusz Dziurzynski Date: Sun, 28 Nov 2021 22:07:52 -0500 Subject: [PATCH 2/4] Add "~/Documents" as an additional ROOT_DIR --- .../modules/DazToMaya/scripts/Definitions.py | 9 ++++++-- .../modules/DazToMaya/scripts/d2m.py | 23 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py index 9b2a0f0..aa7c1e5 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py @@ -1,5 +1,10 @@ import os 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 c9affb2..b96ce7c 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py @@ -2368,19 +2368,36 @@ 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) +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 + 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 = 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 From 2f8bd78374e16c938d73ccb1699c3fbcb7de6938 Mon Sep 17 00:00:00 2001 From: Janusz Dziurzynski Date: Sun, 28 Nov 2021 22:32:21 -0500 Subject: [PATCH 3/4] Move try_paths() into Definitions.py --- .../modules/DazToMaya/scripts/Definitions.py | 16 ++++++++++++++++ .../modules/DazToMaya/scripts/d2m.py | 19 +------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/Definitions.py index aa7c1e5..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,21 @@ 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_DIRS = [ diff --git a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py index b96ce7c..8eebb96 100644 --- a/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py +++ b/Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/d2m.py @@ -2375,26 +2375,9 @@ def import_fbx(daz_file_path): mel.eval(import_cmd) -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 - def auto_import_daz(): - # Importing only first figure for now - daz_file_path = try_paths(Definitions.EXPORT_DIRS, os.path.join("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 not daz_file_path: From e2505d5c4c8351f5588bacd696fbf61cd5aecc0f Mon Sep 17 00:00:00 2001 From: Janusz Dziurzynski Date: Sun, 28 Nov 2021 22:33:16 -0500 Subject: [PATCH 4/4] Use Definitions.try_paths() for FIG path --- Maya/MAYA_APP_DIR/modules/DazToMaya/scripts/dazmaterials.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: