public static void XCloseAll() { if (!CheckLicense.Check()) { return; } Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptKeywordOptions kopts = new PromptKeywordOptions("\nTüm dosyalar kaydedilmeden kapatılacak. Devam edilsin mi? [Evet/Hayır] <Hayir>: ", "Yes No"); kopts.AllowNone = true; kopts.Keywords.Default = "No"; PromptResult kres = ed.GetKeywords(kopts); if (kres.Status != PromptStatus.OK || kres.StringResult != "Yes") { return; } foreach (Document doc in Application.DocumentManager) { if (doc.CommandInProgress != "" && doc.CommandInProgress != "XCLOSEALL") { doc.SendStringToExecute("\x03\x03", false, false, false); } DocumentExtension.CloseAndDiscard(doc); } }
public void DrawContourMap() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Surface type Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick interval Topography topo = Topography.Instance; PromptDoubleOptions dblOpts = new PromptDoubleOptions("\nKontur aralığı: "); dblOpts.AllowNegative = false; dblOpts.AllowZero = false; dblOpts.DefaultValue = ContourInterval; dblOpts.UseDefaultValue = true; PromptDoubleResult dblRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(dblOpts); if (dblRes.Status == PromptStatus.OK) { ContourInterval = dblRes.Value; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { IEnumerable <Polyline> contours = topo.ContourMap(surface, ContourInterval); foreach (Polyline pline in contours) { btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } } }
public void DrawParabola() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; PromptPointResult p0Res; while (true) { PromptPointOptions p0Opts = new PromptPointOptions("\nVertex Point: [Seçenekler]", "Settings"); p0Res = doc.Editor.GetPoint(p0Opts); if (p0Res.Status == PromptStatus.Keyword && p0Res.StringResult == "Settings") { PromptIntegerOptions opts = new PromptIntegerOptions("Eğri segment sayısı: "); opts.AllowNone = true; opts.AllowZero = false; opts.AllowNegative = false; opts.LowerLimit = 1; opts.UpperLimit = 100; opts.DefaultValue = CurveSegments; opts.UseDefaultValue = true; PromptIntegerResult res = doc.Editor.GetInteger(opts); if (res.Status == PromptStatus.Cancel) { return; } else if (res.Status == PromptStatus.OK) { CurveSegments = res.Value; } } else if (p0Res.Status != PromptStatus.OK) { return; } else { break; } } ParabolaJig.Jig(p0Res.Value, CurveSegments); }
public void Drape() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick polyline PromptEntityOptions entityOpts = new PromptEntityOptions("\nEğri: "); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Curve curve = tr.GetObject(entityRes.ObjectId, OpenMode.ForRead) as Curve; Topography topo = Topography.Instance; Point3dCollection points = topo.DrapeCurve(curve, surface); Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, curve.Closed, points); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); tr.Commit(); } } }
public void CreateSurface() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (ShowSettings()) { try { IEnumerable <ObjectId> items = SelectEntitites(); Point3dCollection points = ReadPoints(items, MaxPointSpacing); if (points.Count > 0) { Topography topo = Topography.Instance; topo.SurfaceFromPoints(points, surface); doc.Editor.WriteMessage(topo.OriginalTIN.Triangles.Count.ToString() + " adet üçgen oluşturuldu."); } if (EraseEntities) { AcadUtility.AcadEntity.EraseEntities(db, items); } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static void XPurge() { if (!CheckLicense.Check()) { return; } // Process active document Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; // Read settings var deploy = new Deploy(); // Add purge actions deploy.AddAction(new PurgeDGNLS()); deploy.AddAction(new PurgeAll()); // Start processing deploy.Run(db); }
public static void DrawBoreholeDetails() { if (!CheckLicense.Check()) { return; } using (DrawBoreholeDetailsForm form = new DrawBoreholeDetailsForm()) { if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(null, form, false) == System.Windows.Forms.DialogResult.OK) { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; PromptPointResult res = doc.Editor.GetPoint("Sondaj çizimi başlangıç noktası: "); Point3d pt = res.Value; Dictionary <string, string> headers = form.GetHeaders(); Dictionary <string, List <string> > data = form.GetData(); List <double> depths = form.GetDepths(); string layerName = form.LayerName; double textHeight = form.TextHeight; bool hasGW = form.HasGroundwater; double gwLevel = form.GroundwaterLevel; Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; double xSpacing = 5.3 * textHeight; using (Transaction tr = db.TransactionManager.StartTransaction()) using (LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead)) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { // Get layer ObjectId layerId = ObjectId.Null; Color headerColor = Color.FromColorIndex(ColorMethod.ByAci, 4); Color textColor = Color.FromColorIndex(ColorMethod.ByAci, 1); Color gwColor = Color.FromColorIndex(ColorMethod.ByAci, 4); double tickSize = 0.5 * textHeight; if (lt.Has(layerName)) { layerId = lt[layerName]; } else { LayerTableRecord ltr = new LayerTableRecord(); ltr.Name = layerName; ltr.Color = textColor; lt.UpgradeOpen(); layerId = lt.Add(ltr); tr.AddNewlyCreatedDBObject(ltr, true); } Point3d depthLineTop = Point3d.Origin; Point3d depthLineBottom = Point3d.Origin; // Header underline if (data.Count > 0) { Point3d pt1 = new Point3d(pt.X - xSpacing, pt.Y + 0.9 * textHeight, pt.Z); Point3d pt2 = new Point3d(pt.X + xSpacing * data.Count - xSpacing, pt.Y + 0.9 * textHeight, pt.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1.TransformBy(ucs2wcs), pt2.TransformBy(ucs2wcs)); line.LayerId = layerId; line.Color = headerColor; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } // Process columns int j = 0; foreach (KeyValuePair <string, List <string> > item in data) { string key = item.Key; // Header text of this column string headerText = headers[key]; if (!string.IsNullOrEmpty(headerText)) { string[] lines = headerText.Split(' '); Point3d ptText = new Point3d(pt.X + xSpacing * j - xSpacing / 2, pt.Y + 0.6 * textHeight + lines.Length * 1.3 * textHeight, pt.Z); foreach (string line in lines) { DBText dbtext = AcadUtility.AcadEntity.CreateText(db, ptText.TransformBy(ucs2wcs), line, textHeight, 0, 1, TextHorizontalMode.TextMid, TextVerticalMode.TextVerticalMid); dbtext.LayerId = layerId; dbtext.Color = headerColor; btr.AppendEntity(dbtext); tr.AddNewlyCreatedDBObject(dbtext, true); ptText = new Point3d(ptText.X, ptText.Y - textHeight * 1.3, ptText.Z); } } // Item texts for this column int i = 0; foreach (string text in item.Value) { if (!string.IsNullOrEmpty(text)) { if (string.Compare(key, "Depth", StringComparison.InvariantCultureIgnoreCase) == 0) { // Item text double depth = depths[i]; Point3d ptText = new Point3d(pt.X + xSpacing * j, pt.Y - depth, pt.Z); DBText dbtext = AcadUtility.AcadEntity.CreateText(db, ptText.TransformBy(ucs2wcs), text, textHeight, 0, 1, TextHorizontalMode.TextRight, TextVerticalMode.TextVerticalMid); dbtext.LayerId = layerId; btr.AppendEntity(dbtext); tr.AddNewlyCreatedDBObject(dbtext, true); // Horizontal depth ticks Point3d pt1 = new Point3d(ptText.X + 0.25, ptText.Y, ptText.Z); Point3d pt2 = new Point3d(ptText.X + 0.25 + tickSize, ptText.Y, ptText.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1.TransformBy(ucs2wcs), pt2.TransformBy(ucs2wcs)); line.LayerId = layerId; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); if (depthLineTop.GetAsVector().IsZeroLength()) { depthLineTop = pt1; } depthLineBottom = pt1; } else { // Item text double depth = depths[i]; Point3d ptText = new Point3d(pt.X + xSpacing * j - xSpacing / 2, pt.Y - depth, pt.Z); DBText dbtext = AcadUtility.AcadEntity.CreateText(db, ptText.TransformBy(ucs2wcs), text, textHeight, 0, 1, TextHorizontalMode.TextMid, TextVerticalMode.TextVerticalMid); dbtext.LayerId = layerId; btr.AppendEntity(dbtext); tr.AddNewlyCreatedDBObject(dbtext, true); } } i++; } j++; } // Vertical depth line if (!depthLineTop.GetAsVector().IsZeroLength()) { Point3d pt1 = new Point3d(depthLineTop.X + tickSize / 2, pt.Y, depthLineTop.Z); Point3d pt2 = new Point3d(depthLineBottom.X + tickSize / 2, depthLineBottom.Y, depthLineBottom.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1.TransformBy(ucs2wcs), pt2.TransformBy(ucs2wcs)); line.LayerId = layerId; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } // Ground water if (hasGW) { // Horizontal line Point3d pt1 = new Point3d(pt.X + 0.25 - 6.6 * textHeight, pt.Y - gwLevel, pt.Z); Point3d pt2 = new Point3d(pt.X + 0.25, pt.Y - gwLevel, pt.Z); Line line = AcadUtility.AcadEntity.CreateLine(db, pt1.TransformBy(ucs2wcs), pt2.TransformBy(ucs2wcs)); line.LayerId = layerId; line.Color = gwColor; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); // GW marker double markerSize = 0.8 * textHeight; Polyline pline = new Polyline(1); pline.Normal = ucs2wcs.CoordinateSystem3d.Zaxis; pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); Plane plinePlane = new Plane(Point3d.Origin, pline.Normal); pline.Reset(false, 3); Point3d wcsPt1 = new Point3d(pt.X + 0.25 - 4.6 * textHeight, pt.Y - gwLevel, pt.Z).TransformBy(ucs2wcs); // Convert to WCS Point2d ecsPt1 = plinePlane.ParameterOf(wcsPt1); // Convert to ECS pline.AddVertexAt(pline.NumberOfVertices, ecsPt1, 0, 0, 0); Point3d wcsPt2 = new Point3d(pt.X + 0.25 - 4.6 * textHeight - markerSize, pt.Y - gwLevel + markerSize, pt.Z).TransformBy(ucs2wcs); // Convert to WCS Point2d ecsPt2 = plinePlane.ParameterOf(wcsPt2); // Convert to ECS pline.AddVertexAt(pline.NumberOfVertices, ecsPt2, 0, 0, 0); Point3d wcsPt3 = new Point3d(pt.X + 0.25 - 4.6 * textHeight + markerSize, pt.Y - gwLevel + markerSize, pt.Z).TransformBy(ucs2wcs); // Convert to WCS Point2d ecsPt3 = plinePlane.ParameterOf(wcsPt3); // Convert to ECS pline.AddVertexAt(pline.NumberOfVertices, ecsPt3, 0, 0, 0); pline.Closed = true; pline.LayerId = layerId; pline.Color = gwColor; btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); // GW text Point3d ptText = new Point3d(pt.X + 0.25 - 4.6 * textHeight, pt.Y - gwLevel + markerSize, pt.Z); DBText dbtext = AcadUtility.AcadEntity.CreateText(db, ptText.TransformBy(ucs2wcs), gwLevel.ToString(), textHeight, 0, 1, TextHorizontalMode.TextCenter, TextVerticalMode.TextBottom); dbtext.LayerId = layerId; dbtext.Color = gwColor; btr.AppendEntity(dbtext); tr.AddNewlyCreatedDBObject(dbtext, true); } tr.Commit(); } } } }
public void DrawDeck() { if (!CheckLicense.Check()) { return; } var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; Matrix3d ucs2wcs = AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadGraphics.WcsToUcs; Alignment = Bridge.PickAlignment(); if (Alignment == Bridge.AlignmentType.None) { return; } PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: "); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = ed.GetEntity(entityOpts); if (entityRes.Status != PromptStatus.OK) { return; } CenterlineId = entityRes.ObjectId; var resp1 = ed.GetPoint("\nBaşlangıç noktası: "); if (resp1.Status != PromptStatus.OK) { return; } StartPoint = resp1.Value.TransformBy(ucs2wcs); var resp2 = ed.GetPoint("\nBitiş noktası: "); if (resp2.Status != PromptStatus.OK) { return; } EndPoint = resp2.Value.TransformBy(ucs2wcs); var opts = new PromptDistanceOptions("\nAsktan taşma mesafesi: "); opts.AllowNegative = false; opts.AllowZero = false; opts.DefaultValue = OverhangDistance; opts.UseDefaultValue = true; opts.BasePoint = resp1.Value; var res = ed.GetDistance(opts); if (res.Status != PromptStatus.OK) { return; } OverhangDistance = res.Value; if (Alignment == Bridge.AlignmentType.Plan) { var opts1 = new PromptDistanceOptions("\nTabliye genişliği: "); opts1.AllowNegative = false; opts1.AllowZero = false; opts1.DefaultValue = DeckWidth; opts1.UseDefaultValue = true; opts1.BasePoint = resp1.Value; var reso1 = ed.GetDistance(opts1); if (reso1.Status != PromptStatus.OK) { return; } DeckWidth = reso1.Value; } else { var opts1 = new PromptDistanceOptions("\nAsfalt kalınlığı: "); opts1.AllowNegative = false; opts1.AllowZero = false; opts1.DefaultValue = AsphaltThickness; opts1.UseDefaultValue = true; var reso1 = ed.GetDistance(opts1); if (reso1.Status != PromptStatus.OK) { return; } AsphaltThickness = reso1.Value; var opts2 = new PromptDistanceOptions("\nTabliye kalınlığı: "); opts2.AllowNegative = false; opts2.AllowZero = false; opts2.DefaultValue = DeckThickness; opts2.UseDefaultValue = true; var reso2 = ed.GetDistance(opts2); if (reso2.Status != PromptStatus.OK) { return; } DeckThickness = reso2.Value; var opts3 = new PromptDistanceOptions("\nKaldırım kalınlığı: "); opts3.AllowNegative = false; opts3.AllowZero = false; opts3.DefaultValue = SidewalkThickness; opts3.UseDefaultValue = true; var reso3 = ed.GetDistance(opts3); if (reso3.Status != PromptStatus.OK) { return; } SidewalkThickness = reso3.Value; } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { ObjectId lineLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, DeckLayerName, Color.FromColorIndex(ColorMethod.ByAci, 4)); ObjectId hatchLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, HatchLayerName, Color.FromColorIndex(ColorMethod.ByAci, 31)); ObjectId sidewalkLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, SidewalkLayerName, Color.FromColorIndex(ColorMethod.ByAci, 21)); // Adjust start and end point to account for overhang Curve centerline = tr.GetObject(CenterlineId, OpenMode.ForRead) as Curve; if (Alignment == Bridge.AlignmentType.Plan) { StartPoint = centerline.GetClosestPointTo(StartPoint, false); double startDistance = centerline.GetDistAtPoint(StartPoint) - OverhangDistance; StartPoint = centerline.GetPointAtDist(startDistance); EndPoint = centerline.GetClosestPointTo(EndPoint, false); double endDistance = centerline.GetDistAtPoint(EndPoint) + OverhangDistance; EndPoint = centerline.GetPointAtDist(endDistance); using (Plane horizontal = new Plane(Point3d.Origin, Vector3d.ZAxis)) { Curve planCurve = centerline.GetOrthoProjectedCurve(horizontal); planCurve = planCurve.GetTrimmedCurve(StartPoint, EndPoint, true); Vector3d dir = planCurve.GetFirstDerivative(planCurve.StartParam).CrossProduct(Vector3d.ZAxis); dir /= dir.Length; var rightCurve = planCurve.GetOffsetCurves(planCurve.StartPoint + dir * DeckWidth / 2)[0] as Curve; var leftCurve = planCurve.GetOffsetCurves(planCurve.StartPoint - dir * DeckWidth / 2)[0] as Curve; // Join curves and close ends with lines var finalCurve = AcadEntity.CreatePolyLine(db, true, rightCurve, AcadEntity.CreateLine(db, rightCurve.StartPoint, leftCurve.StartPoint), leftCurve, AcadEntity.CreateLine(db, rightCurve.EndPoint, leftCurve.EndPoint)); var finalCurveId = btr.AppendEntity(finalCurve); tr.AddNewlyCreatedDBObject(finalCurve, true); finalCurve.LayerId = lineLayerId; // Hatch inside var hatch = new Hatch(); btr.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true); hatch.LayerId = hatchLayerId; hatch.Associative = true; hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection() { finalCurveId }); hatch.PatternScale = HatchScale; hatch.SetHatchPattern(HatchPatternType.PreDefined, HatchPattern); hatch.EvaluateHatch(true); } } else { Vector3d upDir = db.Ucsydir; var topline = centerline.GetTransformedCopy(Matrix3d.Displacement(upDir * -AsphaltThickness)) as Curve; var bottomline = topline.GetTransformedCopy(Matrix3d.Displacement(upDir * -DeckThickness)) as Curve; var sidewalkline = topline.GetTransformedCopy(Matrix3d.Displacement(upDir * SidewalkThickness)) as Curve; using (Plane horizontal = new Plane(Point3d.Origin, upDir)) { Curve planCurve = centerline.GetOrthoProjectedCurve(horizontal); Point3d startPointOnPlan = planCurve.GetClosestPointTo(StartPoint, true); double startDistance = planCurve.GetDistAtPoint(startPointOnPlan) - OverhangDistance; startPointOnPlan = planCurve.GetPointAtDist(startDistance); StartPoint = centerline.GetClosestPointTo(startPointOnPlan, upDir, true); Point3d endPointOnPlan = planCurve.GetClosestPointTo(EndPoint, true); double endDistance = planCurve.GetDistAtPoint(endPointOnPlan) + OverhangDistance; endPointOnPlan = planCurve.GetPointAtDist(endDistance); EndPoint = centerline.GetClosestPointTo(endPointOnPlan, upDir, true); } topline = topline.GetTrimmedCurve(topline.GetClosestPointTo(StartPoint, upDir, true), topline.GetClosestPointTo(EndPoint, upDir, true), true); bottomline = bottomline.GetTrimmedCurve(bottomline.GetClosestPointTo(StartPoint, upDir, true), bottomline.GetClosestPointTo(EndPoint, upDir, true), true); sidewalkline = sidewalkline.GetTrimmedCurve(sidewalkline.GetClosestPointTo(StartPoint, upDir, true), sidewalkline.GetClosestPointTo(EndPoint, upDir, true), true); // Sidewalk var finalSWCurve = AcadEntity.CreatePolyLine(db, false, AcadEntity.CreateLine(db, topline.StartPoint, sidewalkline.StartPoint), sidewalkline, AcadEntity.CreateLine(db, topline.EndPoint, sidewalkline.EndPoint)); btr.AppendEntity(finalSWCurve); tr.AddNewlyCreatedDBObject(finalSWCurve, true); finalSWCurve.LayerId = sidewalkLayerId; // Deck polyline var finalCurve = AcadEntity.CreatePolyLine(db, true, topline, AcadEntity.CreateLine(db, topline.StartPoint, bottomline.StartPoint), bottomline, AcadEntity.CreateLine(db, topline.EndPoint, bottomline.EndPoint)); ObjectId finalCurveId = btr.AppendEntity(finalCurve); tr.AddNewlyCreatedDBObject(finalCurve, true); finalCurve.LayerId = lineLayerId; // Hatch inside var hatch = new Hatch(); btr.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true); hatch.LayerId = hatchLayerId; hatch.Associative = true; hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection() { finalCurveId }); hatch.PatternScale = HatchScale; hatch.SetHatchPattern(HatchPatternType.PreDefined, HatchPattern); hatch.EvaluateHatch(true); } } catch (System.Exception e) { MessageBox.Show(e.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
public void Numbering() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs; using (NumberingForm form = new NumberingForm()) { // Read settings form.SelectObjects = (NumberingForm.SelectNumberingObjects)Properties.Settings.Default.Command_NUMARALANDIR_SelectObjects; form.AttributeName = Properties.Settings.Default.Command_NUMARALANDIR_AttributeName; form.Ordering = (NumberingForm.CoordinateOrdering)Properties.Settings.Default.Command_NUMARALANDIR_Order; form.Prefix = Properties.Settings.Default.Command_NUMARALANDIR_Prefix; form.StartNumber = Properties.Settings.Default.Command_NUMARALANDIR_StartNumber; form.Increment = Properties.Settings.Default.Command_NUMARALANDIR_Increment; form.Format = Properties.Settings.Default.Command_NUMARALANDIR_Format; form.Suffix = Properties.Settings.Default.Command_NUMARALANDIR_Suffix; if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK) { // Save changes Properties.Settings.Default.Command_NUMARALANDIR_SelectObjects = (int)form.SelectObjects; Properties.Settings.Default.Command_NUMARALANDIR_AttributeName = form.AttributeName; Properties.Settings.Default.Command_NUMARALANDIR_Order = (int)form.Ordering; Properties.Settings.Default.Command_NUMARALANDIR_Prefix = form.Prefix; Properties.Settings.Default.Command_NUMARALANDIR_StartNumber = form.StartNumber; Properties.Settings.Default.Command_NUMARALANDIR_Increment = form.Increment; Properties.Settings.Default.Command_NUMARALANDIR_Format = form.Format; Properties.Settings.Default.Command_NUMARALANDIR_Suffix = form.Suffix; // Select objects List <TypedValue> tvs = new List <TypedValue>(); switch (form.SelectObjects) { case NumberingForm.SelectNumberingObjects.Text: tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR")); tvs.Add(new TypedValue((int)DxfCode.Start, "TEXT")); tvs.Add(new TypedValue((int)DxfCode.Start, "MTEXT")); tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>")); break; default: tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR")); tvs.Add(new TypedValue((int)DxfCode.Start, "INSERT")); tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>")); break; } SelectionFilter filter = new SelectionFilter(tvs.ToArray()); PromptSelectionResult selRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(filter); if (selRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) { try { List <Tuple <ObjectId, Point3d> > items = new List <Tuple <ObjectId, Point3d> >(); // Read objects foreach (ObjectId id in selRes.Value.GetObjectIds()) { if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText obj = tr.GetObject(id, OpenMode.ForRead) as DBText; items.Add(new Tuple <ObjectId, Point3d>(id, obj.Position.TransformBy(wcs2ucs))); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(MText)).UnmanagedObject) { MText obj = tr.GetObject(id, OpenMode.ForRead) as MText; items.Add(new Tuple <ObjectId, Point3d>(id, obj.Location.TransformBy(wcs2ucs))); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject) { BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference; items.Add(new Tuple <ObjectId, Point3d>(id, obj.Position.TransformBy(wcs2ucs))); } } // Sort items by coordinates items.Sort((p1, p2) => { switch (form.Ordering) { case NumberingForm.CoordinateOrdering.IncreasingX: return(p1.Item2.X < p2.Item2.X ? -1 : 1); case NumberingForm.CoordinateOrdering.IncreasingY: return(p1.Item2.Y < p2.Item2.Y ? -1 : 1); case NumberingForm.CoordinateOrdering.DecreasingX: return(p1.Item2.X > p2.Item2.X ? -1 : 1); case NumberingForm.CoordinateOrdering.DecreasingY: return(p1.Item2.Y > p2.Item2.Y ? -1 : 1); default: return(0); } }); // Write numbering text double num = form.StartNumber; string format = form.Format; foreach (Tuple <ObjectId, Point3d> item in items) { bool found = false; ObjectId id = item.Item1; string numstr = num.ToString(format); string text = form.Prefix + numstr + form.Suffix; if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText obj = tr.GetObject(id, OpenMode.ForWrite) as DBText; obj.TextString = text; found = true; } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(MText)).UnmanagedObject) { MText obj = tr.GetObject(id, OpenMode.ForWrite) as MText; obj.Contents = text; found = true; } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject) { BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference; foreach (ObjectId attId in obj.AttributeCollection) { AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead); if (string.Compare(attRef.Tag, form.AttributeName, StringComparison.OrdinalIgnoreCase) == 0) { attRef.UpgradeOpen(); attRef.TextString = text; found = true; } } } if (found) { // Only increment if a change was made num += form.Increment; } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } } } } }
public void LevelLabel() { if (!CheckLicense.Check()) { return; } if (!init) { if (!ShowSettings()) { return; } } while (true) { PromptPointOptions ptOpts = new PromptPointOptions("\nKot noktası: [Reset/Güncelle]", "Reset Update"); PromptPointResult ptRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(ptOpts); if (ptRes.Status == PromptStatus.Cancel) { return; } else if (ptRes.Status == PromptStatus.Keyword && ptRes.StringResult == "Reset") { Reset(); return; } else if (ptRes.Status == PromptStatus.Keyword && ptRes.StringResult == "Update") { PromptSelectionResult selRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(); if (selRes.Status != PromptStatus.OK) { return; } UpdateLevelBlocks(selRes.Value.GetObjectIds()); return; } else { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; ObjectId blockId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) { if (bt.Has(BlockName)) { blockId = bt[BlockName]; } tr.Commit(); } if (blockId.IsNull) { MessageBox.Show("Kot bloğu '" + BlockName + "' bulunamadı.", "Level", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string level = GetLevel(ptRes.Value); Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Point3d ptWorld = ptRes.Value.TransformBy(ucs2wcs); double rotation = Math.Atan2(ucs2wcs.CoordinateSystem3d.Xaxis.Y, ucs2wcs.CoordinateSystem3d.Xaxis.X); using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { BlockReference bref = new BlockReference(ptWorld, blockId); bref.Rotation = rotation; bref.ScaleFactors = new Scale3d(BlockScale); btr.AppendEntity(bref); tr.AddNewlyCreatedDBObject(bref, true); Dictionary <AttributeReference, AttributeDefinition> dict = new Dictionary <AttributeReference, AttributeDefinition>(); BlockTableRecord blockDef = tr.GetObject(blockId, OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId id in blockDef) { AttributeDefinition attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition; if ((attDef != null) && (!attDef.Constant)) { // Create a new AttributeReference AttributeReference attRef = new AttributeReference(); dict.Add(attRef, attDef); attRef.SetAttributeFromBlock(attDef, bref.BlockTransform); attRef.TextString = level; bref.AttributeCollection.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(attRef, true); } } if (LevelJig.Jig(ptRes.Value, bref, dict)) { Line line = new Line(); line.StartPoint = ptWorld; line.EndPoint = bref.Position; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } else { bref.Dispose(); tr.Abort(); return; } } } } }
public void TrenchExcavation() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } Topography topo = Topography.Instance; TriangleNet.Mesh mesh = (surface == Topography.SurfaceType.Original ? topo.OriginalTIN : topo.ProposedTIN); // Pick polyline bool flag = true; ObjectId centerlineId = ObjectId.Null; while (flag) { PromptEntityOptions entityOpts = new PromptEntityOptions("\nKazı tabanı [Seçenekler]:", "Settings"); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.Keyword && entityRes.StringResult == "Settings") { ShowSettings(); continue; } else if (entityRes.Status == PromptStatus.OK) { centerlineId = entityRes.ObjectId; break; } else { return; } } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Curve centerline = tr.GetObject(centerlineId, OpenMode.ForRead) as Curve; // Excavate TrenchExcavation ex = new TrenchExcavation(mesh, centerline, Width, ExcavationStepSize); ExcavationSection slope = new ExcavationSection(); slope.AddSlope(ExcavationH, ExcavationV); ex.AddSection(0, slope); ex.Excavate(); // Draw excavation boundries Point3dCollection bottombounds = new Point3dCollection(); Point3dCollection topbounds = new Point3dCollection(); bool closed = true; bool alt = false; foreach (ExcavationSection section in ex.OutputSections) { if (section.Elements[section.Elements.Count - 1].HasTopPoint) { bottombounds.Add(section.Elements[0].BottomPoint); topbounds.Add(section.Elements[section.Elements.Count - 1].TopPoint); Point3d pt1 = section.Elements[0].BottomPoint; Point3d pt2 = section.Elements[section.Elements.Count - 1].TopPoint; if (alt) { pt1 = pt1 + (pt2 - pt1) / 2; } Line line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2); line.ColorIndex = 11; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } else { if (bottombounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, bottombounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } if (topbounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, topbounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } closed = false; topbounds = new Point3dCollection(); } alt = !alt; } if (bottombounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, bottombounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } if (topbounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, closed, topbounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } }
public void DrawAxes() { if (!CheckLicense.Check()) { return; } var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; var db = doc.Database; // Reset parameters Alignment = Bridge.AlignmentType.None; CenterlineId = ObjectId.Null; StartPoint = Point3d.Origin; StartCH = 0; SelectionMethod = AxisSelectionMethod.Point; AxisDistance = DefaultAxisDistance; LastAxisPoint = Point3d.Origin; Prefix = "A"; Suffix = ""; Number = 1; FirstRun = true; // Pick alignment if (!GetAlignmentParameters()) { return; } // Print axes while (true) { // Calculate axis insertion point and chainage if (GetAxisInsertionPoint(out Point3d axisPoint, out double axisDistanceFromStartPoint, out Vector3d axisDirection)) { // Axis name if (!GetAxisName()) { return; } if (DrawingType == AxisDrawingType.Line || !AcadEntity.BlockExists(db, BlockName)) { DrawAxisLine(axisPoint, axisDirection, StartCH + axisDistanceFromStartPoint); } else { DrawAxisBlock(axisPoint, axisDirection, StartCH + axisDistanceFromStartPoint); } // Increment axis number FirstRun = false; Number += 1; LastAxisPoint = axisPoint; } else { break; } } }
public static void XCOMBatch() { if (!CheckLicense.Check()) { return; } using (MainForm mainForm = new MainForm()) { if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(mainForm) == System.Windows.Forms.DialogResult.OK) { // Read settings var deploy = new Deploy(); // Add source files string[] filenames = mainForm.Filenames; deploy.AddFiles(filenames); // Add actions IXCOMAction[] actions = mainForm.SelectedActions; deploy.AddActions(actions); ProgressForm progressForm = new ProgressForm(); Thread thread = new Thread(() => { Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(progressForm); }); thread.IsBackground = true; thread.Start(); deploy.DeployStarted += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.Start(filenames, 1 + actions.Length); })); } else { progressForm.Start(filenames, 3 + actions.Length); } }; deploy.FileStarted += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.StartFile(e.Filename); })); } else { progressForm.StartFile(e.Filename); } }; deploy.FileOpened += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.ActionComplete(e.Filename, "Aç"); })); } else { progressForm.ActionComplete(e.Filename, "Aç"); } if (e.Error != null) { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.ActionError(e.Filename, e.Error.ToString()); })); } else { progressForm.ActionError(e.Filename, e.Error.ToString()); } } }; deploy.ActionError += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.ActionError(e.Filename, e.Error.ToString()); })); } else { progressForm.ActionError(e.Filename, e.Error.ToString()); } }; deploy.ActionCompleted += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.ActionComplete(e.Filename, e.ActionName); })); } else { progressForm.ActionComplete(e.Filename, e.ActionName); } }; deploy.FileCompleted += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.FileComplete(e.Filename); })); } else { progressForm.FileComplete(e.Filename); } }; deploy.DeployCompleted += (sender, e) => { if (progressForm.InvokeRequired) { progressForm.Invoke(new Action(() => { progressForm.Complete(); })); } else { progressForm.Complete(); } }; // Start processing deploy.RunBatch(); } } }
public void PrintChainage() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; ObjectId textStyleId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } tr.Commit(); } Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs; // Pick polyline bool flag = true; ObjectId centerlineId = ObjectId.Null; while (flag) { PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: [Seçenekler]", "Settings"); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.Keyword && entityRes.StringResult == "Settings") { ShowSettings(); continue; } else if (entityRes.Status == PromptStatus.OK) { centerlineId = entityRes.ObjectId; break; } else { return; } } // Start point Point3d startPoint; PromptPointResult pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nBaşlangıç Noktası: "); if (pointRes.Status == PromptStatus.OK) { startPoint = pointRes.Value.TransformBy(ucs2wcs); } else { return; } // Start CH string startCH = ""; PromptResult stringRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetString("\nBaşlangıç KM: <0+000.00>"); startCH = stringRes.StringResult; if (stringRes.Status == PromptStatus.None) { startCH = "0+000.00"; } else if (stringRes.Status != PromptStatus.OK) { return; } // Print chainages using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { Autodesk.AutoCAD.DatabaseServices.Curve centerline = tr.GetObject(centerlineId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Curve; if (centerline != null) { double curveStartCH = AcadText.ChainageFromString(startCH) - centerline.GetDistAtPoint(startPoint); double distToNearestInterval = Math.Ceiling(curveStartCH / Interval) * Interval - curveStartCH; double currentDistance = distToNearestInterval; double curveLength = centerline.GetDistanceAtParameter(centerline.EndParam); while (currentDistance < curveLength) { string currentCH = AcadText.ChainageToString(currentDistance + curveStartCH, Precision); Point3d currentPoint = centerline.GetPointAtDist(currentDistance); Vector3d perp = centerline.GetFirstDerivative(currentPoint).RotateBy(Math.PI / 2.0, Vector3d.ZAxis); perp /= perp.Length; Point3d lineStart = currentPoint + perp * TextHeight / 2.0; Point3d lineEnd = currentPoint - perp * TextHeight / 2.0; Point3d textStart = currentPoint + perp * TextHeight / 2.0 * 1.2; // Tick mark Line line = new Line(); line.StartPoint = lineStart; line.EndPoint = lineEnd; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); // CH text double textRotation = Vector3d.XAxis.GetAngleTo(perp, Vector3d.ZAxis); double rot = textRotation * 180 / Math.PI; TextHorizontalMode textHorizontalMode = TextHorizontalMode.TextLeft; if (rot > 90.0 && rot < 270.0) { textRotation = textRotation + Math.PI; textHorizontalMode = TextHorizontalMode.TextRight; } textStyleId = ObjectId.Null; if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } DBText text = AcadEntity.CreateText(db, textStart, currentCH, TextHeight, textRotation, 0.8, textHorizontalMode, TextVerticalMode.TextVerticalMid, textStyleId); btr.AppendEntity(text); tr.AddNewlyCreatedDBObject(text, true); currentDistance += Interval; } } tr.Commit(); } }
public void PrintEntityCoordinates() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs; using (PrintEntitiesForm form = new PrintEntitiesForm()) { // Read settings form.SelectPoint = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPoint; form.SelectCircle = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectCircle; form.SelectLine = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectLine; form.SelectPolyline = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPolyline; form.Select3DFace = Properties.Settings.Default.Command_PRINTENTCOORDS_Select3DFace; form.SelectText = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectText; form.SelectBlock = Properties.Settings.Default.Command_PRINTENTCOORDS_SelectBlock; form.UseUCS = Properties.Settings.Default.Command_PRINTENTCOORDS_UCS; form.SetLineFormats(Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Cast <string>()); form.Precision = Properties.Settings.Default.Command_PRINTENTCOORDS_Precision; if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK) { // Save changes Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPoint = form.SelectPoint; Properties.Settings.Default.Command_PRINTENTCOORDS_SelectCircle = form.SelectCircle; Properties.Settings.Default.Command_PRINTENTCOORDS_SelectLine = form.SelectLine; Properties.Settings.Default.Command_PRINTENTCOORDS_SelectPolyline = form.SelectPolyline; Properties.Settings.Default.Command_PRINTENTCOORDS_Select3DFace = form.Select3DFace; Properties.Settings.Default.Command_PRINTENTCOORDS_SelectText = form.SelectText; Properties.Settings.Default.Command_PRINTENTCOORDS_SelectBlock = form.SelectBlock; Properties.Settings.Default.Command_PRINTENTCOORDS_UCS = form.UseUCS; string selectedFormat = form.LineFormat; bool found = false; foreach (string format in Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat) { if (string.Compare(format, selectedFormat) == 0) { found = true; break; } } if (!found) { Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Insert(0, selectedFormat); } while (Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Count > 40) { Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.RemoveAt(Properties.Settings.Default.Command_PRINTENTCOORDS_LineFormat.Count - 1); } Properties.Settings.Default.Command_PRINTENTCOORDS_Precision = form.Precision; Properties.Settings.Default.Save(); // Select objects List <TypedValue> tvs = new List <TypedValue>(); tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR")); if (form.SelectPoint) { tvs.Add(new TypedValue((int)DxfCode.Start, "POINT")); } if (form.SelectCircle) { tvs.Add(new TypedValue((int)DxfCode.Start, "CIRCLE")); } if (form.SelectLine) { tvs.Add(new TypedValue((int)DxfCode.Start, "LINE")); } if (form.SelectPolyline) { tvs.Add(new TypedValue((int)DxfCode.Start, "POLYLINE")); } if (form.SelectPolyline) { tvs.Add(new TypedValue((int)DxfCode.Start, "LWPOLYLINE")); } if (form.Select3DFace) { tvs.Add(new TypedValue((int)DxfCode.Start, "3DFACE")); } if (form.SelectText) { tvs.Add(new TypedValue((int)DxfCode.Start, "TEXT")); } if (form.SelectText) { tvs.Add(new TypedValue((int)DxfCode.Start, "MTEXT")); } if (form.SelectBlock) { tvs.Add(new TypedValue((int)DxfCode.Start, "INSERT")); } tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>")); SelectionFilter filter = new SelectionFilter(tvs.ToArray()); PromptSelectionResult selRes = doc.Editor.GetSelection(filter); if (selRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) { try { var listPoints = new List <Point3d>(); var listCircles = new List <Point3d>(); var listTexts = new List <Point3d>(); var listBlocks = new List <Point3d>(); var listLines = new List <Tuple <Point3d, Point3d> >(); var listPolylines = new List <Point3dCollection>(); var list3DFaces = new List <Tuple <Point3d, Point3d, Point3d, Point3d> >(); Point3d GetPoint(Point3d pt) => form.UseUCS ? pt : pt.TransformBy(wcs2ucs); // Read objects foreach (ObjectId id in selRes.Value.GetObjectIds()) { if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBPoint)).UnmanagedObject) { DBPoint obj = tr.GetObject(id, OpenMode.ForRead) as DBPoint; listPoints.Add(GetPoint(obj.Position)); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Circle)).UnmanagedObject) { Circle obj = tr.GetObject(id, OpenMode.ForRead) as Circle; listCircles.Add(GetPoint(obj.Center)); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(DBText)).UnmanagedObject) { DBText obj = tr.GetObject(id, OpenMode.ForRead) as DBText; listTexts.Add(GetPoint(obj.Position)); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(MText)).UnmanagedObject) { MText obj = tr.GetObject(id, OpenMode.ForRead) as MText; listTexts.Add(GetPoint(obj.Location)); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(BlockReference)).UnmanagedObject) { BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference; listBlocks.Add(GetPoint(obj.Position)); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Line)).UnmanagedObject) { Line obj = tr.GetObject(id, OpenMode.ForRead) as Line; listLines.Add(new Tuple <Point3d, Point3d>(GetPoint(obj.StartPoint), GetPoint(obj.EndPoint))); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Face)).UnmanagedObject) { Face obj = tr.GetObject(id, OpenMode.ForRead) as Face; list3DFaces.Add(new Tuple <Point3d, Point3d, Point3d, Point3d>( GetPoint(obj.GetVertexAt(0)), GetPoint(obj.GetVertexAt(1)), GetPoint(obj.GetVertexAt(2)), GetPoint(obj.GetVertexAt(3)))); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline)).UnmanagedObject) { Polyline obj = tr.GetObject(id, OpenMode.ForRead) as Polyline; Point3dCollection points = new Point3dCollection(); for (int i = 0; i < obj.NumberOfVertices; i++) { points.Add(GetPoint(obj.GetPoint3dAt(i))); } listPolylines.Add(points); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline2d)).UnmanagedObject) { Polyline2d obj = tr.GetObject(id, OpenMode.ForRead) as Polyline2d; Point3dCollection points = new Point3dCollection(); foreach (ObjectId vId in obj) { Vertex2d vertex = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead); points.Add(GetPoint(vertex.Position)); } listPolylines.Add(points); } else if (id.ObjectClass.UnmanagedObject == RXClass.GetClass(typeof(Polyline3d)).UnmanagedObject) { Polyline3d obj = tr.GetObject(id, OpenMode.ForRead) as Polyline3d; Point3dCollection points = new Point3dCollection(); foreach (ObjectId vId in obj) { PolylineVertex3d vertex = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead); points.Add(GetPoint(vertex.Position)); } listPolylines.Add(points); } } // Write text using (System.IO.StreamWriter file = new System.IO.StreamWriter(form.OutputFilename)) { string PrintCoord(double coord) => coord.ToString(form.Precision == 0 ? "0" : "0." + new string('0', form.Precision)); string ClearLine(string line) => line.Replace("[X]", "").Replace("[Y]", "").Replace("[Z]", "") .Replace("[X1]", "").Replace("[Y1]", "").Replace("[Z1]", "") .Replace("[X2]", "").Replace("[Y2]", "").Replace("[Z2]", "") .Replace("[X3]", "").Replace("[Y3]", "").Replace("[Z3]", "") .Replace("[X4]", "").Replace("[Y4]", "").Replace("[Z4]", ""); var headerStr = form.LineFormat.Replace("[", "").Replace("]", ""); void PrintPointList(List <Point3d> points) { file.WriteLine(headerStr); int i = 1; foreach (var pt in points) { var str = form.LineFormat; str = str.Replace("[#]", i.ToString()); str = str.Replace("[X]", PrintCoord(pt.X)); str = str.Replace("[Y]", PrintCoord(pt.Y)); str = str.Replace("[Z]", PrintCoord(pt.Z)); str = str.Replace("[X1]", PrintCoord(pt.X)); str = str.Replace("[Y1]", PrintCoord(pt.Y)); str = str.Replace("[Z1]", PrintCoord(pt.Z)); str = ClearLine(str); file.WriteLine(str); i++; } } // Point if (listPoints.Count > 0) { file.WriteLine("POINT({0})", listPoints.Count); PrintPointList(listPoints); } // Circle if (listCircles.Count > 0) { file.WriteLine("CIRCLE({0})", listCircles.Count); PrintPointList(listCircles); } // Line if (listLines.Count > 0) { file.WriteLine("LINE({0})", listLines.Count); file.WriteLine(headerStr); int i = 1; foreach (var points in listLines) { var pt1 = points.Item1; var pt2 = points.Item2; var str = form.LineFormat; str = str.Replace("[#]", i.ToString()); str = str.Replace("[X1]", PrintCoord(pt1.X)); str = str.Replace("[Y1]", PrintCoord(pt1.Y)); str = str.Replace("[Z1]", PrintCoord(pt1.Z)); str = str.Replace("[X2]", PrintCoord(pt2.X)); str = str.Replace("[Y2]", PrintCoord(pt2.Y)); str = str.Replace("[Z2]", PrintCoord(pt2.Z)); str = ClearLine(str); file.WriteLine(str); i++; } } // Polyline if (listPolylines.Count > 0) { file.WriteLine("POLYLINE({0})", listPolylines.Count); int i = 1; foreach (var polyline in listPolylines) { file.WriteLine("POLYLINE-{0}", i); file.WriteLine(headerStr); for (int j = 0; j < polyline.Count; j++) { var str = form.LineFormat; str = str.Replace("[#]", (j + 1).ToString()); str = str.Replace("[X]", PrintCoord(polyline[j].X)); str = str.Replace("[Y]", PrintCoord(polyline[j].Y)); str = str.Replace("[Z]", PrintCoord(polyline[j].Z)); str = str.Replace("[X1]", PrintCoord(polyline[j].X)); str = str.Replace("[Y1]", PrintCoord(polyline[j].Y)); str = str.Replace("[Z1]", PrintCoord(polyline[j].Z)); str = ClearLine(str); file.WriteLine(str); } i++; } } // 3DFace if (list3DFaces.Count > 0) { file.WriteLine("3DFACE({0})", list3DFaces.Count); file.WriteLine(headerStr); int i = 1; foreach (var points in list3DFaces) { var pt1 = points.Item1; var pt2 = points.Item2; var pt3 = points.Item3; var pt4 = points.Item4; var str = form.LineFormat; str = str.Replace("[#]", i.ToString()); str = str.Replace("[X1]", PrintCoord(pt1.X)); str = str.Replace("[Y1]", PrintCoord(pt1.Y)); str = str.Replace("[Z1]", PrintCoord(pt1.Z)); str = str.Replace("[X2]", PrintCoord(pt2.X)); str = str.Replace("[Y2]", PrintCoord(pt2.Y)); str = str.Replace("[Z2]", PrintCoord(pt2.Z)); str = str.Replace("[X3]", PrintCoord(pt3.X)); str = str.Replace("[Y3]", PrintCoord(pt3.Y)); str = str.Replace("[Z3]", PrintCoord(pt3.Z)); str = str.Replace("[X4]", PrintCoord(pt4.X)); str = str.Replace("[Y4]", PrintCoord(pt4.Y)); str = str.Replace("[Z4]", PrintCoord(pt4.Z)); str = ClearLine(str); file.WriteLine(str); i++; } } // Text if (listTexts.Count > 0) { file.WriteLine("TEXT({0})", listTexts.Count); PrintPointList(listTexts); } // Block if (listBlocks.Count > 0) { file.WriteLine("BLOCK({0})", listBlocks.Count); PrintPointList(listBlocks); } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } } } } }
public void DrawGradeLines() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; Editor ed = doc.Editor; PromptEntityResult topRes = ed.GetEntity("\nŞev üstü "); if (topRes.Status != PromptStatus.OK) { return; } if (!topRes.ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Curve)))) { return; } PromptEntityResult botRes = ed.GetEntity("\nŞev altı "); if (botRes.Status != PromptStatus.OK) { return; } if (!botRes.ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Curve)))) { return; } PromptDistanceOptions disOpts = new PromptDistanceOptions("Tarama sıklığı "); disOpts.AllowNegative = false; disOpts.AllowZero = false; disOpts.DefaultValue = LineSpacing; disOpts.UseDefaultValue = true; PromptDoubleResult disRes = ed.GetDistance(disOpts); if (disRes.Status != PromptStatus.OK) { return; } LineSpacing = disRes.Value; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { Curve top = (Curve)tr.GetObject(topRes.ObjectId, OpenMode.ForRead); Curve bot = (Curve)tr.GetObject(botRes.ObjectId, OpenMode.ForRead); double botLen = Math.Abs(bot.GetDistanceAtParameter(bot.EndParam) - bot.GetDistanceAtParameter(bot.StartParam)); double topLen = Math.Abs(top.GetDistanceAtParameter(top.EndParam) - top.GetDistanceAtParameter(bot.StartParam)); double len = Math.Max(botLen, topLen); bool rev = (botLen > topLen); int count = (int)Math.Round(len / disRes.Value); if (count > 0) { double startDist = rev ? bot.GetDistanceAtParameter(bot.StartParam) : top.GetDistanceAtParameter(top.StartParam); double endDist = rev ? bot.GetDistanceAtParameter(bot.EndParam) : top.GetDistanceAtParameter(top.EndParam); double distStep = (endDist - startDist) / (double)count; double dist = startDist; bool half = false; for (int i = 0; i <= count; i++) { Point3d pt1, pt2; try { pt1 = (rev ? bot : top).GetPointAtDist(dist); pt2 = (rev ? top : bot).GetClosestPointTo(pt1, false); } catch (System.Exception) { continue; } Point3d startPt = rev ? pt2 : pt1; Point3d endPt = rev ? pt1 : pt2; if (half) { endPt = new LineSegment3d(startPt, endPt).MidPoint; } Line ln = AcadUtility.AcadEntity.CreateLine(db, startPt, endPt); btr.AppendEntity(ln); tr.AddNewlyCreatedDBObject(ln, true); dist += distStep; half = !half; } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
public void ProfileOnCurve() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick alignment bool flag = true; ObjectId curveId = ObjectId.Null; while (flag) { PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen [Seçenekler]: ", "Settings"); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.Keyword) { ShowSettings(); } else if (entityRes.Status == PromptStatus.OK) { curveId = entityRes.ObjectId; break; } else if (entityRes.Status == PromptStatus.Cancel) { return; } } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; ObjectId textStyleId = ObjectId.Null; using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } } // Project curve onto surface Topography topo = Topography.Instance; Curve curve = tr.GetObject(curveId, OpenMode.ForRead) as Curve; Point2dCollection points = topo.ProfileOnCurve(curve, surface); // Base point for profile drawing PromptPointResult pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nProfil başlangıcı: "); if (pointRes.Status != PromptStatus.OK) { return; } Point3d basePt = pointRes.Value; if (points.Count > 0) { // Limits Extents2d ex = AcadUtility.AcadGeometry.Limits(points); // Base level for profile drawing PromptDoubleOptions levelOpts = new PromptDoubleOptions("\nProfil baz kotu: "); levelOpts.DefaultValue = Math.Floor(ex.MinPoint.Y / ProfileGridV) * ProfileGridV; levelOpts.UseDefaultValue = true; PromptDoubleResult levelRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(levelOpts); if (pointRes.Status != PromptStatus.OK) { return; } double startLevel = levelRes.Value; double endLevel = Math.Ceiling(ex.MaxPoint.Y / ProfileGridV + 1) * ProfileGridV; // Base chainage for profile drawing double startCh = 0; flag = true; while (flag) { PromptStringOptions chOpts = new PromptStringOptions("\nProfil baz KM: "); chOpts.DefaultValue = AcadUtility.AcadText.ChainageToString(0, Precision); chOpts.UseDefaultValue = true; PromptResult chRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetString(chOpts); if (chRes.Status != PromptStatus.OK) { return; } if (AcadUtility.AcadText.TryChainageFromString(chRes.StringResult, out startCh)) { break; } } double endCh = Math.Ceiling((startCh + ex.MaxPoint.X) / ProfileGridH) * ProfileGridH; // Draw grid IEnumerable <Entity> entities = DrawProfileFrame(db, basePt, startCh, startLevel, endCh, endLevel, ProfileGridH, ProfileGridV, ProfileVScale, TextHeight, Precision, textStyleId); foreach (Entity ent in entities) { ent.TransformBy(ucs2wcs); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } // Draw profile ObjectId profileLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Eksen", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 5)); Point2dCollection trPoints = new Point2dCollection(points.Count); foreach (Point2d pt in points) { trPoints.Add(new Point2d(basePt.X + pt.X, basePt.Y + (pt.Y - startLevel) * ProfileVScale)); } Polyline pline = AcadUtility.AcadEntity.CreatePolyLine(db, false, trPoints); pline.TransformBy(ucs2wcs); pline.LayerId = profileLayerId; btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } }
public void Coord() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; if (!init) { if (!ShowSettings()) { return; } } bool flag = true; ObjectId textStyleId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } tr.Commit(); } Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; while (flag) { PromptPointResult pointRes = null; if (AutoNumbering) { PromptPointOptions pointOpts = new PromptPointOptions("\n" + CurrentNumber.ToString() + ". Koordinat yeri: [Reset/Liste/Seç]", "Reset List Select"); pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pointOpts); } else { PromptPointOptions pointOpts = new PromptPointOptions("\nKoordinat yeri: [Reset/Seç]", "Reset Select"); pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pointOpts); } if (pointRes.Status == PromptStatus.Cancel) { return; } else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "Reset") { Reset(); return; } else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "List") { PromptPointOptions listOpts = new PromptPointOptions("\nListe yeri: "); PromptPointResult listRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(listOpts); ShowList(listRes.Value); return; } else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "Select") { using (SelectObjectsForm form = new SelectObjectsForm()) { if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK) { // Select objects List <TypedValue> tvs = new List <TypedValue>(); switch (form.SelectObjects) { case SelectObjectsForm.SelectCoordinateObjects.Polyline: tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR")); tvs.Add(new TypedValue((int)DxfCode.Start, "LWPOLYLINE")); tvs.Add(new TypedValue((int)DxfCode.Start, "POLYLINE")); tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>")); break; case SelectObjectsForm.SelectCoordinateObjects.Circle: tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR")); tvs.Add(new TypedValue((int)DxfCode.Start, "CIRCLE")); tvs.Add(new TypedValue((int)DxfCode.Start, "ARC")); tvs.Add(new TypedValue((int)DxfCode.Start, "ELLIPSE")); tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>")); break; case SelectObjectsForm.SelectCoordinateObjects.Block: tvs.Add(new TypedValue((int)DxfCode.Start, "INSERT")); break; case SelectObjectsForm.SelectCoordinateObjects.Point: tvs.Add(new TypedValue((int)DxfCode.Start, "POINT")); break; case SelectObjectsForm.SelectCoordinateObjects.Line: tvs.Add(new TypedValue((int)DxfCode.Start, "LINE")); break; } SelectionFilter filter = new SelectionFilter(tvs.ToArray()); PromptSelectionResult selRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(filter); if (selRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { TextPositioner positioner = new TextPositioner(ucs2wcs, TextRotation * Math.PI / 180, LineLength); // Read object coordinates List <TextPositioner.SelectedObjectCoordinate> objectPoints = new List <TextPositioner.SelectedObjectCoordinate>(); foreach (ObjectId id in selRes.Value.GetObjectIds()) { if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline))) { Autodesk.AutoCAD.DatabaseServices.Polyline obj = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline; positioner.ClearPoints(); for (int i = 0; i < obj.NumberOfVertices; i++) { positioner.AddPoint(obj.GetPoint3dAt(i)); } objectPoints.AddRange(positioner.GetPositions()); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Circle))) { Circle obj = tr.GetObject(id, OpenMode.ForRead) as Circle; objectPoints.Add(positioner.GetPosition(obj.Center)); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Arc))) { Arc obj = tr.GetObject(id, OpenMode.ForRead) as Arc; objectPoints.Add(positioner.GetPosition(obj.Center)); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Ellipse))) { Ellipse obj = tr.GetObject(id, OpenMode.ForRead) as Ellipse; objectPoints.Add(positioner.GetPosition(obj.Center)); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.BlockReference))) { BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference; objectPoints.Add(positioner.GetPosition(obj.Position)); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.DBPoint))) { DBPoint obj = tr.GetObject(id, OpenMode.ForRead) as DBPoint; objectPoints.Add(positioner.GetPosition(obj.Position)); } else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line))) { Line obj = tr.GetObject(id, OpenMode.ForRead) as Line; positioner.ClearPoints(); positioner.AddPoint(obj.StartPoint); positioner.AddPoint(obj.EndPoint); objectPoints.AddRange(positioner.GetPositions()); } } // Sort coordinates objectPoints.Sort((p1, p2) => { switch (form.Ordering) { case SelectObjectsForm.CoordinateOrdering.IncreasingX: return(p1.BasePoint.X < p2.BasePoint.X ? -1 : 1); case SelectObjectsForm.CoordinateOrdering.IncreasingY: return(p1.BasePoint.Y < p2.BasePoint.Y ? -1 : 1); case SelectObjectsForm.CoordinateOrdering.DecreasingX: return(p1.BasePoint.X > p2.BasePoint.X ? -1 : 1); case SelectObjectsForm.CoordinateOrdering.DecreasingY: return(p1.BasePoint.Y > p2.BasePoint.Y ? -1 : 1); default: return(0); } }); // Write coordinates foreach (TextPositioner.SelectedObjectCoordinate coord in objectPoints) { MText mtext = CreateText(textStyleId, coord.TextPoint); btr.AppendEntity(mtext); tr.AddNewlyCreatedDBObject(mtext, true); // Rotate text if (coord.TextToLeft) { mtext.Attachment = (AutoNumbering ? AttachmentPoint.BottomRight : AttachmentPoint.MiddleRight); } else { mtext.Attachment = (AutoNumbering ? AttachmentPoint.BottomLeft : AttachmentPoint.MiddleLeft); } Line line = new Line(); line.StartPoint = coord.BasePoint; line.EndPoint = coord.TextPoint; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); points.Add(new CoordPoint(CurrentNumber, coord.BasePoint)); if (AutoNumbering) { CurrentNumber = CurrentNumber + 1; } } tr.Commit(); } } } } return; } else { Point3d pCoord = pointRes.Value.TransformBy(ucs2wcs); using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { MText mtext = CreateText(textStyleId, pCoord); btr.AppendEntity(mtext); tr.AddNewlyCreatedDBObject(mtext, true); if (CoordinateJig.Jig(pointRes.Value, mtext, AutoLine, LineLength, AutoRotateText, TextRotation)) { points.Add(new CoordPoint(CurrentNumber, pCoord)); if (AutoNumbering) { CurrentNumber = CurrentNumber + 1; } Line line = new Line(); line.StartPoint = pCoord; line.EndPoint = mtext.Location; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } else { mtext.Dispose(); tr.Abort(); return; } } } } }
public void RenameBlock() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; // Select block name in dialog if there is one picked string selectBlockName = ""; PromptSelectionResult selRes = doc.Editor.SelectImplied(); if (selRes.Status == PromptStatus.OK) { var selSet = selRes.Value; if (selSet.Count > 0) { var id = selSet[0].ObjectId; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockReference bref = tr.GetObject(id, OpenMode.ForRead) as BlockReference; if (bref != null) { if (bref.IsDynamicBlock) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead); selectBlockName = btr.Name; } else { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead); selectBlockName = btr.Name; } } } } } var allNames = AcadSymbolTable.GetBlockTableRecords(db); var tempNames = new Dictionary <string, string>(); int tempCount = 1; using (RenameBlockForm form = new RenameBlockForm()) { foreach (var item in AcadSymbolTable.GetBlockTableRecords(db, p => !p.IsLayout && !p.IsFromExternalReference && !p.IsFromOverlayReference, p => new { p.Name, p.IsAnonymous, p.PreviewIcon })) { form.AddBlockName(item.Name, item.IsAnonymous, item.PreviewIcon); // Create a temporary name for this block string tempName = "_TMP_BLOCK_NAME_" + tempCount.ToString(); while (allNames.ContainsKey(tempName)) { tempCount++; tempName = "_TMP_BLOCK_NAME_" + tempCount.ToString(); } tempNames.Add(item.Name, tempName); tempCount++; } form.SelectBlock(selectBlockName); // Rename blocks if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK) { var names = form.BlockNames; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) { try { // Set temporary names first to prevent name collisions foreach (var pair in names) { ObjectId id = bt[pair.Key]; BlockTableRecord btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForWrite); btr.Name = tempNames[pair.Key]; } // Set final names now foreach (var pair in names) { ObjectId id = bt[tempNames[pair.Key]]; BlockTableRecord btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForWrite); btr.Name = pair.Value; } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } } } }
public void DrawCulvertsOnProfile() { if (!CheckLicense.Check()) { return; } if (!ShowSettings()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; using (Transaction tr = db.TransactionManager.StartTransaction()) using (LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead)) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { // Get layer ObjectId layerId = ObjectId.Null; if (lt.Has(LayerName)) { layerId = lt[LayerName]; } else { LayerTableRecord ltr = new LayerTableRecord(); ltr.Name = LayerName; lt.UpgradeOpen(); layerId = lt.Add(ltr); tr.AddNewlyCreatedDBObject(ltr, true); } // Process columns foreach (DrawCulvertForm.CulvertInfo culvert in Data) { Point3d midPt = new Point3d(BasePoint.X + culvert.Chainage - BaseChainage, BasePoint.Y + (culvert.Level - BaseLevel) * this.ProfileScale, 0); // Outer polyline Polyline outerPoly = AcadUtility.AcadEntity.CreatePolyLine(db, true, new Point3d(midPt.X - culvert.Width / 2 - culvert.Wall, midPt.Y - culvert.BottomSlab * ProfileScale, 0).TransformBy(ucs2wcs), new Point3d(midPt.X + culvert.Width / 2 + culvert.Wall, midPt.Y - culvert.BottomSlab * ProfileScale, 0).TransformBy(ucs2wcs), new Point3d(midPt.X + culvert.Width / 2 + culvert.Wall, midPt.Y + culvert.Height * ProfileScale + culvert.TopSlab * ProfileScale, 0).TransformBy(ucs2wcs), new Point3d(midPt.X - culvert.Width / 2 - culvert.Wall, midPt.Y + culvert.Height * ProfileScale + culvert.TopSlab * ProfileScale, 0).TransformBy(ucs2wcs) ); outerPoly.LayerId = layerId; ObjectId outerPolyId = btr.AppendEntity(outerPoly); tr.AddNewlyCreatedDBObject(outerPoly, true); // Inner polyline Polyline innerPoly = AcadUtility.AcadEntity.CreatePolyLine(db, true, new Point3d(midPt.X - culvert.Width / 2, midPt.Y, 0).TransformBy(ucs2wcs), new Point3d(midPt.X + culvert.Width / 2, midPt.Y, 0).TransformBy(ucs2wcs), new Point3d(midPt.X + culvert.Width / 2, midPt.Y + culvert.Height * ProfileScale, 0).TransformBy(ucs2wcs), new Point3d(midPt.X - culvert.Width / 2, midPt.Y + culvert.Height * ProfileScale, 0).TransformBy(ucs2wcs) ); innerPoly.LayerId = layerId; ObjectId innerPolyId = btr.AppendEntity(innerPoly); tr.AddNewlyCreatedDBObject(innerPoly, true); // Hatch Hatch hatch = AcadUtility.AcadEntity.CreateHatch(db, "ANSI31", HatchScale, 0); hatch.LayerId = layerId; btr.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true); hatch.Associative = true; hatch.AppendLoop(HatchLoopTypes.External, new ObjectIdCollection { outerPolyId }); hatch.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection { innerPolyId }); hatch.EvaluateHatch(true); // Axis Line axis = AcadUtility.AcadEntity.CreateLine(db, new Point3d(midPt.X, BasePoint.Y, 0).TransformBy(ucs2wcs), new Point3d(midPt.X, midPt.Y + culvert.Height * ProfileScale + culvert.TopSlab * ProfileScale + 4 * ProfileScale, 0).TransformBy(ucs2wcs) ); axis.LayerId = layerId; btr.AppendEntity(axis); tr.AddNewlyCreatedDBObject(axis, true); // Texts Point3d textBase = new Point3d(midPt.X - TextHeight * 1.25, midPt.Y + culvert.Height * ProfileScale + culvert.TopSlab * ProfileScale + 0.5 * ProfileScale, 0); string text = "KM: " + AcadUtility.AcadText.ChainageToString(culvert.Chainage) + "\\P" + "(" + culvert.Width.ToString("F2") + "x" + culvert.Height.ToString("F2") + ") KUTU MENFEZ"; if (DrawCulvertInfo) { text = text + "\\P" + "L=" + culvert.Length.ToString("F2") + " m" + " FL=" + culvert.Level.ToString("F2") + " m" + " My=%" + culvert.Grade.ToString("F2") + "\\P"; if (culvert.Skew == 0) { text = text + "V=DİK"; } else { text = text + "V=" + culvert.Skew.ToString("F2") + " g"; } if (culvert.WellLength != 0) { text = text + " Kuyu Boyu=" + culvert.WellLength.ToString("F2") + " m"; } } MText mtext = AcadUtility.AcadEntity.CreateMText(db, textBase.TransformBy(ucs2wcs), text, TextHeight, Math.PI / 2.0); mtext.LayerId = layerId; btr.AppendEntity(mtext); tr.AddNewlyCreatedDBObject(mtext, true); } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
public void DrawSurface() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography topo = Topography.Instance; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } TriangleNet.Mesh mesh = (surface == Topography.SurfaceType.Original ? topo.OriginalTIN : topo.ProposedTIN); // Object type PromptKeywordOptions opts = new PromptKeywordOptions("\nÇizim nesneleri [Geçici/3dFace/Point/polyfaceMesh] <Geçici>: ", "Temporary 3dFace Point polyfaceMesh"); opts.Keywords.Default = "Temporary"; opts.AllowNone = true; PromptResult res = doc.Editor.GetKeywords(opts); string outputType = res.StringResult; if (res.Status == PromptStatus.None) { outputType = "Temporary"; } else if (res.Status != PromptStatus.OK) { return; } // Color option opts = new PromptKeywordOptions("\nRenkli çizim [E/H] <E>: ", "Yes No"); opts.Keywords.Default = "Yes"; opts.AllowNone = true; res = doc.Editor.GetKeywords(opts); bool useColor = true; if (res.Status == PromptStatus.None) { useColor = true; } else if (res.Status != PromptStatus.OK) { return; } else { useColor = (string.Compare(res.StringResult, "Yes", StringComparison.OrdinalIgnoreCase) == 0); } double zmin = double.MaxValue; double zmax = double.MinValue; foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { zmin = Math.Min(zmin, v.Attributes[0]); zmax = Math.Max(zmax, v.Attributes[0]); } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { if (string.Compare(outputType, "Temporary", StringComparison.OrdinalIgnoreCase) == 0) { EraseTemporaryGraphics(); foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { TriangleNet.Data.Vertex v1 = tri.GetVertex(0); TriangleNet.Data.Vertex v2 = tri.GetVertex(1); TriangleNet.Data.Vertex v3 = tri.GetVertex(2); Face face = new Face(new Point3d(v1.X, v1.Y, v1.Attributes[0]), new Point3d(v2.X, v2.Y, v2.Attributes[0]), new Point3d(v3.X, v3.Y, v3.Attributes[0]), true, true, true, true); if (useColor) { face.Color = ColorFromZ((v1.Attributes[0] + v2.Attributes[0] + v3.Attributes[0]) / 3, zmin, zmax); } temporaryGraphics.Add(face); } DrawTemporaryGraphics(); } else if (string.Compare(outputType, "3dFace", StringComparison.OrdinalIgnoreCase) == 0) { foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { TriangleNet.Data.Vertex v1 = tri.GetVertex(0); TriangleNet.Data.Vertex v2 = tri.GetVertex(1); TriangleNet.Data.Vertex v3 = tri.GetVertex(2); Face face = new Face(new Point3d(v1.X, v1.Y, v1.Attributes[0]), new Point3d(v2.X, v2.Y, v2.Attributes[0]), new Point3d(v3.X, v3.Y, v3.Attributes[0]), true, true, true, true); if (useColor) { face.Color = ColorFromZ((v1.Attributes[0] + v2.Attributes[0] + v3.Attributes[0]) / 3, zmin, zmax); } btr.AppendEntity(face); tr.AddNewlyCreatedDBObject(face, true); } } else if (string.Compare(outputType, "Point", StringComparison.OrdinalIgnoreCase) == 0) { foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { DBPoint point = new DBPoint(new Point3d(v.X, v.Y, v.Attributes[0])); if (useColor) { point.Color = ColorFromZ(v.Attributes[0], zmin, zmax); } btr.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } } else if (string.Compare(outputType, "polyfaceMesh", StringComparison.OrdinalIgnoreCase) == 0) { PolyFaceMesh pfm = new PolyFaceMesh(); btr.AppendEntity(pfm); tr.AddNewlyCreatedDBObject(pfm, true); // Vertices SortedDictionary <int, Point3d> vertices = new SortedDictionary <int, Point3d>(); foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { vertices.Add(v.ID, new Point3d(v.X, v.Y, v.Attributes[0])); } foreach (KeyValuePair <int, Point3d> v in vertices) { PolyFaceMeshVertex point = new PolyFaceMeshVertex(v.Value); pfm.AppendVertex(point); tr.AddNewlyCreatedDBObject(point, true); } // Faces foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { FaceRecord face = new FaceRecord((short)(tri.P0 + 1), (short)(tri.P1 + 1), (short)(tri.P2 + 1), 0); if (useColor) { face.Color = ColorFromZ((tri.GetVertex(0).Attributes[0] + tri.GetVertex(1).Attributes[0] + tri.GetVertex(2).Attributes[0]) / 3, zmin, zmax); } pfm.AppendFaceRecord(face); tr.AddNewlyCreatedDBObject(face, true); } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
public void MakeCoordGrid() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; ObjectId textStyleId = ObjectId.Null; using (Transaction tr = db.TransactionManager.StartTransaction()) using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } tr.Commit(); } ObjectId textLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, TextLayerName, Color.FromColorIndex(ColorMethod.ByAci, 1)); ObjectId lineLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, LineLayerName, Color.FromColorIndex(ColorMethod.ByAci, 3)); ObjectId blockId = GetOrCreateBlock(db, BlockName, textLayerId, lineLayerId, textStyleId); Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs; // Pick polyline PromptPointResult ptRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nKöşe noktası: "); if (PolylineJig.Jig(ptRes.Value, out Point3dCollection points)) { int xmin = int.MaxValue; int xmax = int.MinValue; int ymin = int.MaxValue; int ymax = int.MinValue; for (int i = 0; i < 4; i++) { Point3d pt = points[i]; xmin = Math.Min(xmin, (int)pt.X); xmax = Math.Max(xmax, (int)pt.X); ymin = Math.Min(ymin, (int)pt.Y); ymax = Math.Max(ymax, (int)pt.Y); } // Interval PromptIntegerOptions intOpts = new PromptIntegerOptions("\nAralık: "); intOpts.AllowNegative = false; intOpts.AllowZero = false; intOpts.AllowNone = false; intOpts.DefaultValue = Properties.Settings.Default.Command_COORDGRID_Interval; intOpts.UseDefaultValue = true; PromptIntegerResult intRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(intOpts); if (intRes.Status == PromptStatus.OK) { Interval = intRes.Value; } else { return; } // Round limits to multiples of the interval xmin = (int)Math.Floor((double)xmin / Interval) * Interval; xmax = (int)Math.Ceiling((double)xmax / Interval) * Interval; ymin = (int)Math.Floor((double)ymin / Interval) * Interval; ymax = (int)Math.Ceiling((double)ymax / Interval) * Interval; // Text height PromptDoubleOptions thOpts = new PromptDoubleOptions("\nYazı yüksekliği: "); thOpts.AllowNegative = false; thOpts.AllowZero = false; thOpts.AllowNone = false; thOpts.DefaultValue = Properties.Settings.Default.Command_COORDGRID_TextHeight; thOpts.UseDefaultValue = true; PromptDoubleResult thRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(thOpts); if (thRes.Status == PromptStatus.OK) { TextHeight = thRes.Value; } else { return; } // Save settings Properties.Settings.Default.Command_COORDGRID_TextHeight = TextHeight; Properties.Settings.Default.Command_COORDGRID_Interval = Interval; Properties.Settings.Default.Save(); // Print grid NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); nfi.NumberGroupSeparator = " "; nfi.NumberDecimalDigits = 0; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { BlockTableRecord blockDef = (BlockTableRecord)tr.GetObject(blockId, OpenMode.ForRead); for (int x = xmin; x <= xmax; x += Interval) { for (int y = ymin; y <= ymax; y += Interval) { Point3d v = new Point3d(x, y, 0); if (!PolylineContains(points, v)) { continue; } BlockReference blockRef = AcadUtility.AcadEntity.CreateBlockReference(db, blockId, v, TextHeight, 0); btr.AppendEntity(blockRef); tr.AddNewlyCreatedDBObject(blockRef, true); // Set attributes foreach (ObjectId id in blockDef) { AttributeDefinition attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition; if (attDef != null) { using (AttributeReference attRef = new AttributeReference()) { attRef.SetDatabaseDefaults(db); attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform); blockRef.AttributeCollection.AppendAttribute(attRef); tr.AddNewlyCreatedDBObject(attRef, true); attRef.TextString = attDef.Tag == "X" ? x.ToString("n", nfi) : y.ToString("n", nfi); attRef.AdjustAlignment(db); } } } } } tr.Commit(); } } }