本博客内容正在持续更新,最后一次更新时间:2020.08.09
【本文重点】
1.查文档:(1) RhinoCommon SDK (2) Grasshopper API
2.专栏地址:专栏:Rhino (Grasshopper) 二次开发 (C#)
推荐阅读:
【C#】:本文以介绍 Rhino, Grasshopper 的二次开发为主,具体有关 C# 语法的知识点欢迎参考 专栏:C#
【Grasshopper】:有关 Grasshopper 部分知识点和操作欢迎参考 专栏:Rhino (Grasshopper) 二次开发 (C#) 内的 Grasshopper 学习笔记
【视频教程】:本文部分内容来自油管教程 C# Scripting and Plugin Development for Grasshopper
1 Class in C# 组件
使用 Grasshopper 内置的 C# 组件可以就编写一个简单的类(关于该组件的知识点请查看 Rhino (Grasshopper) 二次开发 (C#) Part 1 - Introductions to the C# Coding in Grasshopper),如下图
但是这样创建的类有许多缺点,譬如 代码长度可能过长(不能分割成多个文件)、难以调试等,因此我们一般还是在 Visual Studio 中创建
2 Class in Plug-in
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino.Geometry;
namespace Workshop
{
class Pyramid
{
public Plane BasePlane;
public double Length;
public double Width;
public double Height;
// 构造函数
public Pyramid(Plane basePlane, double length, double height, double width)
{
BasePlane = basePlane;
Length = length;
Width = width;
Height = height;
}
// 求角锥体的 8 条棱
public List<LineCurve> ComputeDisplayLines()
{
Point3d A = BasePlane.Origin + BasePlane.XAxis * Length * 0.5 + BasePlane.YAxis * Width * 0.5;
Point3d B = BasePlane.Origin - BasePlane.XAxis * Length * 0.5 + BasePlane.YAxis * Width * 0.5;
Point3d C = BasePlane.Origin - BasePlane.XAxis * Length * 0.5 - BasePlane.YAxis * Width * 0.5;
Point3d D = BasePlane.Origin + BasePlane.XAxis * Length * 0.5 - BasePlane.YAxis * Width * 0.5;
Point3d M = BasePlane.Origin + BasePlane.ZAxis * Height;
List<LineCurve> displayLines = new List<LineCurve>();
displayLines.Add(new LineCurve(A, B));
displayLines.Add(new LineCurve(B, C));
displayLines.Add(new LineCurve(C, D));
displayLines.Add(new LineCurve(D, A));
displayLines.Add(new LineCurve(A, M));
displayLines.Add(new LineCurve(B, M));
displayLines.Add(new LineCurve(C, M));
displayLines.Add(new LineCurve(D, M));
return displayLines;
}
}
}
3 Debug in VS2019
3.1 设置
双击 Properties - 调试 - 启动外部程序,绑定 Rhino.exe 的路径