Free Motion Capture for Everyone πβ¨
TypeScript
update `blender path` guess
jonmatthis935c2b4eaf7f
diff --git a/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py b/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.pyindex 26fe4f96..c285392c 100644--- a/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py+++ b/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py@@ -1,43 +1,41 @@import loggingimport platformfrom pathlib import Path-from typing import Union-from packaging import version+from typing import Union, Optionallogger = logging.getLogger(__name__)-def guess_blender_exe_path_from_path(base_path: Union[str, Path]) -> Path:- blender_folder_paths = sorted(- [path for path in base_path.rglob("Blender 3*") if "blender.exe" in (p.name for p in path.iterdir())],- key=lambda x: version.parse(x.name.split()[-1]),- reverse=True- )+def guess_blender_exe_path_from_path(base_path: Union[str, Path],+ exclude_blender_4: bool = True) -> Optional[Path]:+ base_path = Path(base_path)+ blender_folder_paths = [path for path in base_path.rglob("blender.exe")]+if blender_folder_paths:- blender_exe_path = blender_folder_paths[0] / "blender.exe"- if blender_exe_path.is_file():- return blender_exe_path- return None+ if exclude_blender_4:+ blender_folder_paths = [path for path in blender_folder_paths if "blender-4" not in str(path)]+ blender_folder_paths = [path for path in blender_folder_paths if "Blender 4" not in str(path)]++ best_guess = blender_folder_paths[-1]++ return best_guessdef get_best_guess_of_blender_path():if platform.system() == "Windows":- paths_to_check = [- Path(r"C:\Program Files\Blender Foundation"),- Path(Path.home()) / "Blender Foundation"- ]- found_paths = []+ # check all lettered drives and the user's home directory+ paths_to_check = [Path(f"{letter}:/Program Files/Blender Foundation") for letter in+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]++ paths_to_check.append(Path.home() / "Blender Foundation")+for base_path in paths_to_check:blender_exe_path = guess_blender_exe_path_from_path(base_path)if blender_exe_path is not None and blender_exe_path.is_file():- found_paths.append((version.parse(blender_exe_path.parent.name.split()[-1]), blender_exe_path))+ logger.info(f"Found `blender.exe` at: {str(blender_exe_path)}")- if found_paths:- highest_version_path = max(found_paths, key=lambda x: x[0])[1]- logger.info(- f"Windows machine detected - highest version of `blender` found at: {str(highest_version_path)}")- return str(highest_version_path)+ return str(blender_exe_path)else:logger.warning("Could not find `blender.exe` in the expected locations. Please locate it manually (or install Blender, if it isn't installed)."@@ -83,3 +81,7 @@ def get_best_guess_of_blender_path():else:logger.info("Machine system not detected, please locate Blender path manually.")return None+++if __name__ == "__main__":+ print(f" blender path: {get_best_guess_of_blender_path()}")