- UID
- 777355
- 积分
- 180
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2018-7-10
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
请教一下各位大佬:
我用 IntersectWith 判断相交来确定文字是否重叠, 现在的问题是怎么避免文字的包围盒相交问题。 怎么样使结果跟准确一点,符合人判断的结果。
或者有跟好的方法推荐一下。
代码在下面:
- using AcDoNetTools;
- 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;
- using System.Text;
- using System.Threading.Tasks;
- namespace 文本重叠
- {
- public class Class1
- {
- [CommandMethod("XZ_选择集")]
- //[CommandMethod("XZ_选择集",CommandFlags.UsePickSet)] 支持先选择后操作
- public void XZ_选择集()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- PromptPointResult ppr = ed.GetPoint("\n请选择文字:");
- if (ppr.Status != PromptStatus.OK) return;
- PromptPointResult ppr2 = ed.GetCorner(new PromptCornerOptions("\n", ppr.Value));
- if (ppr2.Status != PromptStatus.OK) return;
- TypedValue[] values = new TypedValue[] {
- new TypedValue(0,"TEXT")
- };
- SelectionFilter filter = new SelectionFilter(values);
- int jishu = 0;
- int jishuline = 0;
- int jishuset = 0;
- Line line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));
- Entity dBText;
- Point3dCollection points = new Point3dCollection();
- PromptSelectionResult psr;
- SelectionSet sSet;
- ObjectId[] ids;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- for (int i = (int)ppr.Value.X; i < ppr2.Value.X; i += 1500)
- {
- for (int j = (int)ppr.Value.Y; j > ppr2.Value.Y; j -= 1500)
- {
- psr = ed.SelectCrossingWindow(new Point3d(i + 1500, j - 1500, 0), new Point3d(i, j, 0), filter);
- if (psr.Status == PromptStatus.OK)
- {
- sSet = psr.Value;
- ids = sSet.GetObjectIds();
- for (int x = 0; x < ids.Length; x++)
- {
- if (ids[x] == line1.ObjectId) continue;
- dBText = (Entity)ids[x].GetObject(OpenMode.ForRead);
- for (int xx = x + 1; xx < ids.Length; xx++)
- {
- dBText.IntersectWith((DBText)ids[xx].GetObject(OpenMode.ForRead), Intersect.OnBothOperands,points, IntPtr.Zero, IntPtr.Zero);
- //dBText.BoundingBoxIntersectWith
- jishu++;
- }
- ids[x] = line1.ObjectId;
- }
- }
- jishuset++;
- }
- }
- for (int i = 0; i < points.Count; i+=2)
- {
- Line line0 = new Line(new Point3d(0, 0, 0), points);
- btr.AppendEntity(line0);
- trans.AddNewlyCreatedDBObject(line0, true);
- jishuline++;
- }
- trans.Commit();
- }
- ed.WriteMessage("重叠判断次数:" + jishu.ToString() + "\n");
- ed.WriteMessage("直线数量:" + jishuline.ToString() + "\n");
- ed.WriteMessage("选择集数量:" + jishuset.ToString() + "\n");
- }
- }
- }
|
-
-
测试文件.zip
1.07 MB, 下载次数: 2, 下载积分: D豆 -1 , 活跃度 1
|