Skip to content

Instantly share code, notes, and snippets.

View sbaer's full-sized avatar

Steve Baer sbaer

View GitHub Profile
@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)
@sbaer
sbaer / CustomMeshCommand.cs
Created September 9, 2013 23:35
Debugging a Custom Mesh Problem
using System;
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
namespace examples_cs
{
[System.Runtime.InteropServices.Guid("476cc15c-8979-4325-8819-298024efbb56")]
public class CustomMeshCommand : Command
{
@sbaer
sbaer / gist:6543953
Created September 12, 2013 21:20
Scripting AttachGHSData with python
import rhinoscriptsyntax as rs
rs.UnselectAllObjects()
rs.Command('-AttachGHSData General Title "My Scripted Vessel" Enter')
id = rs.AddSphere((0,0,0), 30)
rs.SelectObject(id)
rs.Command('-AttachGHSData HullItems Add BySurface SelId ' + str(id) + 'Enter')
@sbaer
sbaer / gist:7938220
Created December 13, 2013 00:39
packing arguments as tuples and then unpacking them in the parallel function
import ghpythonlib.components as ghcomp
import ghpythonlib.parallel
#custom function that is executed by parallel.run
def slice_at_angle(args):
brep, plane = args #unpack input
result = ghcomp.BrepXPlane(brep, plane)
if result: return result.curves
if parallel:
@sbaer
sbaer / gist:b2ff6de6eda8b6d0a814
Last active June 24, 2016 09:58
Sample use of Eto and Rhino
using System;
using Eto.Forms;
using Eto.Drawing;
using Eto;
using System.Collections.Generic;
namespace EtoRhinoTests
{
public class EtoRhinoCommand : Rhino.Commands.Command
{
@sbaer
sbaer / monobuild.py
Created October 31, 2014 06:41
post build fie rename for RhinoCommon builds
"""
Post-Build script for RhinoCommon plug-in projects.
Make sure this file is in the same directory as your plug-in
project. In Xamarin Studio under project properties, add the following
to Custom Commands->After Build
python monobuild.py ${TargetFile}
Also make sure to set your project's build output to build to the MacPlugIns
directory
ex.
/Users/steve/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/HelloMonoPlugIn
@sbaer
sbaer / gist:d3b6660697812b444ead
Created June 19, 2015 05:38
Use OpenGL in Display Conduit
[CommandStyle(Style.Hidden)]
public class TestOpenGlCallCommand : Command
{
public override string EnglishName { get { return "TestGlCall"; } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
m_conduit.Enabled = !m_conduit.Enabled;
doc.Views.Redraw();
return Result.Success;
}
@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;
@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;
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