Skip to content

Instantly share code, notes, and snippets.

View sbaer's full-sized avatar

Steve Baer sbaer

View GitHub Profile
@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 / 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: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: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: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: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);
}
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 / 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"
@sbaer
sbaer / radial_contour.py
Created July 29, 2013 19:05
multi-threaded python sample
import System.Threading.Tasks as tasks
import Rhino
import rhinoscriptsyntax as rs
import time, math
import scriptcontext
def radial_contour(brep, parallel, slice_count=360):
"""Generate series of curve slices through a brep by rotating a plane
multiple times and intersecting that plane with the brep. This function
@sbaer
sbaer / useshapeways.py
Created July 29, 2013 19:08
shapeways sample
"""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"