本帖最后由 qq1254582201 于 2024-9-25 16:51 编辑
- [CommandMethod("ISOL")]
- public static void IsolateSelection()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- var selection = ed.GetSelection();
- if (selection.Status != PromptStatus.OK)
- return;
- var ids = new HashSet<ObjectId>(selection.Value.GetObjectIds());
- using (var tr = new OpenCloseTransaction())
- {
- var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- foreach (ObjectId id in curSpace)
- {
- if (!ids.Contains(id))
- {
- var entity = (Entity)tr.GetObject(id, OpenMode.ForWrite);
- entity.Visible = false;
- }
- }
- tr.Commit();
- }
- }
- [CommandMethod("UNISOL")]
- public static void UnisolateAll()
- {
- var db = HostApplicationServices.WorkingDatabase;
- using (var tr = new OpenCloseTransaction())
- {
- var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- foreach (ObjectId id in curSpace)
- {
- var entity = (Entity)tr.GetObject(id, OpenMode.ForRead);
- if (!entity.Visible)
- {
- entity.UpgradeOpen();
- entity.Visible = true;
- }
- }
- tr.Commit();
- }
- }
- //Summary: Lets user select seed point -> Zooms Extent -> Selects Boundary set -> Isolates them -> Creates boundary -> Unisolates all -> Returns Boundaries
- public DBObjectCollection CreateBoundary(Transaction trans, BlockTableRecord btr, DBObjectCollection boundarySet, Point3d internalSeedPoint)
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- var ResultingBoundaries = new DBObjectCollection(); //Return
- var ResultingBoundaryIds = new ObjectIdCollection();
- try
- {
- //Summary: Isolate Boundary set -> Create boundary -> Unisolates Boundary set ;
- //Isolate the boundarySet entities.
- var hiddenEntities = new List<Entity>();
- foreach (ObjectId id in btr)
- {
- var entity = (Entity)trans.GetObject(id, OpenMode.ForWrite);
- if (boundarySet.Contains(entity))
- {
- entity.Visible = true;
- }
- else
- {
- entity.Visible = false;
- hiddenEntities.Add(entity);
- }
- }
- //Creating and adding boundary objects to the drawing. Also collecting its ObjectIds for later use.
- //Tracing the bondary out of input curves. Here InternalSeedPoint is a point inside the boundary that is going to be generated.
- ResultingBoundaries = ed.TraceBoundary(internalSeedPoint, false);
- //Appending the boundary to the databse
- foreach (Polyline boundary in ResultingBoundaries)
- {
- btr.AppendEntity(boundary);
- trans.AddNewlyCreatedDBObject(boundary, true);
- //Collecting ResultingBoundaryIds for later use (if required)
- ResultingBoundaryIds.Add(boundary.ObjectId);
- }
- //Unisolate the boundarySet entities.
- foreach (Entity entity in hiddenEntities)
- {
- entity.Visible = true;
- }
- }
- catch (Exception ex)
- {
- Application.ShowAlertDialog("Error: " + ex.Message);
- }
- return ResultingBoundaries;
- }
- public void MakeSelection(DBObjectCollection selectedObjects)
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- ObjectId[] selectedObjIds = new ObjectId[selectedObjects.Count];
- for (int i = 0; i < selectedObjects.Count; i++)
- {
- selectedObjIds[i] = selectedObjects[i].ObjectId;
- }
- //Mark selection on the drawing
- ed.SetImpliedSelection(selectedObjIds);
- }
复制代码
- public static void IsolateSelection()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- var selection = ed.GetSelection();
- if (selection.Status != PromptStatus.OK) return;
- var ids = new HashSet<ObjectId>(selection.Value.GetObjectIds());
- using (var tr = new OpenCloseTransaction())
- {
- var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- foreach (ObjectId id in curSpace)
- {
- if (!ids.Contains(id))
- {
- var entity = (Autodesk.AutoCAD.DatabaseServices.Entity)tr.GetObject(id, OpenMode.ForWrite);
- entity.Visible = false;
- }
- }
- tr.Commit();
- }
- }
- public static void UnisolateAll()
- {
- var db = HostApplicationServices.WorkingDatabase;
- using (var tr = new OpenCloseTransaction())
- {
- var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- foreach (ObjectId id in curSpace)
- {
- var entity = (Autodesk.AutoCAD.DatabaseServices.Entity)tr.GetObject(id, OpenMode.ForWrite);
- if (!entity.Visible)
- {
- //curSpace.DowngradeOpen();
- //entity.UpgradeOpen();
- entity.Visible = true;
- //entity.DowngradeOpen(); //Temporarily Added.
- }
- }
- tr.Commit();
- }
- }
|