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: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:6117280
Created July 30, 2013 21:43
Using python inside of a RhinoCommon command
...
Rhino.Runtime.PythonScript m_py_script;
Rhino.Runtime.PythonCompiledCode m_compiled_script;
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
{
// create an instance of a python script processor
if (m_py_script == null)
m_py_script = Rhino.Runtime.PythonScript.Create();
if (m_py_script == null)
class MeshDisplayCache : IDisposable
{
Dictionary<System.Drawing.Color, Tuple<DisplayMaterial, Mesh>> _meshesToDraw;
public void Add(System.Drawing.Color color, Mesh mesh)
{
if (null == _meshesToDraw)
_meshesToDraw = new Dictionary<System.Drawing.Color, Tuple<DisplayMaterial, Mesh>>();
Tuple<DisplayMaterial, Mesh> data;
@sbaer
sbaer / InactiveGhDocDisplay.cs
Last active October 20, 2020 18:55
Hack in V6 to draw an inactive Grasshopper document
using System;
using System.Collections.Generic;
using System.Drawing;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino;
using Rhino.Commands;
namespace InactiveGhDocDisplay
{
import Rhino
import System.Drawing
import scriptcontext
import rhinoscriptsyntax as rs
class CustomConduit(Rhino.Display.DisplayConduit):
def __init__(self):
url = 'https://gist.githubusercontent.com/sbaer/bebd530d103a56cdd0076156af66f54b/raw/a92efce9ef85fd09316a42afcd899bd0e2d19b15/greetings.png'
self.image = Rhino.Display.DisplayBitmap.Load(url)
@sbaer
sbaer / hello_world_4.gh
Last active May 27, 2020 22:11
Binary File Test
@sbaer
sbaer / googletranslate.py
Created July 29, 2013 18:58
sample google translate python script
"""Use Google translate web service"""
import rhinoscriptsyntax as rs
import json, urllib
import scriptcontext
# Api key that I (Steve Baer) got from Google
# http://code.google.com/apis/console-help/#UsingKeys
# You might want to generate your own key, but I don't care
# if you continue to use this one.
KEY = "AIzaSyAZGoS-GjZGaSHZMZdoczfdUtWTjm_D-p4"
declare module 'rhino3dm' {
enum ActiveSpace {
None,
ModelSpace,
PageSpace
}
enum ComponentIndexType {
InvalidType,
@sbaer
sbaer / nurbscurve.json
Last active August 10, 2019 23:18
NURBS Curve as JSON
[{"version": 10000, "archive3dm": 60, "opennurbs": -1942458756, "data": "+n8CAP0BAAAAAAAA+/8CABQAAAAAAAAA3dTXTkfp0xG/5QAQgwEi8BDyeHD8/wIAxQEAAAAAAAAQAwAAAAEAAAADAAAACQAAAAAAAAAAAAAAAAAAAAAA8D8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAYLURU+yH5PxgtRFT7Ifk/GC1EVPshCUAYLURU+yEJQNIhM3982RJA0iEzf3zZEkAYLURU+yEZQBgtRFT7IRlACQAAAAAAAAAAAChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPA/2WzfzHb4IEDZbN/MdvggQAAAAAAAAAAAzDt/Zp6g5j8AAAAAAAAAAAAAAAAAAChAAAAAAAAAAAAAAAAAAADwP9ls38x2+CDA2WzfzHb4IEAAAAAAAAAAAMw7f2aeoOY/AAAAAAAAKMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D/ZbN/MdvggwNls38x2+CDAAAAAAAAAAADMO39mnqDmPwAAAAAAAAAAAAAAAAAAKMAAAAAAAAAAAAAAAAAAAPA/2WzfzHb4IEDZbN/MdvggwAAAAAAAAAAAzDt/Zp6g5j8AAAAAAAAoQAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwP04BQN3/fwKAAAAAAAAAAAA="}]