找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 637|回复: 2

[求助] 判断文字重叠精度问题

[复制链接]

已领礼包: 7个

财富等级: 恭喜发财

发表于 2020-7-4 15:32:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
请教一下各位大佬:
  我用 IntersectWith 判断相交来确定文字是否重叠, 现在的问题是怎么避免文字的包围盒相交问题。 怎么样使结果跟准确一点,符合人判断的结果。

或者有跟好的方法推荐一下。

微信图片_20200704152257.png

代码在下面:

  1. using AcDoNetTools;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.Runtime;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;


  12. namespace 文本重叠
  13. {
  14.     public class Class1
  15.     {
  16.         [CommandMethod("XZ_选择集")]
  17.         //[CommandMethod("XZ_选择集",CommandFlags.UsePickSet)] 支持先选择后操作
  18.         public void XZ_选择集()
  19.         {
  20.             Database db = HostApplicationServices.WorkingDatabase;
  21.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

  22.             PromptPointResult ppr = ed.GetPoint("\n请选择文字:");
  23.             if (ppr.Status != PromptStatus.OK) return;

  24.             PromptPointResult ppr2 = ed.GetCorner(new PromptCornerOptions("\n", ppr.Value));
  25.             if (ppr2.Status != PromptStatus.OK) return;


  26.             TypedValue[] values = new TypedValue[] {
  27.                 new TypedValue(0,"TEXT")
  28.             };
  29.             SelectionFilter filter = new SelectionFilter(values);

  30.             int jishu = 0;
  31.             int jishuline = 0;
  32.             int jishuset = 0;

  33.             Line line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));
  34.             Entity dBText;
  35.             Point3dCollection points = new Point3dCollection();
  36.             PromptSelectionResult psr;
  37.             SelectionSet sSet;
  38.             ObjectId[] ids;
  39.             using (Transaction trans = db.TransactionManager.StartTransaction())
  40.             {
  41.                 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  42.                 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

  43.                 for (int i = (int)ppr.Value.X; i < ppr2.Value.X; i += 1500)
  44.                 {
  45.                     for (int j = (int)ppr.Value.Y; j > ppr2.Value.Y; j -= 1500)
  46.                     {
  47.                         psr = ed.SelectCrossingWindow(new Point3d(i + 1500, j - 1500, 0), new Point3d(i, j, 0), filter);
  48.                         if (psr.Status == PromptStatus.OK)
  49.                         {
  50.                             sSet = psr.Value;
  51.                             ids = sSet.GetObjectIds();
  52.                             for (int x = 0; x < ids.Length; x++)
  53.                             {
  54.                                 if (ids[x] == line1.ObjectId) continue;
  55.                                 dBText = (Entity)ids[x].GetObject(OpenMode.ForRead);
  56.                                 for (int xx = x + 1; xx < ids.Length; xx++)
  57.                                 {
  58.                                     dBText.IntersectWith((DBText)ids[xx].GetObject(OpenMode.ForRead), Intersect.OnBothOperands,points, IntPtr.Zero, IntPtr.Zero);
  59.                                     //dBText.BoundingBoxIntersectWith
  60.                                     jishu++;
  61.                                 }
  62.                                 ids[x] = line1.ObjectId;
  63.                             }
  64.                         }
  65.                         jishuset++;
  66.                     }
  67.                 }
  68.                 for (int i = 0; i < points.Count; i+=2)
  69.                 {
  70.                     Line line0 = new Line(new Point3d(0, 0, 0), points);
  71.                     btr.AppendEntity(line0);
  72.                     trans.AddNewlyCreatedDBObject(line0, true);
  73.                     jishuline++;
  74.                 }
  75.                 trans.Commit();
  76.             }
  77.             ed.WriteMessage("重叠判断次数:" + jishu.ToString() + "\n");
  78.             ed.WriteMessage("直线数量:" + jishuline.ToString() + "\n");
  79.             ed.WriteMessage("选择集数量:" + jishuset.ToString() + "\n");
  80.         }
  81.     }
  82. }


测试文件.zip

1.07 MB, 下载次数: 2, 下载积分: D豆 -1 , 活跃度 1

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 19个

财富等级: 恭喜发财

发表于 2020-7-4 22:38:32 | 显示全部楼层
求实际的文本框,而不是实体的包围盒

点评

还请具体说明一下,要用到那几个函数啊,英语不行看文档找函数太麻烦了  详情 回复 发表于 2020-7-6 08:26
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 7个

财富等级: 恭喜发财

 楼主| 发表于 2020-7-6 08:26:58 | 显示全部楼层
Lisphk 发表于 2020-7-4 22:38
求实际的文本框,而不是实体的包围盒

还请具体说明一下,要用到那几个函数啊,英语不行看文档找函数太麻烦了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-10 19:52 , Processed in 0.358220 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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