CAD二次开发获取输入的关键字 ed.GetKeywords

本文介绍了CAD二次开发中获取用户输入的关键字功能,特别是函数ed.GetKeywords的使用。通过Add方法的三个重载形式设置globalName、localName和displayName,其中displayName用于编辑器内显示,globalName作为后台获取输入值,而localName的作用相对较弱。
摘要由CSDN通过智能技术生成
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database db = acDoc.Database;
            Editor ed = acDoc.Editor;
            PromptKeywordOptions promptKeywordOptions 
要使用C#CAD2019进行二次开发获取块属性,可以使用AutoCAD .NET API。以下是获取块属性的示例代码: ```csharp // 获取当前文档 Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; // 获取当前文档的数据库 Database db = doc.Database; // 获取当前文档的编辑器 Editor ed = doc.Editor; // 提示用户选择块 PromptEntityOptions peo = new PromptEntityOptions("\n请选择块:"); peo.SetRejectMessage("\n只能选择块!"); peo.AddAllowedClass(typeof(BlockReference), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status == PromptStatus.OK) { // 打开块事务 using (Transaction trans = db.TransactionManager.StartTransaction()) { // 获取块对象 BlockReference blkRef = trans.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference; if (blkRef != null) { // 获取块定义对象 BlockTableRecord btr = trans.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; if (btr != null) { // 获取块属性定义集合 AttributeDefinitionCollection attDefs = btr.AttributeCollection; foreach (ObjectId attDefId in attDefs) { AttributeDefinition attDef = trans.GetObject(attDefId, OpenMode.ForRead) as AttributeDefinition; if (attDef != null && !attDef.Constant) { // 获取块属性值 AttributeReference attRef = new AttributeReference(); attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform); ed.WriteMessage($"\n{attDef.Tag}: {attRef.TextString}"); } } } } // 提交块事务 trans.Commit(); } } ``` 以上代码通过选择块,获取块定义对象,遍历块属性定义集合,获取块属性值,并在命令行中输出属性名和属性值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

三好学生~张旺

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

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

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

打赏作者

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

抵扣说明:

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

余额充值