コード例 #1
0
        /// <summary>
        /// 判斷兩線段是否同向
        /// </summary>
        /// <param name="line1"></param>
        /// <param name="line2"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        private bool IsSameDirection(LINE line1, LINE line2, ref double distance)
        {
            distance = -1;
            XYZ  Dir_1           = line1.GetDirection();
            XYZ  Dir_2           = line2.GetDirection();
            bool isSameDirection = IsSamePoint(Dir_1, Dir_2);

            if (!isSameDirection)
            {
                return(false);
            }

            /// 若端點重疊則回傳false
            if (IsSamePoint(line1.GetStartPoint(), line2.GetStartPoint()) ||
                IsSamePoint(line1.GetEndPoint(), line2.GetEndPoint()) ||
                IsSamePoint(line1.GetStartPoint(), line2.GetEndPoint()) ||
                IsSamePoint(line1.GetEndPoint(), line2.GetStartPoint()))
            {
                return(false);
            }

            /// 判斷是否在同一直線上 if == 0
            distance = Math.Round(line1.GetDistanceFromPoint(line2.GetStartPoint()), IG_POINT);

            return(true);
        }
コード例 #2
0
        private List <XYZ> GetClosedColumn(List <XYZ> colCenterPoints, LINE beam)
        {
            List <double> DiffDist1 = new List <double>();
            List <double> DiffDist2 = new List <double>();

            foreach (XYZ item in colCenterPoints)
            {
                XYZ    StartPoint = beam.GetStartPoint();
                XYZ    EndPoint   = beam.GetStartPoint();
                double dist1      = Math.Sqrt((item.X - StartPoint.X) * (item.X - StartPoint.X) +
                                              (item.Y - StartPoint.Y) * (item.Y - StartPoint.Y));
                double dist2 = Math.Sqrt((item.X - EndPoint.X) * (item.X - EndPoint.X) +
                                         (item.Y - EndPoint.Y) * (item.Y - EndPoint.Y));
                DiffDist1.Add(dist1);
                DiffDist2.Add(dist2);
            }

            int p1 = DiffDist1.IndexOf(DiffDist1.Min());
            int p2 = DiffDist2.IndexOf(DiffDist2.Min());

            return(new List <XYZ>()
            {
                colCenterPoints[p1], colCenterPoints[p2]
            });
        }
