明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1214|回复: 2

c#拾取CAD中单行文字

[复制链接]
发表于 2011-1-20 13:44 | 显示全部楼层 |阅读模式
通过选择集选择文字
1.怎样判断相同文字
2.在命令行中显示不同文字的数量
望高手赐教 谢谢
发表于 2011-1-21 08:49 | 显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2011-1-21 08:50 编辑

简单的流程就是先建一个string-int的键值对字典
然后遍历,每发现一个新的字串就在字典中加入一项
否则就在字典的原有项上加一
下面是Linq的方法
结果:

  1.         [CommandMethod("t2")]
  2.         public static void Test2()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;

  7.             var resSel = ed.SelectAll(new ResultList { { 0, "text" } });
  8.             if (resSel.Status != PromptStatus.OK)
  9.                 return;

  10.             using (var tr = db.TransactionManager.StartTransaction())
  11.             {
  12.                 var q =
  13.                     resSel.Value.GetObjectIds()
  14.                     .Select(id => tr.GetObject(id, OpenMode.ForRead) as DBText)
  15.                     .GroupBy(t => t.TextString)
  16.                     .Select(txts => new { txts.Key, Count = txts.Count() })
  17.                     .OrderBy(t => t.Key);

  18.                 foreach (var t in q)
  19.                 {
  20.                     ed.WriteMessage("\n内容:{0}数量:{1}", t.Key, t.Count);
  21.                 }

  22.             }
  23.         }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2011-1-22 09:32 | 显示全部楼层
感谢飞狐大哥
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-29 02:41 , Processed in 0.201547 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表