Skip to content

Instantly share code, notes, and snippets.

View AndersDeleuran's full-sized avatar

Anders Holden Deleuran AndersDeleuran

View GitHub Profile
import Rhino as rc
def meshEndFaces(mesh):
""" Get indices of faces with only one neighbour """
endFaces = []
for i in range(mesh.Faces.Count):
af = mesh.Faces.AdjacentFaces(i)
if len(af) == 1:
import Rhino as rc
def meshEdgeLines(mesh):
lines = []
for i in range(mesh.Vertices.Count):
neighbours = mesh.Vertices.GetConnectedVertices(i)
for n in neighbours:
if n > i:
line = rc.Geometry.Line(mesh.Vertices.Item[i],mesh.Vertices.Item[n])
Hex = ["#%02x%02x%02x" % (c.R,c.G,c.B) for c in RGB]
def sortCurvesByEuclideanCoords(crvs,t):
""" Sort a list of curves by Euclidean coordinates """
ptsOnCrvs = [crv.PointAt(t) for crv in crvs]
sortedBoth = sorted(zip(ptsOnCrvs,crvs))
sortedCrvs = [l[1] for l in sortedBoth]
return sortedCrvs
from scriptcontext import sticky as st
import Rhino as rc
def customDisplay(toggle,component):
""" Make a custom display which is unique to the component and lives in sticky """
# Make unique name and custom display
displayGuid = "customDisplay_" + str(component.InstanceGuid)
if displayGuid not in st:
import Rhino as rc
def mapValuesAsColors(values,srcMin,srcMax,targetMin,targetMax):
""" Make a list of HSL colors where the values are mapped onto a
targetMin-targetMax hue domain. Meaning that low values will be red, medium
values green and large values blue if targetMin: 0.0 and targetMax: 0.7 """
# Remap numbers into new numeric domain
remappedValues = []
import Grasshopper as gh
def listToTree(nestedList):
""" Convert a nested python iterable to a datatree """
dt = gh.DataTree[object]()
for i,l in enumerate(nestedList):
dt.AddRange(l,gh.Kernel.Data.GH_Path(i))
""" Read the Grasshopper Datatree "tree" and translates it to
a nested Python list """
pyList = [list(b) for b in tree.Branches]
@AndersDeleuran
AndersDeleuran / gist:0fbe6512f5ef542ef1bd
Created May 3, 2015 09:51
MassAddition using For Loop
Sum = 0
Results = []
for v in Values:
Sum += v
Results.append(Sum)
foo = []
for i in range(3):
bar = []
for j in range(3):
bar.append(i*j)
foo.append(bar)
print foo