AutoCAD二次开发(.net教程)C#版——学习笔记(二)

选择点和计算两点的距离

选择点和计算两点的距离主要是通过PromptPointOptions和 PromptDistanceOptions两个类获取并通过PromptPointResult和 PromptDoubleResult两个类获取对象的值,最后通过Application.DocumentManager.MdiActiveDocument.Editor输入到CAD的命令窗口。

其中,PromptPointOptions类用来设置提示字符串和其他的一些控制提示的选项。两个功能的代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace SelectAPoint
{
    public class Class1
    {
        [CommandMethod("SelectAPoint")]
        public void SelectAPoint()
        {
            //实例化一个 PromptPointOptions类用来设置提示字符串和其他的一些控制提示
            PromptPointOptions prPointOptions = new PromptPointOptions("Select a point");
            PromptPointResult prPointRes;
            // 实例化一个Editor类,使用GetPoint方法返回
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            prPointRes = ed.GetPoint(prPointOptions);
            if (prPointRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("Error");
            }
            else
            {
                ed.WriteMessage("选择的点为:" + prPointRes.Value.ToString());
            }
        }
        [CommandMethod("getDistance")]
        public void GetDistance()
        {
            PromptDistanceOptions prDistOptions = new
            PromptDistanceOptions("计算两点距离,请选择第一个点:");
            PromptDoubleResult prDistRes;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            prDistRes = ed.GetDistance(prDistOptions);
            if (prDistRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("选择错误!");
            }
            else
            {
                ed.WriteMessage("两点的距离为:" + prDistRes.Value.ToString());
            }
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值