August 11, 2019, 2:31pm
Is it possible to use Kangaroo outside of Grasshopper i.e. in a Python script that’s opened from Rhino with
EditPythonScript? I know you can use Grasshopper components with:
import ghpythonlib.components as ghcomp
but Kangaroo is a little different because it has state.
August 12, 2019, 8:10am
The short answer is yes. Here is a sample from
@DanielPiker which demonstrates how to use the Kangaroo API in Rhino: https://github.com/Dan-Piker/Drop
We’ve also been implementing Kangaroo2 in IronPython since it was a wee Joey. There’s an example of how to reference the assembly here and an implementation of a zombie solver (i.e. one that solves the goals in one go, such that you won’t have to worry about implementing the iterative step solving as a dynamic process):
Can you upload copy/paste just that one component? It might be a really early/dumb implementation with an easy fix.
Edit: Here’s the latest one I could find on my laptop (from Advances in Architectural Geometry 2016):
160907_K2_GHPython_CustomSolvers_02.gh (18.7 KB)
It’s probably not gonna make much of a difference though, but it’s worth a shot. Also, in Rhino 6 GHPython I’ve been referencing the KangarooSolver.dll (that now ships with Grasshopper) like so:
import Grasshopper as gh
Edit: note that these example files are quite old at this point, and a lot has happened since. So I’m sure there are better, more efficient approaches here and there.
August 12, 2019, 11:40am
@fraguada @AndersDeleuran thanks for those references.
I just did a straight translation of one of the Kangaroo examples (Catenary.gh) to a Rhino Python script and it seems to work OK:
import ghpythonlib.components as ghc
from Rhino.Geometry import Vector3d, Rectangle3d, Plane, Point3d
from scriptcontext import doc
# Mesh plane
plane = Plane(Point3d(-10, -10, 0), Vector3d(0, 0, 1))
boundary = Rectangle3d(plane, 20, 20)
mesh, _ = ghc.MeshPlane(boundary, 10, 10)
# Stretch resistance for edges
naked_edges, interior_edges, _ = ghc.MeshEdges(mesh)
length_goal = ghc.Kangaroo2Component.LengthLine(naked_edges + interior_edges, None, 10)
# Fix corners in place
corners = ghc.Kangaroo2Component.MeshCorners(mesh, 2.356194)
anchor_goal = ghc.Kangaroo2Component.Anchor(corners, None, 1000)
# Apply loads to all vertices
vertices, _, _, _ = ghc.DeconstructMesh(mesh)
load_goal = ghc.Kangaroo2Component.Load(vertices, Vector3d(0, 0, 1), 1)
goals = length_goal + anchor_goal + load_goal
_, _, output = ghc.Kangaroo2Component.Solver(goals, False, 1e-15, 0.01, True)
# Output lines
for line in output:
I like the idea in Dynamo where you can switch to DesignScript if you need to. Seems like you can do the same in Grasshopper.