当前位置: 首页 > news >正文

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

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.mrgr.cn/news/46051.html

相关文章:

  • YOLOv5改进——添加SimAM注意力机制
  • 通过Fiddler抓包采集某音作品列表,视频列表
  • 数学建模算法与应用 第1章 线性规划
  • AI视频技术如何应用在电影制作中,十大应用方向+商业案例告诉你
  • WebGIS包括哪些技术栈?怎么学习?
  • npm install报错一堆gyp ERR!
  • 如果表格中包含手写文字,表格识别工具的识别效果会受到影响吗?
  • 芯片复位电路-RC复位
  • QRTCN区间预测 | Matlab实现QRTCN时间卷积神经网络分位数回归区间预测
  • 58.完全二叉树的节点个数
  • 10.8Python数学基础-函数与极限
  • YOLO11实战:解决创新点在自己数据集不涨点现象,通过EMA多尺度注意力举例阐述并提出解决方案(NEU-DET缺陷检测)
  • 行业内卷化,家居老板如何利用AI换道超车?10月17日重庆站,AI营销第一课给你答案
  • Heroic Key to the Focusing Iris
  • 电子会议桌牌:现代会议室的智能化变革
  • CLIP图文多模态模型onnxruntime和tensorrt推理
  • GoJsonQ 学习与使用指南
  • 作业4-23
  • SQL调优指南及高级SQL技巧
  • QString与进制数互相转换