diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f98c464392f..76ad1f03bcc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added crease handling to catmull-clark subdivision scheme. * Added Python 3.9 support +* Added `compas_ghpython.get_grasshopper_userobjects_path` to retrieve User Objects target folder. ### Changed diff --git a/src/compas_ghpython/__init__.py b/src/compas_ghpython/__init__.py index 317e66464ed8..9176a74d2b76 100644 --- a/src/compas_ghpython/__init__.py +++ b/src/compas_ghpython/__init__.py @@ -23,11 +23,21 @@ def get_grasshopper_library_path(version): + """Retrieve Grasshopper's library (components) path""" + return _get_grasshopper_special_folder(version, 'Libraries') + + +def get_grasshopper_userobjects_path(version): + """Retrieve Grasshopper's user objects path""" + return _get_grasshopper_special_folder(version, 'UserObjects') + + +def _get_grasshopper_special_folder(version, folder_name): if compas.WINDOWS: - grasshopper_library_path = os.path.join(os.getenv('APPDATA'), 'Grasshopper', 'Libraries') + grasshopper_library_path = os.path.join(os.getenv('APPDATA'), 'Grasshopper', folder_name) elif compas.OSX: grasshopper_library_path = os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'McNeel', 'Rhinoceros', '{}'.format(version), - 'Plug-ins', 'Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)', 'Libraries') + 'Plug-ins', 'Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)', folder_name) else: raise Exception('Unsupported platform') return grasshopper_library_path