Skip to content

Instantly share code, notes, and snippets.

View sbaer's full-sized avatar

Steve Baer sbaer

View GitHub Profile
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
class SliderForm(Form):
def __init__(self):
self.__value_changed_callback = None
self.InitializeComponent()
@sbaer
sbaer / gist:5615915
Created May 20, 2013 21:58
Dynamic Command Creation
public class TestDynamicCommandPlugIn : Rhino.PlugIns.PlugIn
{
// Override CreateCommands to generate your own commands on the fly
protected override void CreateCommands()
{
base.CreateCommands();
// uncomment the following to get your "private" command to work
//var cmd = new TestSecretCommand();
//Rhino.Runtime.HostUtils.RegisterDynamicCommand(this, cmd);
}
@sbaer
sbaer / gist:5587540
Created May 15, 2013 21:27
Automate Rhino5 with IronPython
# The following script is meant to be run inside of IronPython
# It demonstrates how to automate Rhino from a script
import System
# start an instance of Rhino
t = System.Type.GetTypeFromProgID("Rhino5.Application")
rhino = System.Activator.CreateInstance(t)
# show Rhino (optional)
rhino.Visible = True
@sbaer
sbaer / gist:5331496
Created April 7, 2013 17:38
Parse a string into a list of numbers
from itertools import *
def tonumberlist(s):
rc = []
def shouldtake(x):
return str.isdigit(x) or x=='.'
i = iter(s.replace(' ',''))
while True:
try:
rc.append(float(''.join(takewhile(shouldtake, i))))
@sbaer
sbaer / gist:4289649
Created December 14, 2012 23:45
C functions for ui test
#include "StdAfx.h"
// for Marlin UI Test
class CMarlinUiClass
{
};
typedef int (CALLBACK* GETBOOLVALUEPROC)(CMarlinUiClass* pClass, const RHMONO_STRING* name);
typedef void (CALLBACK* SETBOOLVALUEPROC)(CMarlinUiClass* pClass, const RHMONO_STRING* name, int value);
@sbaer
sbaer / gist:4047746
Created November 9, 2012 19:41
Move View in RhinoCommon
using System.Runtime.InteropServices;
public class MyCommand : Rhino.Commands.Command
{
//...other command stuff...
[DllImport("user32.dll")]
static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
@sbaer
sbaer / gist:3970130
Created October 28, 2012 22:13
marshaling points in RhinoCommon
// C++ portion
// Declare a struct that directly maps to an ON_3dPoint
struct ON_3DPOINT_STRUCT{ double val[3]; };
extern "C" __declspec(dllexport)
void ComputeMeshPoints(int resX, int resY, int resZ,
double* data_array, int data_count, double iso,
ON_3DPOINT_STRUCT min_corner, ON_3DPOINT_STRUCT max_corner,
ON_SimpleArray<ON_3dPoint>* output_points)
{
@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()
@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 / 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: