private void btn_Arc_Click(object sender, EventArgs e) { LoadValue(); var P1 = CAD.PickPoint(); var Arc = CAD.CreateArc(P1, D, R1, R2); }
private void btn_Rectangle_Click(object sender, EventArgs e) { LoadValue(); var P1 = CAD.PickPoint(); var Line = CAD.CreateRectangle(P1, W, H); }
private void btn_Line_Click(object sender, EventArgs e) { LoadValue(); var P1 = CAD.PickPoint(); var P2 = CAD.PickPoint(); var Line = CAD.CreateLine(P1, P2); }
private void CreateRectangle(Curve2d C1, List <Curve2d> Cs) { var C2 = Cs.First(); var sp1 = C1.StartPoint; var ep1 = C1.EndPoint; var Ps1 = new List <Point2d> { sp1, ep1 }; var sp2 = C2.StartPoint; var ep2 = C2.EndPoint; var Ps2 = new List <Point2d> { sp2, ep2 }; var Ps = from p1 in Ps1 from p2 in Ps2 let d = p1.GetDistanceTo(p2) orderby d descending select new List <Point2d> { p1, p2 }; if (Ps.Any()) { var Points = Ps.First(); var Vec1 = CAD.GetVector(C1); var Vec2 = CAD.GetVector(Points[0], Points[1]); if (Vec1.GetAngleTo(Vec2) > Math.PI / 2) { Vec1 = -Vec1; } double Ang = Math.Abs(Vec1.GetAngleTo(Vec2)); var P1 = CAD.ToPoint3D(Points[0]); var P2 = CAD.ToPoint3D(Points[1]); CAD.CreateRectangle(P1, P2, Vec1, Ang); } }
public void Create() { using (Transaction T = Doc.TransactionManager.StartTransaction()) { BlockTable BT = T.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Point3d SP = new Point3d(); Point3d EP = new Point3d(100, 0, 0); Line L = CAD.CreateLine(SP, EP); BTR.AppendEntity(L); T.AddNewlyCreatedDBObject(L, true); T.Commit(); } }
private void btn_zoom_Click(object sender, EventArgs e) { LoadValue(); CAD.ZoomExtents(new Autodesk.AutoCAD.Geometry.Point3d(), new Autodesk.AutoCAD.Geometry.Point3d(), Z); }
public void Play() { acDoc = Application.DocumentManager.MdiActiveDocument; acDb = acDoc.Database; acDL = acDoc.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, true); Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor; PromptSelectionResult acPSR = acDocEd.GetSelection(); // 선택한 객체를 받음 if (acPSR.Status == PromptStatus.OK) { var edgePtrs = new Curve2dCollection(); var edgeTypes = new IntegerCollection(); using (Transaction T = acDb.TransactionManager.StartTransaction()) { BlockTable BT = T.GetObject(acDb.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; SelectionSet acSSet = acPSR.Value; foreach (var objID in acSSet.GetObjectIds()) { var acEnt = T.GetObject(objID, OpenMode.ForWrite) as Entity; if (acEnt is Polyline) { Polyline acPL = acEnt as Polyline; GetEdgeInformation(acPL, ref edgePtrs, ref edgeTypes); } } } var acPolylines = from a in edgePtrs.Cast <Curve2d>() orderby a.StartPoint.GetDistanceTo(a.EndPoint) descending select a; //var usedCurve = new List<Curve2d>(); var usedCurve = new List <Point2d>(); acPolylines.Cast <Curve2d>().ToList().ForEach(c => { var CenterP = CAD.GetCenterPoint2d(c.StartPoint, c.EndPoint); var curves = from a in edgePtrs.Cast <Curve2d>().ToList() where a != c select a; // c와 평행한 선을 받음 var MatchedCurves = from a in curves let d = a.GetDistanceTo(c) where CAD.GetVector(a).GetNormal().IsEqualTo(-CAD.GetVector(c).GetNormal()) where d > Min && d < Max let cp1 = CAD.GetCenterPoint2d(c) let cp2 = CAD.GetCenterPoint2d(a) orderby cp1.GetDistanceTo(cp2) ascending select a; if (MatchedCurves.Any()) { //CAD.CreateLine(c.StartPoint, c.EndPoint); bool B = true; MatchedCurves.ToList().ForEach(c1 => { var cp1 = CAD.GetCenterPoint2d(c1); usedCurve.ForEach(cp2 => { if (cp1.IsEqualTo(cp2)) { B = false; } }); }); if (B) { CreateRectangle(c, MatchedCurves.ToList()); usedCurve.Add(CAD.GetCenterPoint2d(c)); } } }); } else { Application.ShowAlertDialog("Number of objects selected: 0"); } }