コード例 #3
0
ファイル: TT.cs プロジェクト: karthi1015/RevitAPIPractice
 private bool IsConnected(LINE line1, LINE line2)
 {
     if (IsSamePoint(line1.GetStartPoint(), line2.GetStartPoint()) ||
         IsSamePoint(line1.GetEndPoint(), line2.GetEndPoint()) ||
         IsSamePoint(line1.GetStartPoint(), line2.GetEndPoint()) ||
         IsSamePoint(line1.GetEndPoint(), line2.GetStartPoint()))
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
        private bool IsCloseEndsPoint(LINE line, XYZ crossPoint, double SHIFT)
        {
            double Len1 = Math.Sqrt((line.GetStartPoint().X - crossPoint.X) * (line.GetStartPoint().X - crossPoint.X) +
                                    (line.GetStartPoint().Y - crossPoint.Y) * (line.GetStartPoint().Y - crossPoint.Y));
            double Len2 = Math.Sqrt((line.GetEndPoint().X - crossPoint.X) * (line.GetEndPoint().X - crossPoint.X) +
                                    (line.GetEndPoint().Y - crossPoint.Y) * (line.GetEndPoint().Y - crossPoint.Y));

            if (Len1 < SHIFT || Len2 < SHIFT)
            {
                return(true);
            }

            return(false);
        }
コード例 #5
0
        private XYZ GetNewEndedPoint(XYZ ColTarget_, XYZ EndPoint, LINE Beam)
        {
            XYZ    ColTarget    = new XYZ(ColTarget_.X, ColTarget_.Y, Beam.GetStartPoint().Z);
            XYZ    startPoint   = Beam.GetStartPoint();
            XYZ    oriDir       = Beam.GetDirection();
            XYZ    newDir       = new XYZ(oriDir.Y, -oriDir.X, oriDir.Z);
            LINE   VerticalLINE = new LINE(ColTarget, newDir, 1);
            XYZ    newPoint     = VerticalLINE.GetCrossPoint(Beam);
            double dist         = Math.Sqrt((newPoint.X - EndPoint.X) * (newPoint.X - EndPoint.X) +
                                            (newPoint.Y - EndPoint.Y) * (newPoint.Y - EndPoint.Y));

            if (dist > Beam.GetLength())
            {
                return(EndPoint);
            }
            return(VerticalLINE.GetCrossPoint(Beam));
        }
コード例 #6
0
ファイル: LINE.cs プロジェクト: karthi1015/RevitAPIPractice
        public XYZ GetCrossPoint(LINE line2)
        {
            if (this.IsSameDirection(line2.GetDirection(), true))
            {
                LINE tmpLine = new LINE(this.GetEndPoint(), line2.GetStartPoint());
                if (this.IsSameDirection(tmpLine.Direction, true))
                {
                    if (this.IsSameDirection(line2.Direction, true))
                    {
                        return((this.GetEndPoint() + line2.GetStartPoint()) / 2);
                    }
                    else
                    {
                        return((this.GetStartPoint() + line2.GetStartPoint()) / 2);
                    }
                }
                else
                {
                    return(this.GetEndPoint());
                }
            }

            MATRIX m1 = new MATRIX(new double[, ] {
                { this.Direction.X, -line2.Direction.X },
                { this.Direction.Y, -line2.Direction.Y }
            });
            MATRIX m2 = new MATRIX(new double[, ] {
                { line2.OriPoint.X - this.OriPoint.X }, { line2.OriPoint.Y - this.OriPoint.Y }
            });

            MATRIX m3  = m1.InverseMatrix();
            MATRIX res = m3.CrossMatrix(m2);

            double[,] tt = res.Matrix;
            double newX = this.OriPoint.X + this.Direction.X * tt[0, 0];
            double newY = this.OriPoint.Y + this.Direction.Y * tt[0, 0];

            return(new XYZ(newX, newY, this.OriPoint.Z));
        }
コード例 #7
0
        /// <summary>
        /// Get Column centerpoint using to Create column
        /// </summary>
        /// <param name="Collect"></param>
        /// <param name="H_Direction_Lines"></param>
        /// <param name="V_Direction_Lines"></param>
        /// <param name="H_Beams"></param>
        /// <param name="V_Beams"></param>
        public static List <LINE> GetColumnDrawCenterPoints(List <List <LINE> > Collect)
        {
            List <LINE> RESULT = new List <LINE>();

            foreach (List <LINE> Lines in Collect)
            {
                LINE LINE1 = Lines[0];
                LINE LINE2 = Lines[1];
                RESULT.Add(new LINE(LINE1.GetStartPoint(), LINE2.GetEndPoint()));
            }


            return(RESULT);
        }
コード例 #8
0
        /// <summary>
        /// Create Beam
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="baseLevel"></param>
        /// <param name="points"></param>
        public void CreateBeam(FamilySymbol Type, Level baseLevel, LINE points)
        {
            if (!Type.IsActive)
            {
                using (Transaction trans = new Transaction(revitDoc))
                {
                    trans.Start("Activate Family instance");
                    Type.Activate();
                    trans.Commit();
                }
            }

            using (Transaction trans = new Transaction(revitDoc))
            {
                trans.Start("Create Beam");
                FamilyInstance familyInstance = null;
                XYZ            p1             = new XYZ(points.GetStartPoint().X, points.GetStartPoint().Y, baseLevel.Elevation);
                XYZ            p2             = new XYZ(points.GetEndPoint().X, points.GetEndPoint().Y, baseLevel.Elevation);
                familyInstance = revitDoc.Create.NewFamilyInstance(Line.CreateBound(p1, p2), Type, baseLevel, StructuralType.Beam);


                trans.Commit();
            }
        }
コード例 #9
0
        /// <summary>
        /// 取得所有的梁
        /// </summary>
        /// <returns></returns>
        private List <LINE> GetAllBeams()
        {
            FilteredElementCollector collector = new FilteredElementCollector(revitDoc);

            collector.OfCategory(BuiltInCategory.OST_StructuralFraming);
            collector.OfClass(typeof(FamilyInstance));
            IList <Element> beams = collector.ToElements();
            List <LINE>     Beams = new List <LINE>();

            foreach (Element beam in beams)
            {
                try
                {
                    LocationCurve Locurve = beam.Location as LocationCurve;
                    Line          line    = Locurve.Curve as Line;
                    LINE          LINE    = new LINE(line.Origin, new XYZ(line.Origin.X + line.Length * line.Direction.X,
                                                                          line.Origin.Y + line.Length * line.Direction.Y,
                                                                          line.Origin.Z + line.Length * line.Direction.Z));


                    ElementType type      = revitDoc.GetElement(beam.GetTypeId()) as ElementType;
                    Parameter   mLevel    = beam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
                    string      levelName = mLevel.AsValueString();
                    LINE.Name      = beam.Name;
                    LINE.LevelName = levelName;

                    //to get width of section
                    Parameter b = type.LookupParameter("b");
                    LINE.Width = b.AsDouble();

                    ////to get height of section
                    //Parameter h = type.LookupParameter("h");
                    //double height = h.AsDouble();

                    if (Math.Round(LINE.GetStartPoint().Z, 3) == Math.Round(LINE.GetEndPoint().Z, 3))
                    {
                        if (LINE.GetDirection().X == 1 || LINE.GetDirection().Y == 1 || LINE.GetDirection().X == -1 || LINE.GetDirection().Y == -1)
                        {
                            Beams.Add(LINE);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            return(Beams);
        }
コード例 #10
0
 /// <summary>
 /// 建立梁
 /// </summary>
 /// <param name="Type"></param>
 /// <param name="baseLevel"></param>
 /// <param name="points"></param>
 public void CreateBeam(FamilySymbol Type, Level baseLevel, List <BEAM> points_, Document revitDoc)
 {
     using (Transaction trans = new Transaction(revitDoc))
     {
         trans.Start("Create Beam");
         foreach (BEAM item in points_)
         {
             LINE           points         = item.GetEdgeLine(3);
             FamilyInstance familyInstance = null;
             XYZ            p1             = new XYZ(points.GetStartPoint().X, points.GetStartPoint().Y, baseLevel.Elevation);
             XYZ            p2             = new XYZ(points.GetEndPoint().X, points.GetEndPoint().Y, baseLevel.Elevation);
             familyInstance = revitDoc.Create.NewFamilyInstance(Line.CreateBound(p1, p2), Type, baseLevel, StructuralType.Beam);
         }
         trans.Commit();
     }
 }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="NewBeamGroup"></param>
        /// <returns></returns>
        private List <List <LINE> > ConnectedEdgeFromMiddleColumns(List <List <LINE> > NewBeamGroup)
        {
            List <List <LINE> > newFloorGroup = new List <List <LINE> >();

            foreach (List <LINE> Beams in NewBeamGroup)
            {
                //SaveTmp(Beams);
                Dictionary <int, LINE> tmpAddLines = new Dictionary <int, LINE>();
                for (int i = 0; i < Beams.Count; i++)
                {
                    LINE L1 = Beams[i];
                    LINE L2 = i + 1 == Beams.Count ? Beams[0] : Beams[i + 1];
                    if (L1.IsSameDirection(L2.GetDirection(), true) && !L1.IsPointInLine(L2.GetStartPoint()))
                    {
                        tmpAddLines[i] = new LINE(L1.GetEndPoint(), L2.GetStartPoint());
                    }
                }

                foreach (int ii in tmpAddLines.Keys)
                {
                    Beams.Add(tmpAddLines[ii]);
                }
                SaveTmp(Beams);
                int         kk       = 0;
                List <LINE> newBeams = new List <LINE>();
                int[]       flag     = new int[Beams.Count];
                flag[kk] = -1;
                newBeams.Add(Beams[0]);
                while (kk < Beams.Count)
                {
                    if (flag[kk] != -1 && newBeams[newBeams.Count - 1].IsPointInLine(Beams[kk].GetStartPoint()))
                    {
                        flag[kk] = -1;
                        newBeams.Add(Beams[kk]);
                        kk = 0;
                    }
                    kk = kk + 1;
                }

                newFloorGroup.Add(newBeams);
                //SaveTmp(newBeams);
            }

            return(newFloorGroup);
        }
コード例 #12
0
 /// <summary>
 /// Create Column
 /// </summary>
 /// <param name="Type"></param>
 /// <param name="baseLevel"></param>
 /// <param name="topLevel"></param>
 /// <param name="points"></param>
 public void CreateColumn(FamilySymbol Type, Level baseLevel, Level topLevel, LINE points)
 {
     if (!Type.IsActive)
     {
         using (Transaction trans = new Transaction(revitDoc))
         {
             trans.Start("Activate Family instance");
             Type.Activate();
             trans.Commit();
         }
     }
     using (Transaction trans = new Transaction(revitDoc))
     {
         trans.Start("Create Column");
         FamilyInstance familyInstance = null;
         XYZ            point          = new XYZ((points.GetStartPoint().X + points.GetEndPoint().X) / 2, (points.GetStartPoint().Y + points.GetEndPoint().Y) / 2, 0);
         XYZ            botPoint       = new XYZ(point.X, point.Y, baseLevel.Elevation);
         XYZ            topPoint       = new XYZ(point.X, point.Y, topLevel.Elevation);
         familyInstance = revitDoc.Create.NewFamilyInstance(Line.CreateBound(botPoint, topPoint), Type, baseLevel, StructuralType.Column);
         trans.Commit();
     }
 }
コード例 #13
0
        private List <LINE> TakeOffColumnEdge(Dictionary <string, List <LINE> > columns, List <LINE> floor)
        {
            foreach (KeyValuePair <string, List <LINE> > column in columns)
            {
                List <LINE> newFloor = new List <LINE>();
                Dictionary <int, List <LINE> > tmpData = new Dictionary <int, List <LINE> >();
                for (int ii = 0; ii < column.Value.Count; ii++)
                {
                    LINE columnEdge = column.Value[ii];
                    for (int jj = 0; jj < floor.Count; jj++)
                    {
                        LINE floorEdge = floor[jj];
                        if (Math.Round(floorEdge.GetSlope(), 3) == Math.Round(columnEdge.GetSlope(), 3))
                        {
                            continue;
                        }
                        if (Math.Abs(Math.Round(floorEdge.GetDirection().X, 3)) == Math.Abs(Math.Round(columnEdge.GetDirection().X, 3)) &&
                            Math.Abs(Math.Round(floorEdge.GetDirection().Y, 3)) == Math.Abs(Math.Round(columnEdge.GetDirection().Y, 3)))
                        {
                            continue;
                        }

                        XYZ crossPoint = floorEdge.GetCrossPoint(columnEdge);


                        try
                        {
                            if (floorEdge.IsPointInLine(crossPoint) && columnEdge.IsPointInLine(crossPoint))
                            {
                                XYZ innerPoint = IsInner(columnEdge.GetStartPoint(), floor) ?
                                                 columnEdge.GetStartPoint() : columnEdge.GetEndPoint();

                                double      dis1    = (crossPoint - floorEdge.GetStartPoint()).GetLength();
                                double      dis2    = (crossPoint - floorEdge.GetEndPoint()).GetLength();
                                LINE        newLine = null;
                                List <LINE> newList = new List <LINE>();
                                if (dis1 > dis2)
                                {
                                    floorEdge.ResetParameters(crossPoint, "EndPoint");
                                    newLine = new LINE(crossPoint, innerPoint);
                                    newList.Add(floorEdge);
                                    if (dis2 != 0)
                                    {
                                        newList.Add(newLine);
                                    }
                                }
                                else
                                {
                                    newLine = new LINE(innerPoint, crossPoint);
                                    floorEdge.ResetParameters(crossPoint, "StartPoint");
                                    if (dis1 != 0)
                                    {
                                        newList.Add(newLine);
                                    }
                                    newList.Add(floorEdge);
                                }
                                tmpData[jj] = newList;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }


                for (int kk = 0; kk < floor.Count; kk++)
                {
                    if (tmpData.ContainsKey(kk))
                    {
                        foreach (LINE item in tmpData[kk])
                        {
                            newFloor.Add(item);
                        }
                    }
                    else
                    {
                        newFloor.Add(floor[kk]);
                    }
                }
                floor = new List <LINE>();
                floor = newFloor;
            }

            return(floor);
        }
コード例 #14
0
        /// <summary>
        /// 取得所有梁並將轉換至各樓板邊緣線
        /// </summary>
        /// <param name="BEAMS"></param>
        /// <returns></returns>
        private List <List <LINE> > GetBeamGroup(List <LINE> BEAMS)
        {
            double SHIFTDIST = 2000 / 304.8;

            int number = 0;

            int[] count = new int[BEAMS.Count];
            Dictionary <string, List <int> >  pickNumbers = new Dictionary <string, List <int> >();
            Dictionary <string, List <LINE> > DictRes     = new Dictionary <string, List <LINE> >();

            for (int i = 0; i < BEAMS.Count; i++)
            {
                List <LINE> ResTmp         = new List <LINE>();
                List <int>  tmpcheckPicked = new List <int>()
                {
                };
                for (int j = 0; j < BEAMS.Count; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    if (CMPPoints(BEAMS[i].GetEndPoint(), BEAMS[j].GetStartPoint(), SHIFTDIST))
                    {
                        ResTmp.Add(BEAMS[j]);
                        tmpcheckPicked.Add(j);
                    }
                    else if (CMPPoints(BEAMS[i].GetEndPoint(), BEAMS[j].GetEndPoint(), SHIFTDIST))
                    {
                        ResTmp.Add(new LINE(BEAMS[j].GetEndPoint(),
                                            BEAMS[j].GetStartPoint(),
                                            BEAMS[j].Name,
                                            BEAMS[j].LevelName,
                                            BEAMS[j].Width));
                        tmpcheckPicked.Add(j);
                    }
                }

                List <LINE> Res = null;
                for (int pp = 0; pp < ResTmp.Count; pp++)
                {
                    bool open = true;
                    Res = new List <LINE> {
                        BEAMS[i], ResTmp[pp]
                    };
                    List <int> checkPicked = new List <int>()
                    {
                        i, tmpcheckPicked[pp]
                    };

                    while (open)
                    {
                        int         j      = 0;
                        List <LINE> tmpRes = new List <LINE>();
                        tmpRes = Res.ToList();
                        List <int> tmpCheckPicked = new List <int>();
                        while (j < BEAMS.Count)
                        {
                            if (!checkPicked.Contains(j))
                            {
                                if (CMPPoints(Res[Res.Count - 1].GetEndPoint(), BEAMS[j].GetStartPoint(), SHIFTDIST))
                                {
                                    tmpRes.Add(BEAMS[j]);
                                    tmpCheckPicked.Add(j);
                                }
                                else if (CMPPoints(Res[Res.Count - 1].GetEndPoint(), BEAMS[j].GetEndPoint(), SHIFTDIST))
                                {
                                    tmpRes.Add(new LINE(BEAMS[j].GetEndPoint(),
                                                        BEAMS[j].GetStartPoint(),
                                                        BEAMS[j].Name,
                                                        BEAMS[j].LevelName,
                                                        BEAMS[j].Width));
                                    tmpCheckPicked.Add(j);
                                }
                            }
                            j++;
                        }

                        if (tmpRes.Count != Res.Count)
                        {
                            LINE          tmp  = tmpRes[0];
                            List <double> diff = new List <double>();
                            for (int ii = Res.Count; ii < tmpRes.Count; ii++)
                            {
                                if (!IsSamePoint(tmp.GetStartPoint(), tmpRes[ii].GetEndPoint()))
                                {
                                    diff.Add(new LINE(tmp.GetStartPoint(), tmpRes[ii].GetEndPoint()).GetLength());
                                }
                                else
                                {
                                    diff.Add(0);
                                }
                            }
                            int po = diff.FindIndex(item => item.Equals(diff.Min()));
                            checkPicked.Add(tmpCheckPicked[po]);
                            Res.Add(tmpRes[Res.Count + po]);
                            tmpCheckPicked.Clear();
                            if (diff.Min() < SHIFTDIST)
                            {
                                open = false;
                            }
                            else if (CMPPoints(Res[0].GetEndPoint(), Res[Res.Count - 1].GetEndPoint(), SHIFTDIST))
                            {
                                open = false;
                                SaveTmp(Res);
                                Res.RemoveAt(0);
                                checkPicked.RemoveAt(0);
                            }
                        }
                        else
                        {
                            open = false;
                        }
                    }

                    pickNumbers[number.ToString()] = checkPicked;
                    DictRes[number.ToString()]     = Res;
                    number++;
                }
            }


            ////// Filter Groups
            List <int>    sumOf = new List <int>();
            List <string> keys  = pickNumbers.Keys.ToList();

            foreach (KeyValuePair <string, List <int> > item in pickNumbers)
            {
                sumOf.Add(item.Value.Sum());
            }

            int[] flag = new int[sumOf.Count];
            for (int ii = 0; ii < sumOf.Count; ii++)
            {
                if (flag[ii] == -1)
                {
                    continue;
                }
                for (int j = 0; j < sumOf.Count; j++)
                {
                    List <LINE> tmpBeams = DictRes[keys[j]];
                    double      Len      = IsSamePoint(tmpBeams[0].GetStartPoint(), tmpBeams[tmpBeams.Count - 1].GetEndPoint()) ?
                                           0 : (new LINE(tmpBeams[0].GetStartPoint(), tmpBeams[tmpBeams.Count - 1].GetEndPoint())).GetLength();

                    if (ii != j && sumOf[ii] == sumOf[j])
                    {
                        flag[j] = -1;
                    }
                    else if (Len > SHIFTDIST)
                    {
                        flag[j] = -1;
                    }
                }
            }
            List <int> Flag = flag.ToList();

            int[] lastPo = FindAllIndexof(Flag, 0);

            Dictionary <string, List <LINE> > DictResult = new Dictionary <string, List <LINE> >();
            List <List <LINE> >           RESULT         = new List <List <LINE> >();
            Dictionary <int, List <int> > poo            = new Dictionary <int, List <int> >();

            foreach (int pp in lastPo)
            {
                DictResult[keys[pp]] = DictRes[keys[pp]];
                RESULT.Add(DictRes[keys[pp]]);
                poo[pp] = pickNumbers[pp.ToString()];
            }
            return(RESULT);
        }
コード例 #15
0
 public static double Get_Length(LINE Line)
 {
     return(Math.Sqrt(
                (Line.GetStartPoint().X - Line.GetEndPoint().X) * (Line.GetStartPoint().X - Line.GetEndPoint().X) +
                (Line.GetStartPoint().Y - Line.GetEndPoint().Y) * (Line.GetStartPoint().Y - Line.GetEndPoint().Y)));
 }
コード例 #16
0
 public static bool Is_Vertical(LINE line)
 {
     return(line.GetStartPoint().X == line.GetEndPoint().X ? true : false);
 }
コード例 #17
0
        /// <summary>
        /// 梁群組處理
        /// </summary>
        /// <param name="LINES"></param>
        /// <returns></returns>
        private List <BEAM> BeamCenterLineProcessing(List <LINE> LINES)
        {
            List <BEAM> Beams = new List <BEAM>();
            List <int>  flag  = new List <int>();

            for (int i = 0; i < LINES.Count; i++)
            {
                if (flag.Contains(i))
                {
                    continue;
                }

                List <int> tmpFlag = new List <int>()
                {
                };
                List <LINE>   tmpLine     = new List <LINE>();
                List <double> tmpDistance = new List <double>();
                for (int j = 0; j < LINES.Count; j++)
                {
                    double dist = 0;
                    if (i == j || tmpFlag.Contains(j))
                    {
                        continue;
                    }
                    bool IsSameDir = IsSameDirection(LINES[i], LINES[j], ref dist);
                    if (IsSameDir && dist != 0)
                    {
                        LINE tmpLine1 = LINES[i];
                        LINE tmpLine2 = LINES[j];
                        bool IsReverse = IsReverseDirection(tmpLine1.GetDirection(), tmpLine2.GetDirection());
                        XYZ  stPoint_1; XYZ stPoint_2; XYZ enPoint_1; XYZ enPoint_2;
                        if (IsReverse)
                        {
                            stPoint_1 = tmpLine1.GetStartPoint();
                            stPoint_2 = tmpLine2.GetEndPoint();
                            enPoint_1 = tmpLine1.GetEndPoint();
                            enPoint_2 = tmpLine2.GetStartPoint();
                        }
                        else
                        {
                            stPoint_1 = tmpLine1.GetStartPoint();
                            stPoint_2 = tmpLine2.GetStartPoint();
                            enPoint_1 = tmpLine1.GetEndPoint();
                            enPoint_2 = tmpLine2.GetEndPoint();
                        }
                        double dist_1 = GetDistanceByTwoPoint(stPoint_1, stPoint_2);
                        double dist_2 = GetDistanceByTwoPoint(enPoint_1, enPoint_2);

                        if (dist == dist_1 && dist_1 == dist_2)
                        {
                            LINE newLINE = LINES[j];
                            if (IsReverse)
                            {
                                newLINE           = new LINE(LINES[j].GetEndPoint(), LINES[j].GetStartPoint());
                                newLINE.Name      = LINES[j].Name;
                                newLINE.LevelName = LINES[j].LevelName;
                                newLINE.Width     = LINES[j].Width;
                            }
                            tmpFlag.Add(j);
                            tmpLine.Add(newLINE);
                            tmpDistance.Add(dist);
                        }
                    }
                }

                if (tmpFlag.Count > 0)
                {
                    double minDist = tmpDistance.Min();
                    int    po      = FindAllIndexof(tmpDistance, minDist)[0];
                    flag.Add(i);
                    flag.Add(tmpFlag[po]);
                    Beams.Add(new BEAM(LINES[i], tmpLine[po]));
                }
            }

            return(Beams);
        }
コード例 #18
0
        /// <summary>
        /// Get Beam parameter Lines using to Create beam those lines is the center line of beam
        /// </summary>
        /// <param name="Collect"></param>
        /// <param name="H_Direction_Lines"></param>
        /// <param name="V_Direction_Lines"></param>
        /// <param name="H_Beams"></param>
        /// <param name="V_Beams"></param>
        public static List <LINE> GetBeamDrawLines(List <List <LINE> > Collect, List <LINE> H_Direction_Lines, List <LINE> V_Direction_Lines)
        {
            List <LINE> RESULT = new List <LINE>();

            /// Collect Part
            foreach (List <LINE> co in Collect)
            {
                if (co.Count() <= 4)
                {
                    LINE   line1 = co[0];
                    LINE   line2 = co[1];
                    XYZ    p1    = null;
                    XYZ    p2    = null;
                    double ll1   = GeometryResult.Get_Length(line1);
                    double ll2   = GeometryResult.Get_Length(line2);
                    if (ll1 > ll2)
                    {
                        if (line1.GetStartPoint().Y == line1.GetEndPoint().Y)
                        {
                            p1 = new XYZ(line1.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0);
                            p2 = new XYZ(line1.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0);
                        }
                        else if (line1.GetStartPoint().X == line1.GetEndPoint().X)
                        {
                            p1 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetStartPoint().Y, 0);
                            p2 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetEndPoint().Y, 0);
                        }
                    }
                    else
                    {
                        if (line2.GetStartPoint().Y == line2.GetEndPoint().Y)
                        {
                            p1 = new XYZ(line2.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0);
                            p2 = new XYZ(line2.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0);
                        }
                        else if (line2.GetStartPoint().X == line2.GetEndPoint().X)
                        {
                            p1 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetStartPoint().Y, 0);
                            p2 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetEndPoint().Y, 0);
                        }
                    }

                    if (p1 != null)
                    {
                        RESULT.Add(new LINE(p1, p2));
                    }
                }
            }

            /// H-Beam Part
            List <LINE> sorted_H = H_Direction_Lines.OrderBy(e => e.GetStartPoint().Y).ToList();
            List <LINE> H_Beams  = new List <LINE>();

            int[] is_pickup = new int[sorted_H.Count()];
            for (int i = 0; i < sorted_H.Count(); i++)
            {
                if (is_pickup[i] == 1)
                {
                    continue;
                }

                LINE baseLine = sorted_H[i];
                for (int j = 0; j < sorted_H.Count(); j++)
                {
                    if (j == i || is_pickup[j] == 1)
                    {
                        continue;
                    }

                    LINE cmpLine = sorted_H[j];

                    if (baseLine.GetSlope() == -cmpLine.GetSlope())
                    {
                        cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint());
                    }

                    if (baseLine.GetStartPoint().X == cmpLine.GetStartPoint().X&& baseLine.GetEndPoint().X == cmpLine.GetEndPoint().X)
                    {
                        is_pickup[i] = 1;
                        is_pickup[j] = 1;
                        XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0);
                        XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0);
                        H_Beams.Add(new LINE(p1, p2));
                        RESULT.Add(new LINE(p1, p2));
                        break;
                    }
                }
            }

            /// V-Beam Part
            List <LINE> V_Beams  = new List <LINE>();
            List <LINE> sorted_V = V_Direction_Lines.OrderBy(e => e.GetStartPoint().X).ToList();

            is_pickup = new int[sorted_V.Count()];
            for (int i = 0; i < sorted_V.Count(); i++)
            {
                if (is_pickup[i] == 1)
                {
                    continue;
                }

                LINE baseLine = sorted_V[i];
                for (int j = 0; j < sorted_V.Count(); j++)
                {
                    if (j == i || is_pickup[j] == 1)
                    {
                        continue;
                    }

                    LINE cmpLine = sorted_V[j];

                    if (baseLine.GetSlope() == -cmpLine.GetSlope())
                    {
                        cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint());
                    }

                    if (baseLine.GetStartPoint().Y == cmpLine.GetStartPoint().Y&& baseLine.GetEndPoint().Y == cmpLine.GetEndPoint().Y)
                    {
                        is_pickup[i] = 1;
                        is_pickup[j] = 1;
                        XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0);
                        XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0);
                        V_Beams.Add(new LINE(p1, p2));
                        RESULT.Add(new LINE(p1, p2));
                        break;
                    }
                }
            }


            return(RESULT);
        }
