Skip to content

Instantly share code, notes, and snippets.

View sbaer's full-sized avatar

Steve Baer sbaer

View GitHub Profile
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
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="}]
import Rhino
import scriptcontext
import time
import math
start = time.clock()
for i in xrange(600000):
line = Rhino.Geometry.Line(0,0,0,math.sin(i),math.cos(i),0)
scriptcontext.doc.Objects.AddLine(line)
end = time.clock()
import rhinoscriptsyntax as rs
import Rhino
def ModifyInstancePiece():
rs.UnselectAllObjects()
go = Rhino.Input.Custom.GetObject()
go.SubObjectSelect = True
go.Get()
if go.CommandResult() != Rhino.Commands.Result.Success:
return
@sbaer
sbaer / subdvertex.cs
Created August 21, 2015 17:51
SubDVertex ideas
struct SubDVertex
{
SubD m_parent;
IntPtr m_ptr_vertex; // ON_SubDVertex* vertex
uint m_parent_sn;
ComponentIndex m_component_index;
internal SubDVertex(SubD subd, IntPtr ptr_vertex, ComponentIndex ci, Point3d location)
{
m_parent = subd;
@sbaer
sbaer / gist:ec31b428c9be49b06e00
Last active August 29, 2015 14:27
CreatePlugIn function
public static PlugIn CreatePlugIn(Type pluginType, bool printDebugMessages)
{
if (null == pluginType || !typeof(PlugIn).IsAssignableFrom(pluginType))
return null;
InitializeRhinoCommon();
// If we turn on debug messages, we always get debug output
if (printDebugMessages)
SendDebugToCommandLine = true;