Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `compas_ghpython.fetch_ghio_lib` to simplify the loading of Grasshopper's IO library for extension developers.

### Changed

### Removed
Expand Down Expand Up @@ -52,9 +54,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas_rhino.install_plugin` to remove broken symlinks.
* Changed default Rhino version for installation to `7.0`.
* Fixed bug in `compas_ghpython` related to importing `Grasshopper` prematurely.
* Changed `compas.artists.Artist.ITAM_ARTIST` to context-based dict.
* Changed `compas.artists.Artist.ITEM_ARTIST` to context-based dict.
* Changed `compas_rhino.__init__.py` functions.
* Changed `compas_ghpython.__init__.py` functions.
* Renamed `compas_ghpython.get_grasshopper_plugin_path` to `compas_ghpython.get_grasshopper_managedplugin_path`.

### Removed

Expand Down
28 changes: 27 additions & 1 deletion src/compas_ghpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
compas_ghpython.utilities

"""
import io
import os
import urllib
import zipfile

import compas
import compas_rhino

Expand All @@ -24,7 +28,8 @@
__all__ = [
'get_grasshopper_managedplugin_path',
'get_grasshopper_library_path',
'get_grasshopper_userobjects_path'
'get_grasshopper_userobjects_path',
'fetch_ghio_lib'
]
__all_plugins__ = [
'compas_ghpython.install',
Expand Down Expand Up @@ -82,3 +87,24 @@ def get_grasshopper_library_path(version):
def get_grasshopper_userobjects_path(version):
"""Retrieve Grasshopper's user objects path"""
return _get_grasshopper_special_folder(version, 'UserObjects')


# =============================================================================
# GH_IO Dll
# =============================================================================


def fetch_ghio_lib(target_folder='temp'):
"""Fetch the GH_IO.dll library from the NuGet packaging system."""
ghio_dll = 'GH_IO.dll'
filename = 'lib/net48/' + ghio_dll

response = urllib.request.urlopen('https://www.nuget.org/api/v2/package/Grasshopper/')
dst_file = os.path.join(target_folder, ghio_dll)
zip_file = zipfile.ZipFile(io.BytesIO(response.read()))

with zip_file.open(filename, 'r') as zipped_dll:
with open(dst_file, 'wb') as fp:
fp.write(zipped_dll.read())

return dst_file
6 changes: 4 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def prepare_changelog(ctx):


@task(help={
'gh_io_folder': 'Folder where GH_IO.dll is located. Defaults to the Rhino 6.0 installation folder (platform-specific).',
'gh_io_folder': 'Folder where GH_IO.dll is located. If not specified, it will try to download from NuGet.',
'ironpython': 'Command for running the IronPython executable. Defaults to `ipy`.'})
def build_ghuser_components(ctx, gh_io_folder=None, ironpython=None):
"""Build Grasshopper user objects from source"""
Expand All @@ -199,9 +199,11 @@ def build_ghuser_components(ctx, gh_io_folder=None, ironpython=None):
source_dir = os.path.abspath('src/compas_ghpython/components')
target_dir = os.path.join(source_dir, 'ghuser')
ctx.run('git clone https://github.com/compas-dev/compas-actions.ghpython_components.git {}'.format(action_dir))

if not gh_io_folder:
gh_io_folder = 'temp'
import compas_ghpython
gh_io_folder = compas_ghpython.get_grasshopper_plugin_path('6.0')
compas_ghpython.fetch_ghio_lib(gh_io_folder)

if not ironpython:
ironpython = 'ipy'
Expand Down