예제 #1
0
        public static ObjectId Create(LineSegment3d L, double H, ObjectId DimStyleId, ObjectId LayerId)
        {
            ObjectId Return = ObjectId.Null;

            #region T
            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;

                var V       = L.Direction;
                var cross_V = V.CrossProduct(Vector3d.ZAxis);

                var CP = CADUtil.GetCenterPoint3d(L);       // center point
                var DP = CADUtil.MoveP(CP, cross_V, H);     // dimension point

                var acDim = new AlignedDimension(L.StartPoint, L.EndPoint, DP, string.Empty, DimStyleId);

                acDim.DimensionStyle = DimStyleId;
                acDim.LayerId        = LayerId;

                BTR.AppendEntity(acDim);
                T.AddNewlyCreatedDBObject(acDim, true);
                Return = acDim.Id;

                T.Commit();
            }
            #endregion

            return(Return);
        }
예제 #2
0
        public void CreateKeyLine()
        {
            bool B = true;

            while (B)
            {
                //#region PRE
                //SelectionSet acSSet = SelectLines();

                //if (acSSet == null)
                //{
                //    B = false;
                //    return;
                //}
                //#endregion

                //#region 폴리라인 선택
                //var selectedPolyLines = new List<Polyline>();
                //var acPolylines = new List<Polyline>();

                //using (Transaction T = AC.DB.TransactionManager.StartTransaction())
                //{
                //    var Lines = from id in acSSet.GetObjectIds()
                //                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                //                where acEnt is Polyline
                //                let acLine = acEnt as Polyline
                //                select acLine;

                //    if (!Lines.Any())
                //        return;

                //    selectedPolyLines.AddRange(Lines.ToArray());
                //}
                //#endregion

                var Polylines   = select.Objects <Polyline>();
                var acPolylines = new List <Polyline>();

                #region 폴리라인 정리
                Polylines.ForEach(pl =>
                {
                    #region 폴리라인에서 커브 담기
                    var curves = new List <Curve3d>();

                    for (int i = 0; i < pl.NumberOfVertices; i++)
                    {
                        try
                        {
                            var l = pl.GetLineSegmentAt(i).Length;

                            if (l >= Min && l <= Max)
                            {
                                curves.Add(pl.GetLineSegmentAt(i));
                            }
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                    #endregion

                    #region 폴리라인 장축 중심을 읻는 선
                    if (curves.Count == 2)
                    {
                        var cv1 = curves[0];
                        var cv2 = curves[1];

                        var p1 = CADUtil.GetCenterPoint3d(cv1);
                        var p2 = CADUtil.GetCenterPoint3d(cv2);

                        var vec = CADUtil.GetVector(p1, p2);

                        var X = (vec * extend).X;
                        var Y = (vec * extend).Y;

                        var sp = CADUtil.MoveP(p1, -X, -Y, 0);
                        var ep = CADUtil.MoveP(p2, X, Y, 0);

                        var acPolyline = CADUtil.CreatePolyline(sp, ep);

                        acPolylines.Add(acPolyline);
                    }
                    #endregion
                });
                #endregion

                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    #region 검토 & 연속된 선 연결
                    // 제거할 선들
                    var deletePolylines = new List <Polyline>();

                    acPolylines.ForEach(pl1 =>
                    {
                        var contiPolylines = new List <Polyline>();

                        // 평행하고 같은 선상에 있는 선들
                        var paralPolylines = from pl2 in acPolylines
                                             where !deletePolylines.Contains(pl2)
                                             let line1                         = pl1.GetLineSegmentAt(0)
                                                                     let line2 = pl2.GetLineSegmentAt(0)
                                                                                 where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                 where IsAlmostEqual(line1, line2)
                                                                                 select pl2;

                        // 평행하고 같은 선상에 있는 선들 개수
                        int N = paralPolylines.Count();

                        var paralNearPolylines                                                             = from pl2 in paralPolylines
                                                                         let line1                         = pl1.GetLineSegmentAt(0)
                                                                                                 let line2 = pl2.GetLineSegmentAt(0)
                                                                                                             where CADUtil.getNearDistance(line1, line2) < distance
                                                                                                             select pl2;

                        if (paralNearPolylines.Any())
                        {
                            contiPolylines.AddRange(paralNearPolylines);

                            for (int j = 0; j < N; j++)
                            {
                                contiPolylines.ToList().ForEach(a =>
                                {
                                    var srtPolylines = from pl2 in acPolylines
                                                       where !contiPolylines.Contains(pl2)
                                                       let line1                         = a.GetLineSegmentAt(0)
                                                                               let line2 = pl2.GetLineSegmentAt(0)
                                                                                           where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                           where IsAlmostEqual(line1, line2)
                                                                                           where CADUtil.getNearDistance(line1, line2) < 2 * extend + distance
                                                                                           select pl2;

                                    if (srtPolylines.Any())
                                    {
                                        contiPolylines.AddRange(srtPolylines);
                                    }
                                });
                            }
                        }

                        if (contiPolylines.Any())
                        {
                            var Ps = CADUtil.getFurPoints(contiPolylines.ToList());

                            var acPolyline = CADUtil.CreatePolyline(Ps[0], Ps[1]);

                            deletePolylines.AddRange(contiPolylines);
                        }
                    });

                    #endregion

                    #region 제거
                    using (OpenCloseTransaction T = AC.DB.TransactionManager.StartOpenCloseTransaction())
                    {
                        deletePolylines.ForEach(a =>
                        {
                            var entity = T.GetObject(a.Id, OpenMode.ForWrite) as Entity;

                            if (!entity.IsErased)
                            {
                                entity.Erase(true);
                            }
                        });

                        T.Commit();
                    }
                    #endregion
                }
            }

            AC.Editor.WriteMessage("\n키라인 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
예제 #3
0
        public void CreateKeyLine2()
        {
            var selectedPolyLines = new List <Polyline>();
            var acPolylines       = new List <Polyline>();

            #region 폴리라인 선택
            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                try
                {
                    SelectionSet acSSet = SelectLines();

                    var Lines = from id in acSSet.GetObjectIds()
                                let acEnt = T.GetObject(id, OpenMode.ForWrite) as Entity
                                            where acEnt is Polyline
                                            let acLine = acEnt as Polyline
                                                         select acLine;

                    if (!Lines.Any())
                    {
                        return;
                    }

                    selectedPolyLines.AddRange(Lines.ToArray());
                }
                catch (System.Exception ex)
                {
                    AC.Editor.WriteMessage(Convert.ToString(ex));
                }
            }
            #endregion

            using (DocumentLock DL = AC.Doc.LockDocument())
            {
                #region 입력
                selectedPolyLines.ForEach(pl =>
                {
                    #region 폴리라인에서 커브 담기
                    var curves = new List <Curve3d>();

                    for (int i = 0; i < pl.NumberOfVertices; i++)
                    {
                        try
                        {
                            var l = pl.GetLineSegmentAt(i).Length;

                            if (l >= Min && l <= Max)
                            {
                                curves.Add(pl.GetLineSegmentAt(i));
                            }
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                    #endregion

                    if (curves.Count == 2)
                    {
                        var cv1 = curves[0];
                        var cv2 = curves[1];

                        var p1 = CADUtil.GetCenterPoint3d(cv1);
                        var p2 = CADUtil.GetCenterPoint3d(cv2);

                        var vec = CADUtil.GetVector(p1, p2);

                        var X = (vec * extend).X;
                        var Y = (vec * extend).Y;

                        var sp = CADUtil.MoveP(p1, -X, -Y, 0);
                        var ep = CADUtil.MoveP(p2, X, Y, 0);

                        var acPolyline = CADUtil.CreatePolyline(sp, ep);

                        acPolylines.Add(acPolyline);
                    }
                });
                #endregion

                #region 검토 & 연속된 선 연결
                // 제거할 선들
                var deletePolylines = new List <Polyline>();

                acPolylines.ForEach(pl1 =>
                {
                    var direction = pl1.GetLineSegmentAt(0).Direction;
                    direction     = direction.X < 0 ? -direction : direction;
                    var Ang       = Math.Round(Math.Atan2(direction.Y, direction.X) / Math.PI * 180) % 180;
                    var A         = Math.Abs(Ang) == 90 || Ang == 0 ? 0 : Math.Tan(Ang / 180 * Math.PI);

                    //MessageBox.Show(Ang + "\n" + A.ToString());

                    // 같은 2차 그래프에 존재하는 선들
                    var parallelPolylines = from pl2 in acPolylines
                                            where !deletePolylines.Contains(pl2)
                                            let line1                         = pl1.GetLineSegmentAt(0)
                                                                    let line2 = pl2.GetLineSegmentAt(0)
                                                                                where line1.IsParallelTo(line2, new Tolerance(1, 1))
                                                                                //let b1 = line1.StartPoint.Y - A * line1.StartPoint.X
                                                                                //let b2 = line2.StartPoint.Y - A * line2.StartPoint.X
                                                                                //let sp1 = line1.StartPoint
                                                                                //let sp2 = line2.StartPoint
                                                                                //where (Ang == 0 && IsAlmostEqual(sp1.Y, sp2.Y)) ||
                                                                                //      (Math.Abs(Ang) == 90 && IsAlmostEqual(sp1.X, sp2.X)) ||
                                                                                //      (Ang != 0 && Math.Abs(Ang) != 90 && IsAlmostEqual(line1,line2))
                                                                                where IsAlmostEqual(line1, line2)
                                                                                select pl2;

                    if (parallelPolylines.Any())
                    {
                        var Ps = CADUtil.getFurPoints(parallelPolylines.ToList());

                        var acPolyline = CADUtil.CreatePolyline(Ps[0], Ps[1]);

                        deletePolylines.AddRange(parallelPolylines);
                    }
                });

                #endregion

                #region 제거
                using (OpenCloseTransaction T = AC.DB.TransactionManager.StartOpenCloseTransaction())
                {
                    deletePolylines.ForEach(a =>
                    {
                        var entity = T.GetObject(a.Id, OpenMode.ForWrite) as Entity;

                        if (!entity.IsErased)
                        {
                            entity.Erase(true);
                        }
                    });

                    T.Commit();
                }
                #endregion
            }

            AC.Editor.WriteMessage("\n키라인 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }
예제 #4
0
        public void CreateBeamPolyLine()
        {
            bool B = true;

            while (B)
            {
                var Lines = select.Objects <Line>();

                if (Lines == null)
                {
                    B = false;
                    return;
                }

                var usedLines = new List <Point3d>();

                using (DocumentLock DL = AC.Doc.LockDocument())
                {
                    Lines.ForEach(acLine =>
                    {
                        try
                        {
                            var lines = from l in Lines.ToList()
                                        where acLine != l
                                        select l;

                            if (lines.Any())
                            {
                                #region 규칙 적용
                                var matchedLines                                              = from a in lines
                                                                     let A1                   = Math.Abs(Math.Round(CADUtil.GetVector(acLine).Angle / Math.PI * 180)) % 180
                                                                                       let A2 = Math.Abs(Math.Round(CADUtil.GetVector(a).Angle / Math.PI * 180)) % 180
                                                                                                where Math.Abs(A1 - A2) < 5
                                                                                                //where CAD.GetVector(a).IsParallelTo(CAD.GetVector(acLine))
                                                                                                //|| CAD.GetVector(a).IsParallelTo(-CAD.GetVector(acLine))
                                                                                                let curve                 = acLine as Curve
                                                                                                                    let d = Math.Round(acLine.GetGeCurve().GetDistanceTo(CADUtil.GetCenterPoint3d(a)), 0)
                                                                                                                            where d >= Min && d <= Max
                                                                                                                            select a;

                                //MessageBox.Show(matchedLines.Count().ToString());
                                #endregion

                                #region 생성
                                if (matchedLines.Any())
                                {
                                    bool B1 = true;

                                    #region 중복 판별
                                    matchedLines.ToList().ForEach(l1 =>
                                    {
                                        var cp1 = CADUtil.GetCenterPoint3d(l1);

                                        usedLines.ForEach(cp2 =>
                                        {
                                            if (cp1.IsEqualTo(cp2))
                                            {
                                                B1 = false;
                                            }
                                        });
                                    });
                                    #endregion

                                    if (B1)
                                    {
                                        CreateRectangle(acLine, matchedLines.ToList());

                                        usedLines.Add(CADUtil.GetCenterPoint3d(acLine));
                                    }
                                }
                                #endregion
                            }
                        }
                        catch { }
                    });
                }
            }

            AC.Editor.WriteMessage("\n보 입력완료 ");
            AC.Editor.PostCommandPrompt();
        }