コード例 #19
0
        /// <summary>
        /// Classify Lines to "closed curve" or "H_dir_lines" or "V_dir_lines" or "else_dir_lines"
        /// </summary>
        /// <param name="LINES"></param>
        /// <param name="Collect"></param>
        /// <param name="H_Direction_Lines"></param>
        /// <param name="V_Direction_Lines"></param>
        /// <param name="Else_Direction_Lines"></param>
        public static void ClassifyLines(List <LINE> LINES,
                                         out List <List <LINE> > Collect,
                                         out List <LINE> H_Direction_Lines,
                                         out List <LINE> V_Direction_Lines,
                                         out List <LINE> Else_Direction_Lines)
        {
            Collect = new List <List <LINE> >();
            int[] is_pickup = new int[LINES.Count];
            for (int i = 0; i < LINES.Count; i++)
            {
                if (is_pickup[i] == 1)
                {
                    continue;
                }

                LINE        baseLine = LINES[i];
                List <LINE> tmpData  = new List <LINE>();
                tmpData.Add(baseLine);
                int j = 0;

                while (j < LINES.Count)
                {
                    LINE cmpLine = LINES[j];
                    if (is_pickup[j] == 1 || j == i)
                    {
                        j = j + 1;
                        continue;
                    }
                    if (cmpLine.GetStartPoint().X == baseLine.GetEndPoint().X&& cmpLine.GetStartPoint().Y == baseLine.GetEndPoint().Y)
                    {
                        baseLine = cmpLine;
                        tmpData.Add(baseLine);
                        is_pickup[j] = 1;
                        j            = 0;
                    }
                    else if (cmpLine.GetEndPoint().X == baseLine.GetEndPoint().X&& cmpLine.GetEndPoint().Y == baseLine.GetEndPoint().Y)
                    {
                        baseLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint());
                        tmpData.Add(baseLine);
                        is_pickup[j] = 1;
                        j            = 0;
                    }
                    else if (tmpData[0].GetStartPoint().X == cmpLine.GetStartPoint().X&& tmpData[0].GetStartPoint().Y == cmpLine.GetStartPoint().Y)
                    {
                        tmpData.Insert(0, new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()));
                        is_pickup[j] = 1;
                        j            = 0;
                    }
                    else if (tmpData[0].GetStartPoint().X == cmpLine.GetEndPoint().X&& tmpData[0].GetStartPoint().Y == cmpLine.GetEndPoint().Y)
                    {
                        tmpData.Insert(0, cmpLine);
                        is_pickup[j] = 1;
                        j            = 0;
                    }
                    else
                    {
                        j = j + 1;
                    }
                }

                if (tmpData.Count != 1)
                {
                    Collect.Add(tmpData);
                    is_pickup[i] = 1;
                }
            }

            H_Direction_Lines    = new List <LINE>();
            V_Direction_Lines    = new List <LINE>();
            Else_Direction_Lines = new List <LINE>();

            for (int ii = 0; ii < is_pickup.Count(); ii++)
            {
                if (is_pickup[ii] == 0)
                {
                    LINE line = LINES[ii];
                    if (GeometryResult.Is_Horizontal(line))
                    {
                        H_Direction_Lines.Add(line);
                    }
                    else if (GeometryResult.Is_Vertical(line))
                    {
                        V_Direction_Lines.Add(line);
                    }
                    else
                    {
                        Else_Direction_Lines.Add(line);
                    }
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// 取得所有的梁(水平與垂直向)
        /// </summary>
        /// <returns></returns>
        private List <LINE> GetAllBeams(Level targetLevel_)
        {
            FilteredElementCollector collector = new FilteredElementCollector(revitDoc);

            collector.OfCategory(BuiltInCategory.OST_StructuralFraming);
            collector.OfClass(typeof(FamilyInstance));
            IList <Element> beams = collector.ToElements();
            List <LINE>     Beams = new List <LINE>();

            foreach (Element beam in beams)
            {
                try
                {
                    ///// 取得梁的Level
                    Parameter mLevel    = beam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
                    string    levelName = mLevel.AsValueString();

                    //// 取得梁的類型與其寬度
                    ElementType type  = revitDoc.GetElement(beam.GetTypeId()) as ElementType;
                    Parameter   b     = type.LookupParameter("b");
                    double      width = b.AsDouble();



                    ///檢查梁中心線是否有偏移
                    BuiltInParameter paraIndex = BuiltInParameter.START_Y_JUSTIFICATION;
                    Parameter        p1        = beam.get_Parameter(paraIndex);
                    string           offset    = p1.AsValueString();

                    // 取得梁偏移量
                    BuiltInParameter paraIndex1 = BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION;
                    Parameter        of1        = beam.get_Parameter(paraIndex1);
                    string           offset1    = of1.AsValueString();
                    BuiltInParameter paraIndex2 = BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION;
                    Parameter        of2        = beam.get_Parameter(paraIndex2);
                    string           offset2    = of2.AsValueString();

                    if (offset1 != offset2)
                    {
                        continue;
                    }



                    double shift = Convert.ToDouble(offset1) / 304.8;

                    LocationCurve Locurve = beam.Location as LocationCurve;
                    Line          line    = Locurve.Curve as Line;

                    XYZ direction = line.Direction;

                    XYZ VertiDir = offset == "左" ? new XYZ(line.Direction.Y, -line.Direction.X, line.Direction.Z) :
                                   offset == "右" ? new XYZ(-line.Direction.Y, line.Direction.X, line.Direction.Z) : line.Direction;


                    XYZ pp1 = line.GetEndPoint(0);
                    XYZ pp2 = line.GetEndPoint(1);

                    ///Ori Points
                    XYZ stPoint = new XYZ(pp1.X + width / 2 * VertiDir.X,
                                          pp1.Y + width / 2 * VertiDir.Y,
                                          pp1.Z + width / 2 * VertiDir.Z);

                    XYZ enPoint = new XYZ(pp1.X + line.Length * line.Direction.X + width / 2 * VertiDir.X,
                                          pp1.Y + line.Length * line.Direction.Y + width / 2 * VertiDir.Y,
                                          pp1.Z + line.Length * line.Direction.Z + width / 2 * VertiDir.Z);

                    LINE LINE = new LINE(stPoint, enPoint);

                    LINE.Name      = beam.Name;
                    LINE.LevelName = levelName;
                    LINE.Width     = width;


                    if (Math.Round(LINE.GetStartPoint().Z, 3) == Math.Round(LINE.GetEndPoint().Z, 3))
                    {
                        Beams.Add(LINE);
                    }
                }
                catch (Exception)
                {
                }
            }
            return(Beams);
        }
コード例 #21
0
 public static bool Is_Horizontal(LINE line)
 {
     return(line.GetStartPoint().Y == line.GetEndPoint().Y ? true : false);
 }