Rhino插件开发-拾取Rhino对象

  在Rhino实现拾取功能,我们先创建一个Commands;

      该Commands名称为"ceshi",命令没有被实现的时候会在Rhino命令行输出“未实现ceshi命令。 ”提示。

using System.Windows.Forms;
using Rhino;
using Rhino.Commands;
using RhinoWindows;

namespace CowForRhinoWinForms.Commands
{
    [System.Runtime.InteropServices.Guid("GUID")]
    public class CowForRhinoModalFormCommand : Command
    {
        public override string EnglishName
        {
            get { return "ceshi"; }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var rc = Result.Cancel;
            if (mode == RunMode.Interactive)
            {
                //将在这里写拾取对象功能
            }
            else
            {
                var msg = string.Format("未实现 {0} 命令。 ", EnglishName);
                RhinoApp.WriteLine(msg);
            }
            return rc;
        }
    }
}

       拾取对象由Rhino.Input.Custom命名空间下的类来实现对应的拾取操作。例如GetPoint类是拾取Point的,GetLine类是拾取Line的等等。我们用GetLine做一个应用:

GetLine g = new  GetLine();
g.SetCommandPrompt("选择一个直线");
g.Get();
if (g.CommandResult() == Result.Success)
{
  Line line = g.Line();
  // 这里添加更多命令
  .....
  // 这里添加更多命令  
  RhinoApp.WriteLine("直线拾取成功!"); 
} 
else 
{ 
  RhinoApp.WriteLine("直线拾取不成功!"); 
}

      将上面代码添加到if内,实现拾取一个直线的功能,完成拾取操作后将直线赋给line 然后在命令行输出"直线拾取成功!"提示,没有拾取正确类型的对象或取消操作时会在命令行输出"直线拾取成功!"提示。示例中并没有在拾取line后继续实现其他功能,大家可以根据自己的需求添加相应操作,比如获取line的长度、起始点、终点等信息,将它们输出到rhino命令行。

      上面的功能完整代码如下:

using System.Windows.Forms;
using Rhino;
using Rhino.Commands;
using RhinoWindows;

namespace CowForRhinoWinForms.Commands
{
    [System.Runtime.InteropServices.Guid("GUID")]
    public class CowForRhinoModalFormCommand : Command
    {
        public override string EnglishName
        {
            get { return "ceshi"; }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var rc = Result.Cancel;
            if (mode == RunMode.Interactive)
            {
                //将在这里写拾取对象功能
               GetLine g = new  GetLine();
               g.SetCommandPrompt("选择一个直线");
               g.Get();
               if (g.CommandResult() == Result.Success)
               {
                  Line line = g.Line();
                  // 这里添加更多命令
                  .....
                  // 这里添加更多命令  
                  RhinoApp.WriteLine("直线拾取成功!"); 
               } 
               else 
               { 
                  RhinoApp.WriteLine("直线拾取不成功!"); 
               }
            }
            else
            {
                var msg = string.Format("未实现 {0} 命令。 ", EnglishName);
                RhinoApp.WriteLine(msg);
            }
            return rc;
        }
    }
}

扫码加入群聊,一起寻找Rhino开发乐趣!   

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

quejingchang

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

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

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

打赏作者

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

抵扣说明:

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

余额充值