马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- [CommandMethod("searchregion")]
- public void GetIntersectRegion()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- TypedValue[] values = new TypedValue[3]
- {
- new TypedValue(0, "*POLYLINE"),
- new TypedValue( -4,"&="),
- new TypedValue( 70 ,0)
- };
- PromptSelectionOptions pso = new PromptSelectionOptions();
- pso.MessageForAdding = "Select Closed Polyline";
- PromptSelectionResult psr = ed.GetSelection(pso, new SelectionFilter(values));
- if (psr.Status != PromptStatus.OK)
- {
- return;
- }
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- try
- {
- SelectionSet ss = psr.Value;
- ObjectId[] ids = ss.GetObjectIds();
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- for (int i = 0; i < ids.Length; i++)
- {
- Entity ent1 = (Entity)ids[i].GetObject(OpenMode.ForRead);
- Extents3d ext1 = ent1.GeometricExtents;
- for (int j = i + 1; j < ids.Length; j++)
- {
- Entity ent2 = (Entity)ids[j].GetObject(OpenMode.ForRead);
- Extents3d ext2 = ent2.GeometricExtents;
- if (RectIntersects(ext1, ext2))
- {
- DBObjectCollection cvs = new DBObjectCollection();
- cvs.Add(ent1);
- cvs.Add(ent2);
- DBObjectCollection regions = Region.CreateFromCurves(cvs);
- Region reg1 = (Region)regions[0];
- Region reg2 = (Region)regions[1];
- //reg2 dis
- reg1.BooleanOperation(BooleanOperationType.BoolIntersect, reg2);
- reg1.ColorIndex = 1;
- btr.AppendEntity(reg1);
- tr.AddNewlyCreatedDBObject(reg1, true);
- }
- }
- }
- tr.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- private static bool RectIntersects(Extents3d first, Extents3d second)
- {
- bool one = second.MinPoint.X < first.MaxPoint.X &&
- first.MinPoint.X < second.MaxPoint.X &&
- second.MinPoint.Y < first.MaxPoint.Y &&
- first.MinPoint.Y < second.MaxPoint.Y;
- bool two = first.MinPoint.X < second.MaxPoint.X &&
- second.MinPoint.X < first.MaxPoint.X &&
- first.MinPoint.Y < second.MaxPoint.Y &&
- second.MinPoint.Y < first.MaxPoint.Y;
- return one | two;
- }
|