Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to create a new Honeybee plus plugin
Is it possible to create a new honeybee[+] library for another 3d modeling tool?
One of the frequently asked questions is if it is possible to create a new honeybee[+] library for other 3d modeling tools (e.g. Blender, ArcGIS)? and if we're going to develop more [+] libraries.
The short answers are yes and yes if someone who is expert in the platform wants to get involved. The development is the easy part, and where it gets hard is the maintenance and support.
Before we get to how you can write a new library you need to understand the structure of the code. Honeybee consists of a core library which is developed in python and is developed on top the simulation engines. The inputs are coordinates, numbers and other standard python inputs. The core library is relatively large and has taken most of the time for the development and since it works with standard inputs it's platform agnostic.
For instance you can create a honeybee surface by having the coordinates of the surface corners as a collection of (x, y, z) values. Then you can use
to_ep_string to get Radiance and EnergyPlus definitions for the surface.
What the [+] libraries do is to add a collection of functions that takes geometry inputs and translates them to standard inputs for the core library. These libraries are much smaller and are platform specific but all of them must have the same name, input arguments and outputs. This pattern makes it possible to call the functions from inside the core library regardless of which [+] library is used.
How does it look like in reality a.k.a show me the code!
Take the honeybee-grasshopper as an example. It currently consists of only two files:
plus.py. To convert the core library to honeybee-grasshopper library all you need to do is to copy these two files in the honeybee installation folder.
__init__.py will overwrite the init file in the core library. The only difference between the two files is this line:
setattr(sys.modules[__name__], 'isplus', True)
This line sets the
isplus property for honeybee to True. This is important because all the methods inside core libraries which are using the [+] functions have a check for isplus. Take the
from_geometry method for
HBSurface as an example. This method calls functions from the [+] library to the geometry to coordinates. The first line in the method checks if the call is coming from a [+] library before executing the main part of the method, and that's why we need to overwrite
assert honeybee.isplus, \ '"from_geometries" method can only be used in [+] libraries.'
As you can see the code has no dependencies from Grasshopper or Rhino and so for your new library you can just copy the
__init__.py from honeybee-grasshopper! Bingo.
The second file is the only file that you really need to re-write. In the current version there is only 3 methods that you need to re-write: extract_geometry_points, xyz_to_geometrical_points and polygon. The first one is the one that can take an hour or so but the other two function should take a couple of minutes to write. Once you have theses functions you basically have your new [+] library ready to go! As easy at that.
What about the plugin itself? Can I recreate the nodes from one of the available plugins?
The answer depends on the platform. We have a script that takes the Grasshopper components and creates the Dynamo nodes! But this is possible because Dynamo nodes are XML files. The script uses dyfpy library which can be modified for new platforms.
Get in touch if you need help or have any questions.