Skip to content

Instantly share code, notes, and snippets.

View sbaer's full-sized avatar

Steve Baer sbaer

View GitHub Profile
@sbaer
sbaer / gist:1023456
Created June 13, 2011 19:05
Get world points from mouse cursor position
import scriptcontext
import time
import System
import Rhino
rc, view = Rhino.Input.RhinoGet.GetView("select view")
print "position mouse where you want"
for i in [5,4,3,2,1]:
time.sleep(0.5)
@sbaer
sbaer / gist:1025541
Created June 14, 2011 18:38 — forked from bengolder/gist:1019295
Grasshopper File and Geometry Import Script
import Rhino
# read geometry out of 3dm files and filter by layernames
if DoImport and FilePaths and LayerNames:
geometry = []
for filepath in FilePaths:
model = Rhino.FileIO.File3dm.Read(filepath)
if not model: continue
for layer in LayerNames:
objs = model.Objects.FindByLayer(layer)
@sbaer
sbaer / gist:1028638
Created June 16, 2011 03:48
shapeways including pricing
"""Sample script that accesses the shapeways API
http://www.shapeways.com/api
"""
import wsdlprovider
wsdl_url = "http://api.shapeways.com/v1/wsdl.php"
username = "username"
password = "password"
application_id = "rhinotest"
@sbaer
sbaer / divideSrf.py
Created October 8, 2011 16:52
ghpython script for creating data trees
import rhinoscriptsyntax as rs
import Rhino
import clr
clr.AddReference("grasshopper")
import Grasshopper as gh
DomainU = rs.SurfaceDomain(srf, 0)
DomainV = rs.SurfaceDomain(srf, 1)
flatlist = []
@sbaer
sbaer / gist:2003958
Created March 8, 2012 22:49
CellulateGrid3D sample for Rajaa
public static bool CellulateGrid3D(List<Rhino.Geometry.Point3d[]> points1,
List<Rhino.Geometry.Point3d[]> points2,
out Rhino.Geometry.Line[] wires,
out List<Rhino.Geometry.Point3d[]> cells,
out Rhino.Geometry.Brep[] boxes)
{
bool rc = false;
if (points1.Count > 0 && points2.Count > 0)
{
using (var divide_points1 = new ClassArrayPointArray(points1))
@sbaer
sbaer / gist:2175229
Created March 23, 2012 21:24
Using Custom Messages in a Get operation
// Your "get" class will have code that looks like.
var go = new Rhino.Input.Custom.GetOption();
var optDbl = new Rhino.Input.Custom.OptionDouble(12, 0,100);
go.SetCommandPrompt("Give me an option");
go.SetCommandPromptDefault("");
go.AcceptCustomMessage(true); // NEW!!
while (true)
{
// need to clear and reset the command options every iteration because
// Rhino doesn't know that it needs to update the option string
@sbaer
sbaer / gist:2432281
Created April 20, 2012 22:13
list-of-attractors
distance = []
vector = []
#### Check each attractor against all surface points
for pt in srfPT:
v = None
for att in attPT:
line_vector = att - pt
if not v or line_vector.Length < v.Length:
v = line_vector
@sbaer
sbaer / gist:2512920
Created April 27, 2012 20:43
Recursive Panelization translation into python
"""recursively subdivide surface based on curvature
author: robert stuart-smith | 2008 | www.kokkugia.com
translated to python by S. Baer (2012)"""
import rhinoscriptsyntax as rs
import scriptcontext
def PanelizeSurface(surface, subdivisions, generation):
#conditional statement to stop subdividing infinitely
#(as we will Call the Function recursively)
if generation<=0:
@sbaer
sbaer / gist:2559479
Created April 30, 2012 15:50
Brep.CreateFromSweep Sample
Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As Rhino.Commands.RunMode) As Rhino.Commands.Result
Dim command_rc As Rhino.Commands.Result
' Sweep the cross section
Dim rhobj As Rhino.DocObjects.ObjRef = Nothing
command_rc = Rhino.Input.RhinoGet.GetOneObject("Profile shape", False, DocObjects.ObjectType.Curve, rhobj)
If command_rc <> Commands.Result.Success Then Return command_rc
Dim shape As Rhino.Geometry.Curve = rhobj.Curve()
If shape Is Nothing Then Return Commands.Result.Failure
doc.Objects.UnselectAll()
@sbaer
sbaer / luistest.py
Created July 25, 2012 15:48
PointCloud Color/Normal test
import rhinoscriptsyntax as rs
import scriptcontext
def luistest():
id = rs.GetObject("select point cloud", rs.filter.pointcloud)
pc = scriptcontext.doc.Objects.Find(id)
pc = pc.PointCloudGeometry
print "ContainsColors =",pc.ContainsColors
c = pc.GetColors()