private static DBObjectCollection SuperExplode(BlockReference bf, BlockTableRecord modelspace) { var result = new DBObjectCollection(); bf.UpgradeOpen(); var objSet = new DBObjectCollection(); bf.Explode(objSet); foreach (var obj in objSet) { var id = modelspace.AppendEntity(obj as Entity); var ent = id.GetObject(OpenMode.ForRead); if (ent is BlockReference) { ent.UpgradeOpen(); var col = SuperExplode(obj as BlockReference, modelspace); foreach (var explodedObj in col) { result.Add(explodedObj as DBObject); } } else { result.Add(obj as Entity); } } bf.Erase(); return(result); }
public static void InserBlock(Database db, bool bExploded, BlockReference blockRefToInsert) { using (Transaction trans = db.TransactionManager.StartTransaction()) { try { Document Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; using (DocumentLock dl = Doc.LockDocument()) { BlockTableRecord currSpace = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; if (bExploded) { DBObjectCollection objColl = new DBObjectCollection(); blockRefToInsert.Explode(objColl); foreach (DBObject obj in objColl) { currSpace.AppendEntity(obj as Entity); trans.AddNewlyCreatedDBObject(obj, true); } } else { currSpace.AppendEntity(blockRefToInsert); trans.AddNewlyCreatedDBObject(blockRefToInsert, true); } trans.Commit(); } } catch (System.Exception ex) { trans.Abort(); } } }
private static void ForceExpold(BlockReference ent) { var doc = Application.DocumentManager.MdiActiveDocument; using (var doclock = doc.LockDocument()) { var db = HostApplicationServices.WorkingDatabase; using (var tr = db.TransactionManager.StartTransaction()) { using (var coll = new DBObjectCollection()) { ent.Explode(coll); BlockTableRecord table = (BlockTableRecord)tr.GetObject(ent.OwnerId, OpenMode.ForWrite); foreach (DBObject obj in coll) { if (obj is Entity) { table.AppendEntity((Entity)obj); tr.AddNewlyCreatedDBObject(obj, true); } } } var e = tr.GetObject(ent.Id, OpenMode.ForWrite); ent.Erase(); tr.Commit(); } } }
/// <summary> /// 获取文字列表 /// </summary> /// <param name="objlist"></param> /// <returns></returns> private List <string> get_text_list(DBObjectCollection objlist) { List <string> list = new List <string>(); foreach (DBObject obj in objlist) { string dxfName = RXClass.GetClass(obj.GetType()).DxfName; string txt = ""; switch (dxfName) { case "TEXT": DBText txtobj = obj as DBText; txt = txtobj.TextString; list.Add(txt); break; case "MTEXT": MText mtxt = obj as MText; string txtall = mtxt.Contents; string[] sarr = txtall.Split(new string[] { "\\P" }, StringSplitOptions.None); if (checkBox_dhcl.Checked == true) { sarr.ToList().ForEach(a => list.Add(a)); } else { list.Add(List_strcat(sarr.ToList())); } break; case "DIMENSION": Entity ent = obj as Entity; DBObjectCollection objs1 = new DBObjectCollection(); ent.Explode(objs1); List <string> rsStr1 = get_text_list(objs1); list.AddRange(rsStr1); break; case "INSERT": BlockReference blk = obj as BlockReference; DBObjectCollection objs = new DBObjectCollection(); blk.Explode(objs); List <string> rsStr = get_text_list(objs); list.AddRange(rsStr); break; default: break; } } return(list); }
private static Extents2d GetSheetExtents(Transaction tr, BlockReference blkSheet) { List <ObjectId> obj; using (DBObjectCollection dbObjCol = new DBObjectCollection()) { blkSheet.Explode(dbObjCol); IEnumerable <ObjectId> b = dbObjCol.Cast <ObjectId>(); obj = (from obj1 in b where obj1.ObjectClass.DxfName.ToString() == "LWPOLYLINE" select obj1).ToList <ObjectId>(); } return(new Extents2d(new Point2d(0, 0), new Point2d(1, 1))); }
public static List <Entity> ExplodeBlock(this BlockReference refEnt) { DBObjectCollection dbObjs = new DBObjectCollection(); refEnt.Explode(dbObjs); var query = from DBObject dbObj in dbObjs let ent = dbObj as Entity select ent; List <Entity> lstEnt = query.ToList(); refEnt.Erase(); return(lstEnt); }
public void GetJingXiang2() { mirrText = Application.GetSystemVariable("MIRRTEXT"); if (mirrText != null && mirrText.ToString() == "1") { Application.SetSystemVariable("MIRRTEXT", 0); } DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); //eLockViolation br = GetBlockCondition("请选择要镜像的块") as BlockReference; if (br == null) { return; } AcadApplication app = Application.AcadApplication as AcadApplication; DBObjectCollection coll = new DBObjectCollection(); br.Explode(coll); Circle c = new Circle(br.Position, Vector3d.ZAxis, 0.010324); var listEnt = coll.Cast <Entity>().ToList(); listEnt.Add(c); oIdColl = listEnt.ToSpace(); using (var trans = Db.TransactionManager.StartTransaction()) { var blkRef = trans.GetObject(br.ObjectId, OpenMode.ForWrite) as BlockReference; blkRef.Visible = false; blkRef.DowngradeOpen(); trans.Commit(); } m_DocumentLock.Dispose(); }
public static ObjectIdCollection explodeFFL(BlockReference blockToExplode) { Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database acCurrDb = acDoc.Database; Editor acEditor = acDoc.Editor; using (Transaction acTrans = acCurrDb.TransactionManager.StartTransaction()) { try { // explode the block DBObjectCollection fflEntities = new DBObjectCollection(); blockToExplode.Explode(fflEntities); // Erase the block blockToExplode.UpgradeOpen(); blockToExplode.Erase(); // Add the entities back into modelspace BlockTable acBlkTbl = acTrans.GetObject(acCurrDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectIdCollection newEntsIDs = new ObjectIdCollection(); foreach (DBObject obj in fflEntities) { Entity newEnt = (Entity)obj; acBlkTblRec.AppendEntity(newEnt); acTrans.AddNewlyCreatedDBObject(newEnt, true); newEntsIDs.Add(newEnt.Id); } acTrans.Commit(); return(newEntsIDs); } catch (Autodesk.AutoCAD.Runtime.Exception acException) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog ("The following exception was caught: \n" + acException.Message + "\nError exploding FFL block!\n"); acTrans.Commit(); return(null); } } }
public List <Entity> exploreBlock(ref BlockTableRecord spaceRecord, BlockReference block, ref Transaction tr) { List <Entity> ans = new List <Entity>(); using (DBObjectCollection dbObjCol = new DBObjectCollection()) { block.Explode(dbObjCol); foreach (DBObject dbObj in dbObjCol) { Entity acEnt = dbObj as Entity; acEnt.Layer = frameBlockAboveLayer; spaceRecord.AppendEntity(acEnt); tr.AddNewlyCreatedDBObject(acEnt, true); ans.Add(acEnt); } } block.Erase(); return(ans); }
public static string DimensionText(BlockReference BR) { using (Transaction t = AC.DB.TransactionManager.StartTransaction()) { BR = t.GetObject(BR.Id, OpenMode.ForRead) as BlockReference; var A = new DBObjectCollection(); BR.Explode(A); var B = A.Cast <Entity>().ToList(); if (B.Where(x => x.GetType() == typeof(DBText)).Any()) { var C = B.Where(x => x.GetType() == typeof(DBText)); if (!C.Any()) { return(string.Empty); } var dbtext = C.First() as DBText; return(dbtext.TextString); } else { var C = B.Where(x => x.GetType().BaseType == typeof(Dimension)); if (!C.Any()) { return(string.Empty); } var dim = C.First() as Dimension; var width = dim.Measurement; return(dim.DimensionText.Replace("<>", to.Str(width))); } } }
public static List <Entity> ExplodeBlock(this BlockReference refEnt, List <Entity> lstEnt) { if (lstEnt == null) { lstEnt = new List <Entity>(); } DBObjectCollection dbObjs = new DBObjectCollection(); refEnt.Explode(dbObjs); if (refEnt.Database != null) { refEnt.Erase(); } var query = from DBObject dbObj in dbObjs let ent = dbObj as Entity where ent is BlockReference select ent; var queryEnt = from DBObject dbObj in dbObjs let ent = dbObj as Entity where !(ent is BlockReference) select ent; List <Entity> lst = queryEnt.ToList(); if (lst != null && lst.Count > 0) { lstEnt.AddRange(lst); } if (query.Count() > 0) { foreach (BlockReference block in query) { ExplodeBlock(block, lstEnt); } } return(lstEnt); }
public DBObjectCollection Explode(bool addToModelSpace = false) { Transaction trans = this._document.Database.TransactionManager.TopTransaction; DBObjectCollection collection = new DBObjectCollection(); BlockReference reference = (BlockReference)trans.GetObject(this.BaseObject, OpenMode.ForRead); reference.Explode(collection); if (addToModelSpace) { foreach (DBObject dbObject in collection) { Entity ent = (Entity)dbObject; BlockTableRecord btr = _document.Database.GetModelSpace(true); btr.AppendEntity(ent); trans.AddNewlyCreatedDBObject(ent, true); } } return(collection); }
private void DrawCurveOrBlockRef(Entity tempEntity) { if (tempEntity is ICurve) { Draw(tempEntity as ICurve); } else if (tempEntity is LinearDim) { var dim = (LinearDim)tempEntity; //Draw text Draw(new Line(dim.Vertices[6], dim.Vertices[7])); Draw(new Line(dim.Vertices[7], dim.Vertices[8])); Draw(new Line(dim.Vertices[8], dim.Vertices[9])); Draw(new Line(dim.Vertices[9], dim.Vertices[6])); //Draw lines Draw(new Line(dim.Vertices[0], dim.Vertices[1])); Draw(new Line(dim.Vertices[2], dim.Vertices[3])); Draw(new Line(dim.Vertices[4], dim.Vertices[5])); } else if (tempEntity is RadialDim) { var dim = (RadialDim)tempEntity; //Draw text Draw(new Line(dim.Vertices[6], dim.Vertices[7])); Draw(new Line(dim.Vertices[7], dim.Vertices[8])); Draw(new Line(dim.Vertices[8], dim.Vertices[9])); Draw(new Line(dim.Vertices[9], dim.Vertices[6])); Draw(new Line(dim.Vertices[0], dim.Vertices[5])); } else if (tempEntity is AngularDim) { var dim = (AngularDim)tempEntity; //Draw text Draw(new Line(dim.Vertices[4], dim.Vertices[5])); Draw(new Line(dim.Vertices[5], dim.Vertices[6])); Draw(new Line(dim.Vertices[6], dim.Vertices[7])); Draw(new Line(dim.Vertices[7], dim.Vertices[4])); Draw(new Line(dim.Vertices[0], dim.Vertices[1])); Draw(new Line(dim.Vertices[2], dim.Vertices[3])); Draw(dim.UnderlyingArc); } else if (tempEntity is OrdinateDim) { var dim = (OrdinateDim)tempEntity; //Draw text Draw(new Line(dim.Vertices[4], dim.Vertices[5])); Draw(new Line(dim.Vertices[5], dim.Vertices[6])); Draw(new Line(dim.Vertices[6], dim.Vertices[7])); Draw(new Line(dim.Vertices[7], dim.Vertices[4])); Draw(new Line(dim.Vertices[0], dim.Vertices[1])); Draw(new Line(dim.Vertices[1], dim.Vertices[2])); Draw(new Line(dim.Vertices[2], dim.Vertices[3])); } else if (tempEntity is Text) { var txt = (Text)tempEntity; Draw(new Line(txt.Vertices[0], txt.Vertices[1])); Draw(new Line(txt.Vertices[1], txt.Vertices[2])); Draw(new Line(txt.Vertices[2], txt.Vertices[3])); Draw(new Line(txt.Vertices[3], txt.Vertices[0])); } else if (tempEntity is BlockReference) { BlockReference br = (BlockReference)tempEntity; Entity[] entList = br.Explode(this.Blocks); foreach (Entity item in entList) { ICurve curve = item as ICurve; if (curve != null) { Draw(curve); } } } else if (tempEntity is Leader) { var leader = (Leader)tempEntity; Draw(new Line(leader.Vertices[0], leader.Vertices[1])); Draw(new Line(leader.Vertices[1], leader.Vertices[2])); } }
public static void InsertDrawers() { Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database db = activeDoc.Database; //double drawerW = W; double drawerH = (H - doorH) / N; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; for (int cnt = 0; cnt < N; cnt++) { // 2*t-(D/N) * (N-cnt) for placing the drawers in open position. // 0.0 for shut drawers. Point3d pos1 = new Point3d(0.0, 2 * t - (D / N) * (N - cnt), drawerH * cnt); BlockReference bref1 = new BlockReference(pos1, bt["Drawer"]); DBObjectCollection explodeSet1 = new DBObjectCollection(); bref1.Explode(explodeSet1); foreach (DBObject dbObj in explodeSet1) { btr.AppendEntity(dbObj as Entity); tr.AddNewlyCreatedDBObject(dbObj, true); } // Handle if (splitDrawers) { BlockReference bref11 = new BlockReference(new Point3d(0.25 * W, 2 * t - (D / N) * (N - cnt), drawerH * cnt + drawerH * 0.5), bt["Handle"]); btr.AppendEntity(bref11 as Entity); tr.AddNewlyCreatedDBObject(bref11, true); } else { BlockReference bref11 = new BlockReference(new Point3d(0.5 * W, 2 * t - (D / N) * (N - cnt), drawerH * cnt + drawerH * 0.5), bt["Handle"]); btr.AppendEntity(bref11 as Entity); tr.AddNewlyCreatedDBObject(bref11, true); } if (splitDrawers) { // 2*t-(D/N) * (N-cnt) for placing the drawers in open position. // 0.0 for shut drawers. Point3d pos2 = new Point3d(W * 0.5, 2 * t - (D / N) * (N - cnt), drawerH * cnt); BlockReference bref2 = new BlockReference(pos2, bt["Drawer"]); DBObjectCollection explodeSet2 = new DBObjectCollection(); bref2.Explode(explodeSet2); foreach (DBObject dbObj in explodeSet2) { btr.AppendEntity(dbObj as Entity); tr.AddNewlyCreatedDBObject(dbObj, true); } // Handle BlockReference bref22 = new BlockReference(new Point3d(W * 0.75, 2 * t - (D / N) * (N - cnt), drawerH * cnt + drawerH * 0.5), bt["Handle"]); btr.AppendEntity(bref22 as Entity); tr.AddNewlyCreatedDBObject(bref22, true); } } tr.Commit(); } }
public static void LayerInfoGrab(IEnumerable <string> LayName, string LayerType, string DocName) { //link to the current document and databases Document Doc = Aapp.DocumentManager.MdiActiveDocument; Database db = Doc.Database; Editor ed = Doc.Editor; using (Transaction Trans = db.TransactionManager.StartTransaction()) { //Open the block table open for read BlockTable Btr = Trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; //Open the model space database for read BlockTableRecord BtrModel = Trans.GetObject(Btr[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord; //Open the model space database for write BlockTableRecord BtrModelWrite = Trans.GetObject(Btr[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; /////////////////////////////////////////////////////////////////////////////////// //explode all objects in the model space foreach (ObjectId ReadObject in BtrModel) { //Open the DBobject var dbObj = Trans.GetObject(ReadObject, OpenMode.ForRead); //Check to see if the object is a polyline var rxClassPline = RXClass.GetClass(typeof(Polyline)); //Test the object for entity type if (ReadObject.ObjectClass.IsDerivedFrom(rxClassPline)) { //Open the DBobject Polyline Pline = (Polyline)Trans.GetObject(ReadObject, OpenMode.ForRead); //Collect exploded object parts with this using (DBObjectCollection acDBObjColl = new DBObjectCollection()) { //Explode the object Pline.Explode(acDBObjColl); //save each new entity from the exploded object foreach (Entity acEnt in acDBObjColl) { // Add the new object to the block table record and the transaction BtrModelWrite.AppendEntity(acEnt); Trans.AddNewlyCreatedDBObject(acEnt, true); } } } var rxClassBref = RXClass.GetClass(typeof(BlockReference)); //Test the object for block type if (ReadObject.ObjectClass.IsDerivedFrom(rxClassBref)) { //Open the DBobject BlockReference Bref = (BlockReference)Trans.GetObject(ReadObject, OpenMode.ForRead); //Collect exploded object parts with this using (DBObjectCollection acDBObjColl = new DBObjectCollection()) { Bref.Explode(acDBObjColl); //save each new entity from the exploded object foreach (Entity acEnt in acDBObjColl) { //Add the new objects to the block table record and the transaction BtrModelWrite.AppendEntity(acEnt); Trans.AddNewlyCreatedDBObject(acEnt, true); } } } } /////////////////////////////////////////////////////////////////////// //Step through the objects and find any on the layer we want foreach (ObjectId ReadObject in BtrModel) { foreach (string LayerName in LayName) { var rxClassline = RXClass.GetClass(typeof(Line)); //Test the object for block type if (ReadObject.ObjectClass.IsDerivedFrom(rxClassline)) { //Open the DBobject Line line = (Line)Trans.GetObject(ReadObject, OpenMode.ForRead); //Check the Dbobject belings to a layer we are intersted in if (line.Layer == LayerName) { //Add data to the table DataConnection.ExcelConnect(line.Handle.Value, line.StartPoint.X, line.EndPoint.X, line.StartPoint.Y, line.EndPoint.Y, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, line.Angle, "Line", line.Color.Red, line.Color.Blue, line.Color.Green, LayerName, DocName, line.Thickness, line.Linetype, line.Length); //If the layer type is a property boundary send the info to also confirm the screen shot is near a road if (LayerType == "Pboundary") { Form Psort = new Imaging.SortpBoundaryImages(); } //Else just take screenshots else { Imaging.LineImages.Initiate(db, ed, ReadObject, LayerType, LayerName); } } } var rxClass_Circle = RXClass.GetClass(typeof(Circle)); //Test the object for block type if (ReadObject.ObjectClass.IsDerivedFrom(rxClass_Circle)) { //Open the DBobject Circle circle = (Circle)Trans.GetObject(ReadObject, OpenMode.ForRead); //Check the Dbobject belings to a layer we are intersted in if (circle.Layer == LayerName) { //Add data to the table DataConnection.ExcelConnect(circle.Handle.Value, double.NaN, double.NaN, double.NaN, double.NaN, circle.Center.X, circle.Center.Y, double.NaN, double.NaN, circle.Radius, double.NaN, "Circle", circle.Color.Red, circle.Color.Blue, circle.Color.Green, LayerName, DocName, circle.Thickness, circle.Linetype, double.NaN); } } var rxClass_Arc = RXClass.GetClass(typeof(Arc)); //Test the object for block type if (ReadObject.ObjectClass.IsDerivedFrom(rxClass_Arc)) { //Open the DBobject Arc arc = (Arc)Trans.GetObject(ReadObject, OpenMode.ForRead); //Check the Dbobject belings to a layer we are intersted in if (arc.Layer == LayerName) { //Add data to the table DataConnection.ExcelConnect(arc.Handle.Value, arc.StartPoint.X, arc.EndPoint.X, arc.StartPoint.Y, arc.EndPoint.Y, double.NaN, double.NaN, arc.StartAngle, arc.EndAngle, double.NaN, double.NaN, "Arc", arc.Color.Red, arc.Color.Blue, arc.Color.Green, LayerName, DocName, arc.Thickness, arc.Linetype, arc.Length); } } var rxClass_Ellipse = RXClass.GetClass(typeof(Ellipse)); //Test the object for block type if (ReadObject.ObjectClass.IsDerivedFrom(rxClass_Ellipse)) { //Open the DBobject Ellipse ellipse = (Ellipse)Trans.GetObject(ReadObject, OpenMode.ForRead); //Check the Dbobject belings to a layer we are intersted in if (ellipse.Layer == LayerName) { //Add data to the table DataConnection.ExcelConnect(ellipse.Handle.Value, ellipse.MinorAxis.X, ellipse.MinorAxis.Y, ellipse.MajorAxis.X, ellipse.MajorAxis.Y, ellipse.Center.X, ellipse.Center.Y, ellipse.StartAngle, ellipse.EndAngle, ellipse.MajorRadius, ellipse.MinorRadius, "Ellipse", ellipse.Color.Red, ellipse.Color.Blue, ellipse.Color.Green, LayerName, DocName, double.NaN, ellipse.Linetype, double.NaN); } } } } //Finalise transaction Trans.Commit(); } }
public void GetJingXiang() { var mirrText = Application.GetSystemVariable("MIRRTEXT"); if (mirrText != null && mirrText.ToString() == "1") { Application.SetSystemVariable("MIRRTEXT", 0); } DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); //eLockViolation BlockReference br = GetBlockCondition("请选择要镜像的块") as BlockReference; if (br == null) { return; } AcadApplication app = Application.AcadApplication as AcadApplication; DBObjectCollection coll = new DBObjectCollection(); br.Explode(coll); Circle c = new Circle(br.Position, Vector3d.ZAxis, 0.010324); var listEnt = coll.Cast <Entity>().ToList(); listEnt.Add(c); var oIdColl = listEnt.ToSpace(); using (var trans = Db.TransactionManager.StartTransaction()) { var blkRef = trans.GetObject(br.ObjectId, OpenMode.ForWrite) as BlockReference; blkRef.Visible = false; blkRef.DowngradeOpen(); trans.Commit(); } app.ActiveDocument.SendCommand("mirror "); using (var trans = Db.TransactionManager.StartTransaction()) { var blkRef = trans.GetObject(br.ObjectId, OpenMode.ForWrite) as BlockReference; blkRef.Visible = true; blkRef.DowngradeOpen(); for (int i = 0; oIdColl != null && i < oIdColl.Count; i++) { var ent = trans.GetObject(oIdColl[i], OpenMode.ForWrite) as Entity; if (ent != null) { ent.Erase(true); } } trans.Commit(); } var selRes = Ed.GetSelection(); if (selRes.Status != PromptStatus.OK) { return; } var list = selRes.Value.GetObjectIds()?.ToList(); ObjectId recId = ObjectId.Null; Point3d ptPosC = Point3d.Origin; using (var trans = Db.TransactionManager.StartTransaction()) { var blkTbl = trans.GetObject(Db.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blkRec = new BlockTableRecord(); blkRec.Units = br.BlockUnit; string blkName = br.Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); blkRec.Name = blkName; for (int i = 0; list != null && i < list.Count; i++) { var ent = trans.GetObject(list[i], OpenMode.ForWrite); if (ent != null) { bool flag = true; if (ent is Circle) { var cir = ent as Circle; if (cir.Radius == 0.010324) { ptPosC = cir.Center; cir.Erase(true); flag = false; } } if (flag) { Entity entCopy = ent.Clone() as Entity; ent.Erase(true); blkRec.AppendEntity(entCopy); } } } blkRec.Origin = ptPosC; recId = blkTbl.Add(blkRec); trans.AddNewlyCreatedDBObject(blkRec, true); trans.Commit(); } BlockReference brEnt = new BlockReference(ptPosC, recId); // var vec = br.Position - ptPosC; //brEnt.TransformBy(Matrix3d.Displacement(vec * 2.5)); brEnt.ToSpace(); Application.ShowAlertDialog("OK"); Application.SetSystemVariable("MIRRTEXT", mirrText); m_DocumentLock.Dispose(); }
public void GetFFLfromSurface() { Database acCurDb; acCurDb = Application.DocumentManager.MdiActiveDocument.Database; Transaction acTrans = acCurDb.TransactionManager.TopTransaction; BlockReference newBlockRef = acTrans.GetObject(BlockRef, OpenMode.ForWrite) as BlockReference;//(BlockReference)BlockRef.GetObject(OpenMode.ForWrite); DBObjectCollection explodedBlock = new DBObjectCollection(); newBlockRef.Explode(explodedBlock); ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds(); CivSurface proposedGround = null; foreach (ObjectId surfaceId in SurfaceIds) { CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface; if (oSurface.Name == Civils.Constants.ProposedGroundName) { proposedGround = oSurface; } } double maxLevel = double.NegativeInfinity; if (proposedGround != null) { try { foreach (WallJoint wj in Joints) { wj.ExternalLevel = Math.Round(proposedGround.FindElevationAtXY(wj.Point.X, wj.Point.Y) * 1000) / 1000; if (wj.ExternalLevel > maxLevel) { maxLevel = wj.ExternalLevel; } } } catch (PointNotOnEntityException e) { maxLevel = -0.15; this.Status = PlotStatus.Error; this.StatusMessage = "Plot has points not on proposed ground model"; } if (maxLevel == double.NegativeInfinity) { maxLevel = -0.15; this.Status = PlotStatus.Error; this.StatusMessage = "Surface elevations not found correctly"; } } else { maxLevel = -0.15; this.Status = PlotStatus.Error; this.StatusMessage = "Proposed Ground model not found"; } this.FinishedFloorLevel = Math.Round(maxLevel * 1000) / 1000 + 0.15; }
/// <summary> /// Вставка блока в чертеж - интерактивная (BlockInsertJig) /// </summary> public static ObjectId Insert(string blName, LayerInfo?layer, List <Property>?props, bool explode = false) { var doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) { return(ObjectId.Null); } var db = doc.Database; var ed = doc.Editor; using var @lock = doc.LockDocument(); using var t = db.TransactionManager.StartTransaction(); var bt = (BlockTable)t.GetObject(db.BlockTableId, OpenMode.ForRead); if (!bt.Has(blName)) { throw new Exception("Блок не определен в чертеже " + blName); } var idBlBtr = bt[blName]; var pt = Point3d.Origin; var br = new BlockReference(pt, idBlBtr); br.SetDatabaseDefaults(); if (layer != null) { layer.CheckLayerState(); br.Layer = layer.Name; } var spaceBtr = (BlockTableRecord)t.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); var idBlRefInsert = spaceBtr.AppendEntity(br); t.AddNewlyCreatedDBObject(br, true); if (props != null && br.IsDynamicBlock) { foreach (DynamicBlockReferenceProperty item in br.DynamicBlockReferencePropertyCollection) { var prop = props.FirstOrDefault(p => p.Name.Equals(item.PropertyName, StringComparison.OrdinalIgnoreCase)); if (prop != null) { try { item.Value = prop.Value; } catch (Exception ex) { Logger.Log.Error(ex, msg: $"Ошибка типа значения для дин параметра '{item.PropertyName}' " + $"при вставке блока '{blName}': тип устанавливаемого значение '{prop.Value.GetType()}', " + $"а должен быть тип '{item.UnitsType}'"); } } } } // jig var entJig = new Jigs.BlockInsertJig(br); var pr = ed.Drag(entJig); if (pr.Status == PromptStatus.OK) { var btrBl = (BlockTableRecord)t.GetObject(idBlBtr, OpenMode.ForRead); if (btrBl.HasAttributeDefinitions) { AddAttributes(br, btrBl, t); } if (explode) { var owner = br.BlockId.GetObject <BlockTableRecord>(OpenMode.ForWrite); using var explodes = new DBObjectCollection(); br.Explode(explodes); foreach (Entity ent in explodes) { owner.AppendEntity(ent); t.AddNewlyCreatedDBObject(ent, true); ent.Layer = br.Layer; } br.Erase(); } } else { br.Erase(); idBlRefInsert = ObjectId.Null; } t.Commit(); return(idBlRefInsert); }