Grasshopper 二次开发 (C#) Part 4 - Write Your Own Class

本博客内容正在持续更新,最后一次更新时间: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 的路径
在这里插入图片描述

3.2

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖留名

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值