예제 #1
1
파일: XYZMath.cs 프로젝트: AMEE/revit
 /// <summary>
 /// Find the view direction vector, 
 /// which is the same meaning of ViewDirection property in View class
 /// </summary>
 /// <param name="curveArray">the curve array which form floor's AnalyticalModel</param>
 /// <returns>the view direction vector</returns>
 public static Autodesk.Revit.DB.XYZ FindFloorViewDirection(CurveArray curveArray)
 {
     // Because the floor is always on the level,
     // so each curve can give the direction information.
     Curve curve = curveArray.get_Item(0);
     Autodesk.Revit.DB.XYZ first = curve.get_EndPoint(0);
     Autodesk.Revit.DB.XYZ second = curve.get_EndPoint(1);
     return FindDirection(first, second);
 }
예제 #2
0
 /// <summary>
 /// Check if a bunch of lines enclose a rectangle.
 /// </summary>
 /// <param name="lines"></param>
 /// <returns></returns>
 public static bool IsRectangle(List <Curve> lines)
 {
     if (lines.Count() == 4)
     {
         if (GetPtsOfCrvs(lines).Count() == lines.Count())
         {
             CurveArray edges = RegionDetect.AlignCrv(lines);
             if (IsPerpendicular(edges.get_Item(0), edges.get_Item(1)) &&
                 IsPerpendicular(edges.get_Item(1), edges.get_Item(2)))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
예제 #3
0
        /// <summary>
        /// 闭合曲线圈排序
        /// </summary>
        public static CurveArray SortCurves(this CurveArray curves)
        {
            CurveArray _curves  = new CurveArray();
            XYZ        temp     = curves.get_Item(0).GetEndPoint(1); //拿出一根线段的一个终点
            Curve      temCurve = curves.get_Item(0);                //拿出一根线段

            _curves.Append(temCurve);                                //添加第一根线段
            while (_curves.Size != curves.Size)                      //循环停止条件
            {
                temCurve = temCurve.GetNext(curves, temp);           //寻找相连线段
                if (Math.Abs(temp.X - temCurve.GetEndPoint(0).X) < Precision_.TheShortestDistance &&
                    Math.Abs(temp.Y - temCurve.GetEndPoint(0).Y) < Precision_.TheShortestDistance)
                {
                    temp = temCurve.GetEndPoint(1);
                }
                else
                {
                    temp = temCurve.GetEndPoint(0);
                }
                _curves.Append(temCurve);
            }
            if (Math.Abs(temp.X - curves.get_Item(0).GetEndPoint(0).X) > Precision_.TheShortestDistance ||
                Math.Abs(temp.Y - curves.get_Item(0).GetEndPoint(0).Y) > Precision_.TheShortestDistance ||
                Math.Abs(temp.Z - curves.get_Item(0).GetEndPoint(0).Z) > Precision_.TheShortestDistance)   //temp最后一次,应该就是选段闭合的起点
            {
                throw new InvalidOperationException("CurveLoop的起点与终点不闭合。");
            }
            return(_curves);
        }
예제 #4
0
        private CurveArray sortCurveArray(CurveArray unsorted, Boolean Debug)
        {
            unsorted.get_Item(0).GetEndPoint(0);
            CurveArray sorted = new CurveArray();

            sorted.Append(unsorted.get_Item(0));

            while (sorted.Size < 6)
            {
                for (int i = 0; i < unsorted.Size; i++)
                {
                    if (sorted.get_Item(sorted.Size - 1).GetEndPoint(1).IsAlmostEqualTo(unsorted.get_Item(i).GetEndPoint(0)))// checks if end of last point = start of the next
                    {
                        sorted.Append(unsorted.get_Item(i));
                    }
                }
            }
            if (Debug)
            {
                for (int i = 0; i < sorted.Size; i++)
                {
                    System.Diagnostics.Debug.WriteLine("Array Position" + i + "Start Point" + sorted.get_Item(i).GetEndPoint(0).ToString() + "end point" + sorted.get_Item(i).GetEndPoint(1).ToString());
                }
            }
            return(sorted);
            //   return unsorted;
        }
예제 #5
0
        /// <summary>
        /// Chaining the profile.
        /// </summary>
        /// <param name="lines">none-chained profile</param>
        private void SortCurves(CurveArray lines)
        {
            Autodesk.Revit.DB.XYZ temp = lines.get_Item(0).GetEndPoint(1);
            Curve temCurve             = lines.get_Item(0);

            Profile.Append(temCurve);

            while (Profile.Size != lines.Size)
            {
                temCurve = GetNext(lines, temp, temCurve);

                if (Math.Abs(temp.X - temCurve.GetEndPoint(0).X) < PRECISION &&
                    Math.Abs(temp.Y - temCurve.GetEndPoint(0).Y) < PRECISION)
                {
                    temp = temCurve.GetEndPoint(1);
                }
                else
                {
                    temp = temCurve.GetEndPoint(0);
                }

                Profile.Append(temCurve);
            }

            if (Math.Abs(temp.X - lines.get_Item(0).GetEndPoint(0).X) > PRECISION ||
                Math.Abs(temp.Y - lines.get_Item(0).GetEndPoint(0).Y) > PRECISION ||
                Math.Abs(temp.Z - lines.get_Item(0).GetEndPoint(0).Z) > PRECISION)
            {
                throw new InvalidOperationException("The selected walls should be closed.");
            }
        }
예제 #6
0
        private void SortCurves(CurveArray lines)
        {
            XYZ   pointCurves = lines.get_Item(0).GetEndPoint(1);
            Curve temCurve    = lines.get_Item(0);


            Profile = creApp.NewCurveArray();

            Profile.Append(temCurve);

            while (Profile.Size != lines.Size)
            {
                temCurve = GetNext(lines, pointCurves, temCurve);

                if (Math.Abs(pointCurves.X - temCurve.GetEndPoint(0).X) < PRECISION &&
                    Math.Abs(pointCurves.Y - temCurve.GetEndPoint(0).Y) < PRECISION)
                {
                    pointCurves = temCurve.GetEndPoint(1);
                }
                else
                {
                    pointCurves = temCurve.GetEndPoint(0);
                }

                Profile.Append(temCurve);
            }
        }
        /// <summary>
        /// Let user to select four points for determining the edge of a rectengular slab
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument  uidoc = commandData.Application.ActiveUIDocument;
            Document    doc   = uidoc.Document;
            Transaction tx    = new Transaction(doc);

            tx.Start("Create Sloped Slab");

            XYZ point1 = uidoc.Selection.PickPoint();
            XYZ point2 = uidoc.Selection.PickPoint();
            XYZ point3 = uidoc.Selection.PickPoint();
            XYZ point4 = uidoc.Selection.PickPoint();

            Line line1 = Line.CreateBound(point1, point2);
            Line line2 = Line.CreateBound(point2, point3);
            Line line3 = Line.CreateBound(point3, point4);
            Line line4 = Line.CreateBound(point4, point1);

            CurveArray curveArray = new CurveArray();

            curveArray.Append(line1);
            curveArray.Append(line2);
            curveArray.Append(line3);
            curveArray.Append(line4);

            Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).Where <Element>(e => e.Name.Equals("2F")).FirstOrDefault <Element>() as Level;
            Floor floor = doc.Create.NewSlab(curveArray, level, curveArray.get_Item(1) as Line, 0, true);

            tx.Commit();
            return(Result.Succeeded);
        }
예제 #8
0
        internal static int GetindexCurveParalelWithCurve(CurveArray curveArray)
        {
            Curve firthCurve          = curveArray.get_Item(0);
            XYZ   firthCurveDirection = firthCurve.GetEndPoint(1) - firthCurve.GetEndPoint(0);

            for (int i = 1; i < curveArray.Size; i++)
            {
                Curve curve          = curveArray.get_Item(i);
                XYZ   curveDirection = curve.GetEndPoint(1) - curve.GetEndPoint(0);
                if (Common.IsParallel(firthCurveDirection, curveDirection))
                {
                    return(i);
                }
            }
            return(0);
        }
예제 #9
0
        // Create CurveArray from List<Curve>. not a universal method. only after regionCluster()
        public static CurveArray AlignCrv(List <Curve> polylines)
        {
            List <Curve> imagelines = polylines.ToList();
            int          lineNum    = imagelines.Count;
            CurveArray   polygon    = new CurveArray();

            polygon.Append(imagelines[0]);
            imagelines.RemoveAt(0);
            while (polygon.Size < lineNum)
            {
                XYZ endPt = polygon.get_Item(polygon.Size - 1).GetEndPoint(1);
                for (int i = 0; i < imagelines.Count; i++)
                {
                    if (imagelines[i].GetEndPoint(0).IsAlmostEqualTo(endPt))
                    {
                        polygon.Append(imagelines[i]);
                        imagelines.Remove(imagelines[i]);
                        break;
                    }
                    if (imagelines[i].GetEndPoint(1).IsAlmostEqualTo(endPt))
                    {
                        polygon.Append(imagelines[i].CreateReversed());
                        imagelines.Remove(imagelines[i]);
                        break;
                    }
                }
            }
            return(polygon);
        }
예제 #10
0
        internal static XYZ GetSharfOpenningOrigin(Element element)
        {
            XYZ origin = null;

            if (element is Opening)
            {
                Opening opening = element as Opening;
                if (IsRectangle(element))
                {
                    CurveArray curveArray                       = opening.BoundaryCurves;
                    Curve      firthCurve                       = curveArray.get_Item(0);
                    XYZ        midleFirthCurve                  = Common.GetMidlePoint(firthCurve);
                    int        indexCurveParalelFirthCurve      = GetindexCurveParalelWithCurve(curveArray);
                    Curve      curveParalelFirthCurve           = curveArray.get_Item(indexCurveParalelFirthCurve);
                    XYZ        MidlePointCurveParalelFirthCurve = Common.GetMidlePoint(curveParalelFirthCurve);
                    Line       line1      = Line.CreateBound(midleFirthCurve, MidlePointCurveParalelFirthCurve);
                    Curve      seconCurve = null;
                    //GetCoupleParalelCurve(curveArray, indexCurveParalelFirthCurve,out seconCurve, out curveParalelSeconCurve);
                    for (int i = 1; i < curveArray.Size; i++)
                    {
                        if (i != indexCurveParalelFirthCurve)
                        {
                            seconCurve = curveArray.get_Item(i);
                            break;
                        }
                    }
                    XYZ midlePointSeconCurve = Common.GetMidlePoint(seconCurve);
                    origin = line1.Project(midlePointSeconCurve).XYZPoint;
                }
                else
                {
                    CurveArray curveArray = opening.BoundaryCurves;
                    foreach (Curve curve in curveArray)
                    {
                        if (curve is Arc)
                        {
                            Arc arc = curve as Arc;
                            return(arc.Center);
                        }
                    }
                }
            }
            return(origin);
        }
예제 #11
0
        internal static Curve getLongestCurve(CurveArray curveArray, out Curve shorterCurve)
        {
            Curve  firstCurveInCurveArray = curveArray.get_Item(0);
            double Maxlength = firstCurveInCurveArray.Length;
            Curve  curve     = null;

            for (int i = 1; i < curveArray.Size; i++)
            {
                curve = curveArray.get_Item(i);
                double length = curve.Length;
                if (length > Maxlength)
                {
                    shorterCurve = firstCurveInCurveArray;
                    return(curve);
                }
            }
            shorterCurve = curve;
            return(firstCurveInCurveArray);
        }
예제 #12
0
        /// <summary>
        /// Find the view direction vector,
        /// which is the same meaning of ViewDirection property in View class
        /// </summary>
        /// <param name="curveArray">the curve array which form floor's AnalyticalModel</param>
        /// <returns>the view direction vector</returns>
        public static Autodesk.Revit.DB.XYZ FindFloorViewDirection(CurveArray curveArray)
        {
            // Because the floor is always on the level,
            // so each curve can give the direction information.
            Curve curve = curveArray.get_Item(0);

            Autodesk.Revit.DB.XYZ first  = curve.GetEndPoint(0);
            Autodesk.Revit.DB.XYZ second = curve.GetEndPoint(1);
            return(FindDirection(first, second));
        }
예제 #13
0
        ///<summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            //initialize members
            m_revit      = revit;
            m_currentDoc = revit.Application.ActiveUIDocument;
            m_data       = new AreaReinData();

            try
            {
                //check precondition and prepare necessary data to create AreaReinforcement.
                Reference  refer  = null;
                CurveArray curves = null;
                Floor      floor  = InitFloor(ref refer, ref curves);

                //ask for user's input
                AreaReinData dataOnFloor             = new AreaReinData();
                CreateComplexAreaReinForm createForm = new
                                                       CreateComplexAreaReinForm(dataOnFloor);
                if (createForm.ShowDialog() == DialogResult.OK)
                {
                    //define the Major Direction of AreaReinforcement,
                    //we get direction of first Line on the Floor as the Major Direction
                    Line firstLine = (Line)(curves.get_Item(0));
                    Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                        firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                        firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                        firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                    //create AreaReinforcement by NewAreaReinforcement function
                    DocCreator        creator  = m_revit.Application.ActiveUIDocument.Document.Create;
                    AreaReinforcement areaRein = creator.
                                                 NewAreaReinforcement(floor, curves, majorDirection);

                    //set AreaReinforcement and it's AreaReinforcementCurves parameters
                    dataOnFloor.FillIn(areaRein);
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
            }
            catch (ApplicationException appEx)
            {
                message = appEx.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch
            {
                message = "Unknow Errors.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Cancelled);
        }
예제 #14
0
 internal static bool IsRectangle(Element element)
 {
     if (element is Opening)
     {
         Opening    opening    = element as Opening;
         CurveArray curveArray = opening.BoundaryCurves;
         if (curveArray.get_Item(0) is Line)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
예제 #15
0
        /// <summary>
        /// create simple AreaReinforcement on vertical straight rectangular wall
        /// </summary>
        /// <param name="wall"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnWall(Wall wall)
        {
            //make sure selected is basic wall
            if (wall.WallType.Kind != WallKind.Basic)
            {
                MessageBox.Show("Selected wall is not a basic wall.");
                return(false);
            }

            GeomHelper helper = new GeomHelper();
            Reference  refer  = null;
            CurveArray curves = null;

            //check whether wall is vertical rectangular and analytical model shape is line
            if (!helper.GetWallGeom(wall, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a structural straight rectangular wall.");
                throw appEx;
            }

            AreaReinDataOnWall       dataOnWall = new AreaReinDataOnWall();
            CreateSimpleAreaReinForm createForm = new
                                                  CreateSimpleAreaReinForm(dataOnWall);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;

                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //create AreaReinforcement by NewAreaReinforcement function
                AreaReinforcement areaRein = creator.NewAreaReinforcement(wall, curves, majorDirection);
                dataOnWall.FillIn(areaRein);
                return(true);
            }
            return(false);
        }
예제 #16
0
        /// <summary>
        /// judge whether given 4 lines can form a rectangular
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>is rectangular</returns>
        public static bool IsRectangular(CurveArray curves)
        {
            //make sure the CurveArray contains 4 line
            if (curves.Size != 4)
            {
                return(false);
            }
            Line[] lines = new Line[4];
            for (int i = 0; i < 4; i++)
            {
                lines[i] = curves.get_Item(i) as Line;
                if (null == lines[i])
                {
                    return(false);
                }
            }

            //make sure the first line is vertical to 2 lines and parallel to another line
            Line iniLine = lines[0];

            Line[] verticalLines = new Line[2];
            Line   paraLine      = null;
            int    index         = 0;

            for (int i = 1; i < 4; i++)
            {
                if (IsVertical(lines[0], lines[i]))
                {
                    verticalLines[index] = lines[i];
                    index++;
                }
                else
                {
                    paraLine = lines[i];
                }
            }
            if (index != 2)
            {
                return(false);
            }
            bool flag = IsVertical(paraLine, verticalLines[0]);

            return(flag);
        }
예제 #17
0
        /// <summary>
        /// 找出封閉曲線最大與最小邊界值
        /// </summary>
        /// <param name="curveArray"></param>
        /// <returns></returns>
        private List <XYZ> GetMaxRange(CurveArray curveArray)
        {
            List <Curve> curve = new List <Curve>();

            for (int i = 0; i < curveArray.Size; i++)
            {
                curve.Add(curveArray.get_Item(i));
            }

            double min_x = curve.Min(t => t.GetEndPoint(0).X);
            double max_x = curve.Max(t => t.GetEndPoint(0).X);
            double min_y = curve.Min(t => t.GetEndPoint(0).Y);
            double max_y = curve.Max(t => t.GetEndPoint(0).Y);


            return(new List <XYZ>()
            {
                new XYZ(min_x, min_y, 0), new XYZ(max_x, max_y, 0)
            });
        }
예제 #18
0
        /// <summary>
        /// create CurveArray which contain 8 curves, 4 is exterior lines and 4 is interior lines
        /// </summary>
        /// <param name="curves"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private CurveArray AddInlaidCurves(CurveArray curves, double scale)
        {
            //because curves is readonly, can't use method Curve.Append(Curve)
            List <Line> lines = new List <Line>();

            for (int i = 0; i < 4; i++)
            {
                Line temp = curves.get_Item(i) as Line;
                lines.Add(temp);
            }

            //length and width of the rectangle
            double length = GeomUtil.GetLength(lines[0]);
            double width  = GeomUtil.GetLength(lines[1]);

            for (int i = 0; i < 2; i++)
            {
                //height line
                Line   tempLine1   = lines[i * 2];
                Line   scaledLine1 = GeomUtil.GetScaledLine(tempLine1, scale);
                double distance1   = scale / 2 * width;
                Line   movedLine1  = GeomUtil.GetXYParallelLine(scaledLine1, distance1);
                lines.Add(movedLine1);

                //width line
                Line   tempLine2   = lines[i * 2 + 1];
                Line   scaledLine2 = GeomUtil.GetScaledLine(tempLine2, scale);
                double distance2   = scale / 2 * length;
                Line   movedLine2  = GeomUtil.GetXYParallelLine(scaledLine2, distance2);
                lines.Add(movedLine2);
            }

            //add all 8 lines into return array
            CurveArray allLines = new CurveArray();

            for (int i = 0; i < 8; i++)
            {
                allLines.Append(lines[i]);
            }
            return(allLines);
        }
예제 #19
0
파일: GeomUtil.cs 프로젝트: AMEE/revit
        const double PRECISION = 0.00001; //precision when judge whether two doubles are equal

        #endregion Fields

        #region Methods

        /// <summary>
        /// judge whether given 4 lines can form a rectangular
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>is rectangular</returns>
        /// <summary>
        /// judge whether given 4 lines can form a rectangular
        /// </summary>
        /// <param name="lines"></param>
        /// <returns>is rectangular</returns>
        public static bool IsRectangular(CurveArray curves)
        {
            if (curves.Size != 4)
            {
                return false;
            }

            Line[] lines = new Line[4];
            for (int i = 0; i < 4; i++)
            {
                lines[i] = curves.get_Item(i) as Line;
                if (null == lines[i])
                {
                    return false;
                }
            }

            Line iniLine = lines[0];
            Line[] verticalLines = new Line[2];
            Line paraLine = null;
            int index = 0;
            for (int i = 1; i < 4; i++)
            {
                if (IsVertical(lines[0], lines[i]))
                {
                    verticalLines[index] = lines[i];
                    index++;
                }
                else
                {
                    paraLine = lines[i];
                }
            }
            if (index != 2)
            {
                return false;
            }
            bool flag = IsVertical(paraLine, verticalLines[0]);
            return flag;
        }
예제 #20
0
        /// <summary>
        /// create simple AreaReinforcement on horizontal floor
        /// </summary>
        /// <param name="floor"></param>
        /// <returns>is successful</returns>
        private bool CreateAreaReinOnFloor(Floor floor)
        {
            GeomHelper helper = new GeomHelper();
            Reference  refer  = null;
            CurveArray curves = null;

            //check whether floor is horizontal rectangular
            //and prepare necessary to create AreaReinforcement
            if (!helper.GetFloorGeom(floor, ref refer, ref curves))
            {
                ApplicationException appEx = new ApplicationException(
                    "Your selection is not a horizontal rectangular slab.");
                throw appEx;
            }

            AreaReinDataOnFloor      dataOnFloor = new AreaReinDataOnFloor();
            CreateSimpleAreaReinForm createForm  =
                new CreateSimpleAreaReinForm(dataOnFloor);

            //allow use select parameters to create
            if (createForm.ShowDialog() == DialogResult.OK)
            {
                //define the Major Direction of AreaReinforcement,
                //we get direction of first Line on the Floor as the Major Direction
                Line firstLine = (Line)(curves.get_Item(0));
                Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
                    firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X,
                    firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y,
                    firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z);

                //crete AreaReinforcement by NewAreaReinforcement function
                DocCreator        creator  = m_revit.Application.ActiveUIDocument.Document.Create;
                AreaReinforcement areaRein = creator.NewAreaReinforcement(floor, curves, majorDirection);

                //set AreaReinforcement and it's AreaReinforcementCurves parameters
                dataOnFloor.FillIn(areaRein);
                return(true);
            }
            return(false);
        }
        private XYZ GetSharfOpenningOrigin()
        {
            XYZ origin = null;

            if (_element is Opening)
            {
                Opening  opening   = _element as Opening;
                Document document  = opening.Document;
                Level    level     = document.GetElement(opening.LevelId) as Level;
                double   elevation = 0;
                if (level != null)
                {
                    elevation = level.Elevation;
                }
                if (_isRectangle)
                {
                    CurveArray curveArray                       = opening.BoundaryCurves;
                    Curve      firthCurve                       = curveArray.get_Item(0);
                    XYZ        midleFirthCurve                  = Common.GetMidlePoint(firthCurve);
                    int        indexCurveParalelFirthCurve      = GetindexCurveParalelWithCurve(curveArray);
                    Curve      curveParalelFirthCurve           = curveArray.get_Item(indexCurveParalelFirthCurve);
                    XYZ        MidlePointCurveParalelFirthCurve = Common.GetMidlePoint(curveParalelFirthCurve);
                    Line       line1      = Line.CreateBound(midleFirthCurve, MidlePointCurveParalelFirthCurve);
                    Curve      seconCurve = null;
                    //GetCoupleParalelCurve(curveArray, indexCurveParalelFirthCurve,out seconCurve, out curveParalelSeconCurve);
                    for (int i = 1; i < curveArray.Size; i++)
                    {
                        if (i != indexCurveParalelFirthCurve)
                        {
                            seconCurve = curveArray.get_Item(i);
                            break;
                        }
                    }
                    XYZ midlePointSeconCurve = Common.GetMidlePoint(seconCurve);
                    origin = line1.Project(midlePointSeconCurve).XYZPoint;
                    double elevationOfset = 0;
                    if (!Common.IsEqual(elevation, origin.Z))
                    {
                        elevationOfset = elevation;
                    }
                    Parameter paramBaseOfset = opening.LookupParameter("Base Offset");
                    double    baseOfset      = paramBaseOfset.AsDouble();
                    origin = origin + new XYZ(0, 0, baseOfset + elevationOfset);
                    //origin = origin + new XYZ(0, 0, elevationOfset - baseOfset);
                }
                else
                {
                    CurveArray curveArray = opening.BoundaryCurves;
                    foreach (Curve curve in curveArray)
                    {
                        if (curve is Arc)
                        {
                            Arc arc = curve as Arc;
                            origin = arc.Center;
                            double elevationOfset = 0;
                            if (!Common.IsEqual(elevation, origin.Z))
                            {
                                elevationOfset = elevation;
                            }
                            Parameter paramBaseOfset = opening.LookupParameter("Base Offset");
                            double    baseOfset      = paramBaseOfset.AsDouble();
                            origin = origin + new XYZ(0, 0, baseOfset + elevationOfset);
                            return(origin);
                        }
                    }
                }
            }
            return(origin);
        }
예제 #22
0
        public void AddRoof(Document rvtDoc, List <Wall> walls)
        {
            // Hardcoding the roof type we will use.
            // e.g., "Basic Roof: Generic - 400mm"

            const string roofFamilyName        = "Basic Roof";
            const string roofTypeName          = "Generic - 9\"";
            const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName;

            // Find the roof type

            RoofType roofType = (RoofType)ElementFiltering.FindFamilyType(
                rvtDoc,
                typeof(RoofType),
                roofFamilyName,
                roofTypeName,
                null);

            if (roofType == null)
            {
                TaskDialog.Show(
                    "Add roof",
                    "Cannot find (" +
                    roofFamilyAndTypeName +
                    "). Maybe you use a different template? Try with DefaultMetric.rte.");
            }

            /*
             * Wall thickness to adjust the  footprint of the walls
             * to the outer most lines.
             * Note: This may not be the best way,
             * but we will live with this excercise.
             * DIM wallThickness as Double
             */
            double wallThickness = walls[0].WallType.GetCompoundStructure().GetLayers()[0].Width;

            double     dt  = wallThickness / 2.0;
            List <XYZ> dts = new List <XYZ>(5);

            dts.Add(new XYZ(-dt, -dt, 0.0));
            dts.Add(new XYZ(dt, -dt, 0.0));
            dts.Add(new XYZ(dt, dt, 0.0));
            dts.Add(new XYZ(-dt, dt, 0.0));
            dts.Add(dts[0]);

            // set the profile from four wals
            CurveArray footPrint = new CurveArray();

            for (int i = 0; i <= 3; i++)
            {
                LocationCurve locCurve = (LocationCurve)walls[i].Location;
                XYZ           pt1      = locCurve.Curve.GetEndPoint(0) + dts[i];
                XYZ           pt2      = locCurve.Curve.GetEndPoint(1) + dts[i + 1];
                Line          line     = Line.CreateBound(pt1, pt2);
                footPrint.Append(line);
            }

            /////////////////////////////////////////////////
            ///new mapping
            /////////////////////////////////////////////////
            Curve      getCurveOne     = footPrint.get_Item(1);
            Curve      getCurveTwo     = footPrint.get_Item(3);
            CurveArray gabledFootprint = new CurveArray();

            gabledFootprint.Append(getCurveOne);
            gabledFootprint.Append(getCurveTwo);

            // get the lvl2 from wall

            ElementId idlvl2 = walls[0].get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();
            Level     lvl2   = rvtDoc.GetElement(idlvl2) as Level;

            ModelCurveArray mapping = new ModelCurveArray();                                               // footprint to model curve mapping
            FootPrintRoof   aRoof   = rvtDoc.Create.NewFootPrintRoof(footPrint, lvl2, roofType, out mapping);


            //double offsetValue = 10;


            foreach /*set the slope */ (ModelCurve modelCurve in mapping)
            {
                aRoof.set_DefinesSlope(modelCurve, true);
                aRoof.set_SlopeAngle(modelCurve, 0.5);
                //aRoof.set_Offset(modelCurve, offsetValue);
            }

            /* performed automatically by transaction commit.
             * rvtDoc.Regenerate();
             * rvtDoc.AutoJoinElement();
             */
        }
예제 #23
0
 private static string GetGeometrySharpOpening(Element openning, bool isRectangle)
 {
     if (openning is Opening)
     {
         Opening openingObject = openning as Opening;
         string  shapename     = "";
         if (isRectangle == true)
         {
             shapename = Define.RECTANGLE_FAMILY;
             string     widthstr          = "";
             string     lenghtstr         = "";
             Parameter  unconnectedHeight = openingObject.LookupParameter("Unconnected Height");
             string     heightstr         = routingStr(unconnectedHeight.AsValueString());
             CurveArray curveArray        = openingObject.BoundaryCurves;
             Curve      firtLine          = curveArray.get_Item(0);
             double     firtLength        = Common.GetLengthFromCurve(firtLine);
             for (int i = 1; i < curveArray.Size; i++)
             {
                 Curve  line   = curveArray.get_Item(i);
                 double lenght = Common.GetLengthFromCurve(line);
                 if (!Common.IsEqual(lenght, firtLength))
                 {
                     if (lenght < firtLength)
                     {
                         widthstr  = routingStr((lenght * Define.mmToFeet).ToString());
                         lenghtstr = routingStr((firtLength * Define.mmToFeet).ToString());
                     }
                     else if (lenght > firtLength)
                     {
                         widthstr  = routingStr((firtLength * Define.mmToFeet).ToString());
                         lenghtstr = routingStr((lenght * Define.mmToFeet).ToString());
                     }
                 }
                 else
                 {
                     widthstr  = routingStr((firtLength * Define.mmToFeet).ToString());
                     lenghtstr = routingStr((firtLength * Define.mmToFeet).ToString());
                 }
                 RectangleGeometry rectangleGeometry = new RectangleGeometry();
                 rectangleGeometry.ShapeName = shapename;
                 rectangleGeometry.Lenght    = lenghtstr;
                 rectangleGeometry.Width     = widthstr;
                 rectangleGeometry.Height    = heightstr;
                 return(JsonConvert.SerializeObject(rectangleGeometry));
             }
         }
         else
         {
             shapename = Define.CYLYNDER_FAMILY;
             CurveArray curveArray = openingObject.BoundaryCurves;
             Curve      firtArc    = curveArray.get_Item(0);
             foreach (Curve curve in curveArray)
             {
                 if (curve is Arc)
                 {
                     firtArc = curve;
                     break;
                 }
             }
             double           radius            = Common.GetRadiusFromCurve(firtArc);
             Parameter        heightParam       = openning.LookupParameter(Define.HEIGHT_PARAMETER_NAME_MEP);
             Parameter        unconnectedHeight = openingObject.LookupParameter("Unconnected Height");
             string           height            = routingStr(unconnectedHeight.AsValueString());
             CylynderGeometry cylynderGeometry  = new CylynderGeometry();
             cylynderGeometry.ShapeName = shapename;
             cylynderGeometry.Radius    = routingStr((radius * Define.mmToFeet).ToString());
             cylynderGeometry.Height    = height;
             return(JsonConvert.SerializeObject(cylynderGeometry));
         }
     }
     return(null);
 }
예제 #24
0
파일: Data.cs 프로젝트: AMEE/revit
        /// <summary>
        /// Chaining the profile.
        /// </summary>
        /// <param name="lines">none-chained profile</param>
        private void SortCurves(CurveArray lines)
        {
            Autodesk.Revit.DB.XYZ temp = lines.get_Item(0).get_EndPoint(1);
            Curve temCurve = lines.get_Item(0);

            Profile.Append(temCurve);

            while (Profile.Size != lines.Size)
            {

                temCurve = GetNext(lines, temp, temCurve);

                if (Math.Abs(temp.X - temCurve.get_EndPoint(0).X) < PRECISION
                    && Math.Abs(temp.Y - temCurve.get_EndPoint(0).Y) < PRECISION)
                {
                    temp = temCurve.get_EndPoint(1);
                }
                else
                {
                    temp = temCurve.get_EndPoint(0);
                }

                Profile.Append(temCurve);
            }

            if (Math.Abs(temp.X - lines.get_Item(0).get_EndPoint(0).X) > PRECISION
                || Math.Abs(temp.Y - lines.get_Item(0).get_EndPoint(0).Y) > PRECISION
                || Math.Abs(temp.Z - lines.get_Item(0).get_EndPoint(0).Z) > PRECISION)
            {
                throw new InvalidOperationException("The selected walls should be closed.");
            }
        }
예제 #25
0
파일: GeomHelper.cs 프로젝트: AMEE/revit
        /// <summary>
        /// create CurveArray which contain 8 curves, 4 is exterior lines and 4 is interior lines
        /// </summary>
        /// <param name="curves"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private CurveArray AddInlaidCurves(CurveArray curves, double scale)
        {
            //because curves is readonly, can't use method Curve.Append(Curve)
            List<Line> lines = new List<Line>();
            for (int i = 0; i < 4; i++)
            {
                Line temp = curves.get_Item(i) as Line;
                lines.Add(temp);
            }

            //length and width of the rectangle
            double length = GeomUtil.GetLength(lines[0]);
            double width = GeomUtil.GetLength(lines[1]);
            for (int i = 0; i < 2; i++)
            {
                //height line
                Line tempLine1 = lines[i * 2];
                Line scaledLine1 = GeomUtil.GetScaledLine(tempLine1, scale);
                double distance1 = scale / 2 * width;
                Line movedLine1 = GeomUtil.GetXYParallelLine(scaledLine1, distance1);
                lines.Add(movedLine1);

                //width line
                Line tempLine2 = lines[i * 2 + 1];
                Line scaledLine2 = GeomUtil.GetScaledLine(tempLine2, scale);
                double distance2 = scale / 2 * length;
                Line movedLine2 = GeomUtil.GetXYParallelLine(scaledLine2, distance2);
                lines.Add(movedLine2);
            }

            //add all 8 lines into return array
            CurveArray allLines = new CurveArray();
            for (int i = 0; i < 8; i++)
            {
                allLines.Append(lines[i]);
            }
            return allLines;
        }
예제 #26
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static Floor ToRevitFloor(this oM.Physical.Elements.Floor floor, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (floor == null || floor.Construction == null || document == null)
            {
                return(null);
            }

            Floor revitFloor = refObjects.GetValue <Floor>(document, floor.BHoM_Guid);

            if (revitFloor != null)
            {
                return(revitFloor);
            }

            PlanarSurface planarSurface = floor.Location as PlanarSurface;

            if (planarSurface == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            FloorType floorType = floor.Construction?.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_Floors
            }, settings, refObjects) as FloorType;

            if (floorType == null)
            {
                floorType = floor.ElementType(document, settings);
            }

            if (floorType == null)
            {
                Compute.ElementTypeNotFoundWarning(floor);
                return(null);
            }

            double bottomElevation = floor.Location.IBounds().Min.Z;
            Level  level           = document.LevelBelow(bottomElevation.FromSI(UnitType.UT_Length), settings);

            oM.Geometry.Plane sketchPlane = new oM.Geometry.Plane {
                Origin = new BH.oM.Geometry.Point {
                    Z = bottomElevation
                }, Normal = Vector.ZAxis
            };
            ICurve     curve      = planarSurface.ExternalBoundary.IProject(sketchPlane);
            CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves());

            BH.oM.Geometry.Plane slabPlane = planarSurface.FitPlane();
            if (1 - Math.Abs(Vector.ZAxis.DotProduct(slabPlane.Normal)) <= settings.AngleTolerance)
            {
                revitFloor = document.Create.NewFloor(curveArray, floorType, level, true);
            }
            else
            {
                Vector normal = slabPlane.Normal;
                if (normal.Z < 0)
                {
                    normal = -slabPlane.Normal;
                }

                double angle = normal.Angle(Vector.ZAxis);
                double tan   = Math.Tan(angle);

                XYZ dir = normal.Project(oM.Geometry.Plane.XY).ToRevit().Normalize();
                BH.oM.Geometry.Line ln = slabPlane.PlaneIntersection(sketchPlane);
                XYZ start = ln.ClosestPoint(curveArray.get_Item(0).GetEndPoint(0).PointFromRevit(), true).ToRevit();
                Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(start, start + dir);

                revitFloor = document.Create.NewSlab(curveArray, level, line, -tan, true);
                revitFloor.SetParameter(BuiltInParameter.ELEM_TYPE_PARAM, floorType.Id);
            }

            revitFloor.CheckIfNullPush(floor);
            if (revitFloor == null)
            {
                return(null);
            }

            document.Regenerate();

            if (planarSurface.InternalBoundaries != null)
            {
                foreach (ICurve hole in planarSurface.InternalBoundaries)
                {
                    document.Create.NewOpening(revitFloor, Create.CurveArray(hole.IProject(slabPlane).IToRevitCurves()), true);
                }
            }

            foreach (BH.oM.Physical.Elements.IOpening opening in floor.Openings)
            {
                PlanarSurface openingLocation = opening.Location as PlanarSurface;
                if (openingLocation == null)
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Conversion of a floor opening to Revit failed because its location is not a planar surface. Floor BHoM_Guid: {0}, Opening BHoM_Guid: {1}", floor.BHoM_Guid, opening.BHoM_Guid));
                    continue;
                }

                document.Create.NewOpening(revitFloor, Create.CurveArray(openingLocation.ExternalBoundary.IToRevitCurves()), true);

                if (!(opening is BH.oM.Physical.Elements.Void))
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Revit allows only void openings in floors, therefore the BHoM opening of type {0} has been converted to a void opening. Floor BHoM_Guid: {1}, Opening BHoM_Guid: {2}", opening.GetType().Name, floor.BHoM_Guid, opening.BHoM_Guid));
                }
            }

            double offset = revitFloor.LookupParameterDouble(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);

            // Copy parameters from BHoM object to Revit element
            revitFloor.CopyParameters(floor, settings);

            // Update the offset in case the level had been overwritten.
            if (revitFloor.LevelId.IntegerValue != level.Id.IntegerValue)
            {
                Level newLevel = document.GetElement(revitFloor.LevelId) as Level;
                offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length);
            }

            revitFloor.SetParameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM, offset);

            refObjects.AddOrReplace(floor, revitFloor);
            return(revitFloor);
        }