008集—— Keyword关键字及getstring的用法(CAD—C#二次开发入门)

server/2024/10/17 20:51:18/

CAD二开中,经常会用到用户交互功能,常见的方法如下:

GetKeyword 方法提示用户在 AutoCAD 命令提示下输入关键字,GetString 方法提示用户在 AutoCAD 命令提示下输入字符串。两者就有区别又有相似处,getkeyword只允许用户输入指定的字符。

GetKeyword 方法:AllowNone 属性为False强制用户输入关键字,而禁止输入 NULL(按回车键)。Keywords 用于添加有效的关键字列表。

GetString 方法:该方法接收两个参数。PromptStringOptions 对象允许控制用户输入以及怎样显示提示信息。PromptStringOptions 对象的 AllowSpaces 属性控制是否允许输入空格。如果为 False ,按空格键将中止用户输入。

getkeyword案例如下:

 

附代码: 

using AcTools;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;namespace Acdemo
{public  class Acdemo{[CommandMethod("xx")]public void ACDE(){Document acDoc = Application.DocumentManager.MdiActiveDocument;Database db = HostApplicationServices.WorkingDatabase;Line line = new Line(Point3d.Origin, new Point3d(100, 100, 0));Line line1 = new Line(Point3d.Origin, new Point3d(50, 200, 0));//db.AddEntityToModeSpace(line);PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");pKeyOpts.Message = "\nEnter an option ";pKeyOpts.Keywords.Add("Line");pKeyOpts.Keywords.Add("Circle");pKeyOpts.Keywords.Add("Arc");pKeyOpts.AllowNone = false;PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts);//Application.ShowAlertDialog("Entered keyword: " +//                            pKeyRes.StringResult);//if (pKeyRes.StringResult == "Line")//{//    db.AddLineToModeSpace(new Point3d(), new Point3d(100, 100, 0));//}switch (pKeyRes.StringResult){case "Line":Database db1 = HostApplicationServices.WorkingDatabase;db1.AddEntityToModeSpace(line1);break;case "Circle":db.AddCircleModeSpace(new Point3d(), 100);break;case "Arc":db.AddArcToModeSpace(new Point3d(0,0,0), new Point3d(500, 100, 0), new Point3d(200, 200, 0));break;}}}
}

getstring用法:

using AcTools;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;namespace Acdemo
{public  class Acdemo{public static void GetStringFromUser(string message){Document acDoc = Application.DocumentManager.MdiActiveDocument;PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter your name: ");pStrOpts.AllowSpaces = true;PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);Application.ShowAlertDialog(message +  "\nThe name entered was: " +pStrRes.StringResult);}[CommandMethod("xx")]public void ACDE(){  GetStringFromUser("Hello,world !");}}
}


http://www.ppmy.cn/server/131230.html

相关文章

RTSP与ONVIF协议的区别及其在EasyCVR视频汇聚平台中的应用

在视频监控和物联网设备领域,RTSP(Real Time Streaming Protocol)和ONVIF(Open Network Video Interface Forum)是两个重要的协议,它们各自在视频流的传输和控制上发挥着不同的作用,并在实际应用…

【2025】springboot贫困地区捐助系统(源码+文档+调试+答疑)

🍅 简介:2000精品计算机源码学习 🍅 欢迎点赞 👍 收藏 ⭐留言 📝 文末获取源码 目录 一、以下学习内容欢迎领取: 二、文档资料截图: 三想了解更多,请收藏、评论、留言&#xff1a…

安装openai-whisper 失败

昨晚安装python 语音识别模型经常失败: pip install openai-whisper 具体原因是因为国外的源使网络不稳定造成断网 查阅资料我自己的解决办法是在自己C:\Users\用户名目录下建一个pip文件夹,在pip文件夹下建一个pip.ini文件 在pip.ini文件中加入自己要…

C++ ----Qt

1.什么是QT Qt是一个跨平台的C应用程序开发框架。 用于开发图形用户界面、嵌入式系统、以及其他应用程序(嵌入式,桌面,汽车中控),支持Windows、macOS、Linux、Android和iOS等多个操作系统。 Qt框架提供了丰富的功能…

安装和配置k8s可视化UI界面dashboard-1.20.6

安装和配置k8s可视化UI界面dashboard-1.20.6 1.环境规划2.初始化服务器1)配置主机名2)设置IP为静态IP3)关闭selinux4)配置主机hosts文件5)配置服务器之间免密登录6)关闭交换分区swap,提升性能7&…

Java并发安全容器(超级详解版)

在Java1.5以前,并发安全容器有以下几种: Vector:线程安全的容器。它的具体使用方式与 ArrayList 相似,其内部实现的原理是在方法层面上增加 synchronized 来实现线程安全。我们简单看一下源码: public synchronized …

SpringCloud-服务治理-Eureka

本篇是从基础方便讲解一些springcloud-服务治理-Eureka中的一些理论性的故事;具体的代码不详细展示;后面的文章会将源码进行整理,并且将源码的github地址上传。 1.什么是服务治理 专治分布式系统 (一)高可用性:服务治理框架保证…

【Golang】Go语言Seeker接口与文件断点续传实战

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,…