AutoCAD.NET API2018二次开发第十二章

获取用户输入的字符串,输入的点,关键字,int以及向autocad发送命令

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//运行时
using Autodesk.AutoCAD.Runtime;
//数据库
using Autodesk.AutoCAD.DatabaseServices;
//应用程序服务
using Autodesk.AutoCAD.ApplicationServices;
//几何
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
//编辑输入
using Autodesk.AutoCAD.EditorInput;

namespace AutoDemo16
{
    public class Class1
    {
        //获取用户输入的字符串
        [CommandMethod("GerString")]
        public static void GerString()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            //获取数据库
            Database acDB = acDoc.Database;
            //提示输入字符串选项的变量
            PromptStringOptions pSo = new PromptStringOptions("\n输入字符串");
            //空格 允许有空格
            pSo.AllowSpaces = true;
            //输入的结果
            PromptResult pR = acDoc.Editor.GetString(pSo);
            //弹出字符串
            Application.ShowAlertDialog("\n你输入的字符串:"+ pR.ToString());
        }

        //获取输入的点
        [CommandMethod("GetPoint")]
        public static void GetPoint()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            //获取数据库
            Database acDB = acDoc.Database;
            //提示输入点
            PromptPointOptions pSo = new PromptPointOptions("");
            //提示
            pSo.Message = "请输入一个点";
            //输入的结果
            PromptPointResult pR = acDoc.Editor.GetPoint(pSo);
            //3d坐标点
            Autodesk.AutoCAD.Geometry.Point3d p3d = pR.Value;
            Application.ShowAlertDialog("x坐标:"+p3d.X.ToString()+"y坐标:"+p3d.Y.ToString());
        }

        //获取输入的关键词
        [CommandMethod("GetKey")]
        public static void GetKey()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            //获取数据库
            Database acDB = acDoc.Database;
            //提示输入Key
            PromptKeywordOptions pSo = new PromptKeywordOptions("");
            //提示
            pSo.Message = "请输入关键字";
            //添加关键字
            pSo.Keywords.Add("Line");
            pSo.Keywords.Add("Arc");
            //不允许输入空格
            pSo.AllowNone = false;
            //输入的结果
            PromptResult pR = acDoc.Editor.GetKeywords(pSo);
            //提示
            Application.ShowAlertDialog("输入的关键字:" + pR.StringResult);
            
        }


        //获取输入int
        [CommandMethod("GetInt")]
        public static void GetInt()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            //获取数据库
            Database acDB = acDoc.Database;
            //提示输入数字
            PromptIntegerOptions pSo = new PromptIntegerOptions("");
            //提示
            pSo.Message = "请输入数字";
            //不能是负数
            pSo.AllowNegative = false;
            //不能是 0
            pSo.AllowZero = false;
            //不允许输入空格
            pSo.AllowNone = true;
            //添加关键词
            pSo.Keywords.Add("Line");
            pSo.Keywords.Add("Arc");
            //默认
            pSo.Keywords.Default = "Arc";
            //输入的结果
            PromptIntegerResult pR = acDoc.Editor.GetInteger(pSo);
            //如果输入的是关键词
            if (pR.Status == PromptStatus.Keyword)
            {
                Application.ShowAlertDialog("输入的关键字:" + pR.StringResult);
            }
            else
            {
                //提示
                Application.ShowAlertDialog("输入的数值:" + pR.Value.ToString());
            }
        }

        //发送命令
        [CommandMethod("SendCommand")]
        public static void SendCommand()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Point2d pc = GetPointCommand();
            //发送命令
            string str = "._circle "+pc.X.ToString()+","+pc.Y.ToString()+" 10 ";

            //发送命令四个参数  命令,是否激活当前文档,是否将当前文档排入队列,是否在命令行中显示字符串
            acDoc.SendStringToExecute(str, true, false, true);
            //放大范围
            acDoc.SendStringToExecute("._zoom _e ", true, false, true);
            
        }


        public static Point2d GetPointCommand()
        {
            //获取当前文档
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            //点对象
            PromptPointOptions po = new PromptPointOptions("");

            po.Message = "\n输入圆心";
            
            //获取输入的结果
            PromptPointResult pre = acDoc.Editor.GetPoint(po);
            //用3d坐标点接收
            Point3d p3d = pre.Value;

            Point2d p2d = new Point2d(p3d.X, p3d.Y);

            return p2d;
        }

    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值