Example #1
0
        public static void SelectHolePolygons()
        {
            var    objectIds = new ObjectId[0];
            Editor ed        = Application.DocumentManager.MdiActiveDocument.Editor;

            objectIds = ed.GetSelection().Value.GetObjectIds();
            if (objectIds.Count() == 0)
            {
                //过滤选择polyline
                var tvs = new[]
                {
                    new TypedValue((int)DxfCode.Operator, "<or"),
                    new TypedValue((int)DxfCode.Start, "LWPOLYLINE"),
                    new TypedValue((int)DxfCode.Start, "POLYLINE"),
                    new TypedValue((int)DxfCode.Operator, "or>")
                };
                var filter        = new SelectionFilter(tvs);
                var selectionOpts = new PromptSelectionOptions();

                var currDoc = Application.DocumentManager.MdiActiveDocument;
                //选择polyline
                PromptSelectionResult result = currDoc.Editor.GetSelection(selectionOpts, filter);
                if (result.Status == PromptStatus.OK || result.Value.Count >= 1)
                {
                    objectIds = result.Value.GetObjectIds();
                }
            }

            //
            if (objectIds.Count() > 0)
            {
                var      count    = objectIds.Count();
                Document document = Application.DocumentManager.MdiActiveDocument;
                //int count = SetHolePolygons(document.Database, objectIds);
                document.Editor.WriteMessage("将{0}个多边形设定为扣除面积的图形", count);
            }
        }
Example #2
0
        public static void SelectHoleToRemoveArea()
        {
            var      holeIds  = new ObjectId[0];
            ObjectId parcelId = ObjectId.Null;
            Document document = Application.DocumentManager.MdiActiveDocument;

            document.Editor.WriteMessage("\n选择需要扣除面积的孔洞: ");
            var result = StartSelectPolyline(false);

            if (result.Status != PromptStatus.OK)
            {
                return;
            }

            // 洞
            if (result.Value.Count >= 1)
            {
                holeIds = result.Value.GetObjectIds();
            }

            // 检查地块是否封闭
            using (var tr = document.Database.TransactionManager.StartTransaction())
            {
                foreach (var objectId in holeIds)
                {
                    var curve = tr.GetObject(objectId, OpenMode.ForRead) as Curve;
                    if (curve != null && !curve.Closed)
                    {
                        document.Editor.WriteMessage("\n错误:选择的孔洞不封闭");
                        return;
                    }
                }
            }

            // 外边界
            Point3d pickedPoint;

            if (!SelectPolylineEntity("\n选择要扣除面积的地块界线: ", "\n实体错误", out parcelId, out pickedPoint) ||
                parcelId == ObjectId.Null)
            {
                return;
            }

            // 检查地块是否封闭
            using (var tr = document.Database.TransactionManager.StartTransaction())
            {
                var curve = tr.GetObject(parcelId, OpenMode.ForRead) as Curve;
                if (curve != null && !curve.Closed)
                {
                    document.Editor.WriteMessage("\n错误:选择的地块界线不封闭");
                    return;
                }
            }

            // 如果地块是合适的
            if (parcelId.IsValid && holeIds.Any())
            {
                foreach (var objectId in holeIds)
                {
                    if (objectId == parcelId)
                    {
                        document.Editor.WriteMessage("\n错误:句柄为{0}的孔洞与地块边界相同", objectId.Handle);
                        return;
                    }

                    if (!WithIn(objectId, parcelId))
                    {
                        document.Editor.WriteMessage("\n错误:句柄为{0}的孔洞不在地块边界内部", objectId.Handle);
                        return;
                    }
                }

                // 新增孔洞到地块
                var parcel = new ParcelPolygon(parcelId);
                parcel.AddHoleIds(holeIds);
                document.Editor.WriteMessage("\n将{0}个多边形设定为扣除面积的孔洞", holeIds.Count());
            }
        }