|
21 | 21 | if compas.is_rhino(): |
22 | 22 | from .utilities import * # noqa: F401 F403 |
23 | 23 |
|
| 24 | +__all__ = [ |
| 25 | + 'get_grasshopper_managedplugin_path', |
| 26 | + 'get_grasshopper_library_path', |
| 27 | + 'get_grasshopper_userobjects_path' |
| 28 | +] |
| 29 | +__all_plugins__ = [ |
| 30 | + 'compas_ghpython.install', |
| 31 | + 'compas_ghpython.uninstall', |
| 32 | + 'compas_ghpython.artists', |
| 33 | +] |
| 34 | + |
| 35 | + |
| 36 | +# ============================================================================= |
| 37 | +# General Helpers |
| 38 | +# ============================================================================= |
24 | 39 |
|
25 | | -def get_grasshopper_plugin_path(version): |
| 40 | + |
| 41 | +def _get_grasshopper_special_folder(version, folder_name): |
| 42 | + grasshopper = compas_rhino._get_grasshopper_plugin_path(version) |
| 43 | + return os.path.join(grasshopper, folder_name) |
| 44 | + |
| 45 | + |
| 46 | +# ============================================================================= |
| 47 | +# Managed Plugin |
| 48 | +# ============================================================================= |
| 49 | + |
| 50 | + |
| 51 | +def get_grasshopper_managedplugin_path(version): |
26 | 52 | version = compas_rhino._check_rhino_version(version) |
| 53 | + managedplugins = compas_rhino._get_managedplugins_path(version) |
27 | 54 |
|
28 | 55 | if compas.WINDOWS: |
29 | | - version = version.split('.')[0] # take the major only |
30 | | - grasshopper_plugin_path = os.path.join(os.getenv('ProgramFiles'), 'Rhino {}'.format(version), 'Plug-ins', 'Grasshopper') |
| 56 | + gh_managedplugin_path = os.path.join(managedplugins, 'Grasshopper') |
| 57 | + |
31 | 58 | elif compas.OSX: |
32 | | - lib_paths = { |
33 | | - '6.0': ['/', 'Applications', 'Rhinoceros.app'], |
34 | | - '7.0': ['/', 'Applications', 'Rhino 7.app', ] |
35 | | - } |
| 59 | + gh_managedplugin_path = os.path.join(managedplugins, 'GrasshopperPlugin.rhp') |
| 60 | + |
| 61 | + if not os.path.exists(gh_managedplugin_path): |
| 62 | + raise Exception("The Grasshopper (managed) Plug-in folder does not exist in this location: {}".format(gh_managedplugin_path)) |
36 | 63 |
|
37 | | - if version not in lib_paths: |
38 | | - raise Exception('Unsupported Rhino version') |
| 64 | + return gh_managedplugin_path |
39 | 65 |
|
40 | | - grasshopper_plugin_path = os.path.join(*lib_paths.get(version) + |
41 | | - ['Contents', 'Frameworks', 'RhCore.framework', 'Versions', 'A', |
42 | | - 'Resources', 'ManagedPlugIns', 'GrasshopperPlugin.rhp']) |
43 | | - else: |
44 | | - raise Exception('Unsupported platform') |
45 | | - return grasshopper_plugin_path |
| 66 | + |
| 67 | +# ============================================================================= |
| 68 | +# GH Plugin Libraries path |
| 69 | +# ============================================================================= |
46 | 70 |
|
47 | 71 |
|
48 | 72 | def get_grasshopper_library_path(version): |
49 | 73 | """Retrieve Grasshopper's library (components) path""" |
50 | 74 | return _get_grasshopper_special_folder(version, 'Libraries') |
51 | 75 |
|
52 | 76 |
|
| 77 | +# ============================================================================= |
| 78 | +# GH Plugin UserObjects path |
| 79 | +# ============================================================================= |
| 80 | + |
| 81 | + |
53 | 82 | def get_grasshopper_userobjects_path(version): |
54 | 83 | """Retrieve Grasshopper's user objects path""" |
55 | 84 | return _get_grasshopper_special_folder(version, 'UserObjects') |
56 | | - |
57 | | - |
58 | | -def _get_grasshopper_special_folder(version, folder_name): |
59 | | - if compas.WINDOWS: |
60 | | - grasshopper_library_path = os.path.join(os.getenv('APPDATA'), 'Grasshopper', folder_name) |
61 | | - elif compas.OSX: |
62 | | - grasshopper_library_path = os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'McNeel', 'Rhinoceros', '{}'.format(version), |
63 | | - 'Plug-ins', 'Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)', folder_name) |
64 | | - else: |
65 | | - raise Exception('Unsupported platform') |
66 | | - return grasshopper_library_path |
67 | | - |
68 | | - |
69 | | -__all_plugins__ = [ |
70 | | - 'compas_ghpython.install', |
71 | | - 'compas_ghpython.uninstall', |
72 | | - 'compas_ghpython.artists', |
73 | | -] |
74 | | -__all__ = [name for name in dir() if not name.startswith('_')] |
|
0 commit comments