public void TestPolylineJig() { var doc = AcadHelper.Doc; var ed = doc.Editor; var plJig = new PolylineJig(); var res = plJig.DrawPolyline(ed); }
public static bool Jig(Point3d p1, out Point3dCollection points) { PolylineJig jigger = new PolylineJig(CreatePolyline(), p1, p1, p1, p1); Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; bool canceled = false; PromptResult res; if (!canceled) { jigger.CurrentPoint = 2; res = doc.Editor.Drag(jigger); if (res.Status != PromptStatus.OK) { canceled = true; } } if (!canceled) { jigger.CurrentPoint = 3; res = doc.Editor.Drag(jigger); if (res.Status != PromptStatus.OK) { canceled = true; } } if (!canceled) { jigger.CurrentPoint = 4; res = doc.Editor.Drag(jigger); if (res.Status != PromptStatus.OK) { canceled = true; } } var ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; points = new Point3dCollection() { jigger.mp1.TransformBy(ucs2wcs), jigger.mp2.TransformBy(ucs2wcs), jigger.mp3.TransformBy(ucs2wcs), jigger.mp4.TransformBy(ucs2wcs) }; return(!canceled); }
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(); } } }