private _Db.DBObjectCollection getGeometry() { _Db.DBObjectCollection geometry = new _Db.DBObjectCollection(); _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions(); opts.MessageForAdding = "\nSelect Geometry: "; _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts); if (userSelection.Status != _Ed.PromptStatus.OK) { throw new DMTException("[ERROR] Geometry - cancelled"); } _Ed.SelectionSet selectionSet = userSelection.Value; foreach (_Ed.SelectedObject currentObject in selectionSet) { if (currentObject == null) { continue; } _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity; if (currentEntity == null) { continue; } if (currentEntity is _Db.Curve) { geometry.Add(currentEntity); } } return(geometry); }
public static void SelectObjects(AcDb.ObjectIdCollection objectIds) { using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcEd.PromptSelectionResult psr = ed.GetSelection(); if (psr.Status == AcEd.PromptStatus.OK) { AcEd.SelectionSet SSet = psr.Value; foreach (AcEd.SelectedObject SObj in SSet) { if (SObj != null) { AcDb.Entity entityObject = tr.GetObject(SObj.ObjectId, AcDb.OpenMode.ForWrite) as AcDb.Entity; if (entityObject != null) { foreach (AcDb.ObjectId idObj in objectIds) { if (idObj.Equals(entityObject.ObjectId)) { entityObject.Highlight(); } } } } } // Save the new object to the database tr.Commit(); } } }
private List <_AcDb.ObjectId> GetFgAnz(_AcGe.Point3d minExt, _AcGe.Point3d maxExt, _AcDb.ObjectId elFG) { List <_AcDb.ObjectId> Ret = new List <_AcDb.ObjectId>(); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"), new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, _FgLayer) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); //res = ed.SelectAll(filter); if (res.Status != _AcEd.PromptStatus.OK) { // todo: logging: lot4net? return(Ret); } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; if (!oid.Equals(elFG)) { if (PolyInPoly(tm, oid, elFG)) { AddRbToRetCol(Ret, tm, oid); } } } myT.Commit(); } finally { myT.Dispose(); } } return(Ret); }
private void AddRbToRetCol(List <_AcDb.ObjectId> Ret, _AcDb.TransactionManager tm, _AcDb.ObjectId elFG) { _AcDb.Extents3d ext = GetExtents(tm, elFG); _AcGe.Point3d minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z); _AcGe.Point3d maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z); _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName, _RaumblockName) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); if (res.Status != _AcEd.PromptStatus.OK) { // todo: logging: lot4net? return; } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false)) { using (_AcDb.Entity entElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity) { if (pEntity is _AcDb.BlockReference) { _AcDb.BlockReference br = pEntity as _AcDb.BlockReference; if (AreaEngine.InPoly(br.Position, entElFG)) { Ret.Add(oid); } } } } } } }
private bool SelectBlocks() { var ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), }); _AcEd.PromptSelectionResult res = ed.SelectAll(filter); //if (res.Status != _AcEd.PromptStatus.OK) return false; List <_AcDb.ObjectId> selectedBlocks = new List <_AcDb.ObjectId>(); #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { if (ss == null) { return(false); } selectedBlocks.AddRange(ss.GetObjectIds().ToList()); } var doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (var trans = doc.TransactionManager.StartTransaction()) { _BlocksForExcelExport = selectedBlocks.Where(oid => IsBlockToUse(oid, trans, _BlockName)).ToList(); trans.Commit(); } log.InfoFormat("Anzahl gefundener Blöcke namens '{0}': {1}.", _BlockName, _BlocksForExcelExport.Count.ToString()); if (_BlocksForExcelExport.Count > 0) { return(true); } else { return(false); } }
private List <_AcDb.ObjectId> SelectRaumBlocks() { string hkBlockName = RaumBlockName; var ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), //new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName,hkBlockName) }); _AcEd.PromptSelectionResult res = ed.GetSelection(filter); if (res.Status != _AcEd.PromptStatus.OK) { return(new List <_AcDb.ObjectId>()); } #if BRX_APP SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { List <_AcDb.ObjectId> theBlockOids = new List <_AcDb.ObjectId>(); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcDb.Transaction myT = doc.TransactionManager.StartTransaction()) { var lstBlocks = ss.GetObjectIds(); foreach (var oid in lstBlocks) { var br = myT.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; if (br != null && string.Compare(Plan2Ext.Globs.GetBlockname(br, myT), hkBlockName, StringComparison.OrdinalIgnoreCase) == 0) { theBlockOids.Add(oid); } } myT.Commit(); } return(theBlockOids); //return ss.GetObjectIds().ToList(); } }
private List <_AcDb.ObjectId> selRB(_AcGe.Point3d minExt, _AcGe.Point3d maxExt) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName, _RaumblockName) }); _AcEd.PromptSelectionResult res = null; res = ed.SelectCrossingWindow(minExt, maxExt, filter); if (res.Status != _AcEd.PromptStatus.OK) { log.Warn("Fehler beim Auswählen der Raumblöcke!"); return(new List <_AcDb.ObjectId>()); } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { return(ss.GetObjectIds().ToList()); } }
internal bool SelectFgAndRb(List <_AcDb.ObjectId> flaechenGrenzen, List <_AcDb.ObjectId> raumBloecke, string fgLayer, string rbName) { flaechenGrenzen.Clear(); raumBloecke.Clear(); log.Debug("Auswahl Flächengrenzen und Raumblöcke"); _AcEd.PromptSelectionResult res = null; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<OR"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"), new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, fgLayer), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), //new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName ,rbName ), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "OR>") }); _AcEd.PromptSelectionOptions SelOpts = new _AcEd.PromptSelectionOptions(); SelOpts.MessageForAdding = "Raumblöcke und Flächengrenzen wählen: "; res = _Editor.GetSelection(SelOpts, filter); if (res.Status != _AcEd.PromptStatus.OK) { log.Debug("Auswahl wurde abgebrochen."); if (res.Status == _AcEd.PromptStatus.Cancel) { return(false); } else { return(true); } } #if BRX_APP _AcEd.SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { _AcDb.ObjectId[] idArray = ss.GetObjectIds(); _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { for (int i = 0; i < idArray.Length; i++) { _AcDb.ObjectId oid = idArray[i]; using (_AcDb.DBObject dbobj = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity) { _AcDb.Entity ent = dbobj as _AcDb.Entity; if (ent != null) { if (ent is _AcDb.BlockReference) { if (string.Compare(rbName, Plan2Ext.Globs.GetBlockname((_AcDb.BlockReference)ent, myT), StringComparison.OrdinalIgnoreCase) == 0) { raumBloecke.Add(oid); } } else { flaechenGrenzen.Add(oid); } } } } myT.Commit(); } finally { myT.Dispose(); } } log.DebugFormat(CultureInfo.CurrentCulture, "Auswahl: Raumblöcke {0}, Flächengrenzen {1}", raumBloecke.Count, flaechenGrenzen.Count); return(true); }
private List <G.Line> getGeometry() { List <G.Line> polys = new List <G.Line>(); _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions(); opts.MessageForAdding = "\nSelect Geometry: "; _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts); if (userSelection.Status != _Ed.PromptStatus.OK) { throw new DMTException("[ERROR] Geometry - cancelled"); } _Ed.SelectionSet selectionSet = userSelection.Value; foreach (_Ed.SelectedObject currentObject in selectionSet) { if (currentObject == null) { continue; } _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity; if (currentEntity == null) { continue; } if (currentEntity is _Db.Polyline) { _Db.Polyline poly = _c.trans.GetObject(currentEntity.ObjectId, _Db.OpenMode.ForRead) as _Db.Polyline; int points = poly.NumberOfVertices; for (int i = 1; i < points; i++) { _Ge.Point2d p1 = poly.GetPoint2dAt(i - 1); _Ge.Point2d p2 = poly.GetPoint2dAt(i); G.Point new_p1 = new G.Point(p1.X, p1.Y); G.Point new_p2 = new G.Point(p2.X, p2.Y); if (new_p1 == new_p2) { continue; } G.Line line = new G.Line(new_p1, new_p2); if (!polys.Contains(line)) { polys.Add(line); } } if (poly.Closed) { _Ge.Point2d p1 = poly.GetPoint2dAt(points - 1); _Ge.Point2d p2 = poly.GetPoint2dAt(0); G.Point new_p1 = new G.Point(p1.X, p1.Y); G.Point new_p2 = new G.Point(p2.X, p2.Y); if (new_p1 == new_p2) { continue; } G.Line line = new G.Line(new_p1, new_p2); if (!polys.Contains(line)) { polys.Add(line); } } } } if (polys.Count < 3) { throw new DMTException("[ERROR] Geometry - less then 3"); } return(polys); }