private void CreateRectangle(Line L1, List <Line> Ls) { var C2 = Ls.First(); var sp1 = L1.StartPoint; var ep1 = L1.EndPoint; var Ps1 = new List <Point3d> { sp1, ep1 }; var sp2 = C2.StartPoint; var ep2 = C2.EndPoint; var Ps2 = new List <Point3d> { sp2, ep2 }; var Ps = from p1 in Ps1 from p2 in Ps2 let d = p1.DistanceTo(p2) orderby d descending select new List <Point3d> { p1, p2 }; if (Ps.Any()) { var Points = Ps.First(); var P1 = new Point3d(Points[0].X, Points[0].Y, 0); var P2 = new Point3d(Points[1].X, Points[1].Y, 0); var Vec1 = CADUtil.GetVector(L1); var Vec2 = CADUtil.GetVector(P1, P2); if (Vec1.GetAngleTo(Vec2) > Math.PI / 2) { Vec1 = -Vec1; } double Ang = Math.Abs(Vec1.GetAngleTo(Vec2)); var acPolyline = CADUtil.CreateRectangle(P1, P2, Vec1, Ang); //MessageBox.Show(P1.ToString() + "\n" + P2.ToString() + "\n" + Vec1.ToString() + "\n" + Ang.ToString()); //MessageBox.Show(acPolyline.StartPoint.ToString() + "\n" + acPolyline.EndPoint.ToString()); } }
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 = CADUtil.GetVector(C1); var Vec2 = CADUtil.GetVector(Points[0], Points[1]); if (Vec1.GetAngleTo(Vec2) > Math.PI / 2) { Vec1 = -Vec1; } double Ang = Math.Abs(Vec1.GetAngleTo(Vec2)); var P1 = CADUtil.ToPoint3D(Points[0]); var P2 = CADUtil.ToPoint3D(Points[1]); CADUtil.CreateRectangle(P1, P2, Vec1, Ang); } }
public void CreateColumnPolyLine() { bool B = true; while (B) { var Polylines = select.Objects <Polyline>(); if (Polylines == null) { B = false; return; } #region 생성 using (DocumentLock DL = AC.Doc.LockDocument()) { Polylines.ForEach(acPolyline => { var Points = new List <Point3d>(); for (int i = 0; i < acPolyline.NumberOfVertices; i++) { Points.Add(acPolyline.GetPoint3dAt(i)); } Points.Add(acPolyline.GetPoint3dAt(0)); var acNewPolyLine = CADUtil.CreateRectangle(Points); }); } #endregion } AC.Editor.WriteMessage("\n기둥 입력완료 "); AC.Editor.PostCommandPrompt(); }
public List <Polyline> Create_Boundaries() { var Return = new List <Polyline>(); using (DocumentLock DL = AC.Doc.LockDocument()) { #region 택 var acSSet = Utils.Select.MultiObjs(); var acEnts = Utils.Get.Entity(acSSet, typeof(Polyline)); #endregion #region 폴리라인 연장시켜 하나의 덩어리로 만들기 var acLines = new List <LineSegment3d>(); // 선택된 Polyline의 모든 선분을 담음(최대, 최소 좌표를 얻기위해) var acTempLines = new List <Line>(); // 작업 완료 후 지울 보조선 acEnts.Where(x => x is Polyline).ToList().ForEach(acEnt => { var acEntsCopy = acEnts.Where(x => x != acEnt); var acPoly = acEnt as Polyline; for (int i = 0; i < acPoly.NumberOfVertices; i++) { try { var acLine = acPoly.GetLineSegmentAt(i); if (!acLines.Contains(acLine)) { acLines.Add(acLine); } var Di = acLine.Direction; var sp = acLine.StartPoint; var ep = acLine.EndPoint; var moved_sp = Utils.PointUtil.Move(acLine.StartPoint, -Di); var moved_ep = Utils.PointUtil.Move(acLine.StartPoint, Di); var LS1 = new LineSegment3d(sp, moved_sp); // Line에서 연장된 선분 var LS2 = new LineSegment3d(ep, moved_ep); // Line에서 연장된 선분 var IP1 = CADUtil.IntersectedLine(acEntsCopy.ToList(), LS1, sp, 500); var IP2 = CADUtil.IntersectedLine(acEntsCopy.ToList(), LS2, ep, 500); double d = 0; if (IP1 != new Point3d()) { var SP = Utils.PointUtil.Move(sp, Di * d); var EP = Utils.PointUtil.Move(IP1, -Di * d); var L1 = CADUtil.CreateLine(SP, EP, ColorIndex.DarkGray); acTempLines.Add(L1); } if (IP2 != new Point3d()) { var SP = Utils.PointUtil.Move(ep, -Di * d); var EP = Utils.PointUtil.Move(IP2, Di * d); var L2 = CADUtil.CreateLine(SP, EP, ColorIndex.DarkGray); acTempLines.Add(L2); } } catch { } } }); #endregion #region 폴리라인을 감싸는 Box객체를 생성 var P_X = (from a in acLines let p = a.StartPoint orderby p.X select p.X); var P_Y = (from a in acLines let p = a.StartPoint orderby p.Y select p.Y); var Min_P = new Point3d(P_X.First() - 1000, P_Y.First() - 1000, 0); var Max_P = new Point3d(P_X.Last() + 1000, P_Y.Last() + 1000, 0); var Box = CADUtil.CreateRectangle(Min_P, Max_P); #endregion #region 밀폐된 공간에서 Boundary 추적 var P1 = Utils.PointUtil.Move(Min_P, 500, 500); var objColl = AC.Editor.TraceBoundary(P1, true); var acObjs = from a in objColl.Cast <Entity>().ToList() select a; #endregion #region Boundary 생성 if (acObjs.Any()) { using (Transaction T = AC.DB.TransactionManager.StartTransaction()) { var BT = T.GetObject(AC.DB.BlockTableId, OpenMode.ForRead) as BlockTable; var BTR = T.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; acObjs.ToList().ForEach(a => { var acPoly = a as Polyline; if (Math.Abs(acPoly.Area - Box.Area) > 1) { BTR.AppendEntity(acPoly); T.AddNewlyCreatedDBObject(acPoly, true); Return.Add(acPoly); } }); T.Commit(); } } #endregion #region 제거 CADUtil.Erase(Box.Id); acTempLines.ForEach(a => CADUtil.Erase(a.Id)); #endregion } return(Return); }