Weaverbird from Python

Hi Giulio @piac

I’d like to use Weaverbird directly from Python. Is there an example how to use it?
Or a documentation with functions, arguments etc.?

Hi @Jess

thanks for the question here :slight_smile:

If you are aiming for a simple interaction, you can use the method shown on the GH forum. It has access to all components:

http://www.grasshopper3d.com/forum/topics/weavebird-in-python:
You can use ghpythonlib.components.

import ghpythonlib.components as ghc
ghc.WeaverBird. #... will show Wb commands

There are also other methods, but this is the simplest one. Does it help?

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

1 Like

You can install it by running the installer. Then you will need to add the Weaverbird installation folder to the V6 Grasshopper settings, using the _GrasshopperDeveloperSettings command. You should add “C:\Program Files\Weaverbird” there. ghpythonlib should also work in V5, provided the latest GhPython is installed.

If you still have problems in V5, check that you do not have a lot of other add-ons (I know one that makes loading other add-ons impossible in V5).

I hope this helps,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

1 Like

Hi Giulio,

Thanks that helps. I’ll try to make a simple Python example with some WB functions and post it here.

Jess

Fine, here a simple example with Weaverbird via Python:

import Rhino
import ghpythonlib.components as ghc
import scriptcontext as sc

def wbTest():
    plane = Rhino.Geometry.Plane.WorldXY
    width = 5.0
    sides = 3
    top = Rhino.Geometry.Point3d(0,0,10)
    mesh = ghc.WeaverBird.WeaverbirdsMeshPrism(plane,width,sides,top)
    sc.doc.Objects.AddMesh(mesh)
    cc = ghc.WeaverBird.WeaverbirdsCatmull_ClarkSubdivision(mesh,2)
    rc = sc.doc.Objects.AddMesh(cc)
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    wbTest()

enjoy :wink:

3 Likes

I remember looking into accessing the Weaverbird core .dll a while back (similar to how we’ve been implementing Kangaroo2, Plankton etc), would this be one such approach?

:wink:

Yes, exactly, but they are not so straighforward, because they were not written with Python in mind (nor third-parties in mind).

1 Like