Example #1
0
        static public Curve GetFamilyInstanceCutBaseLine(FamilyInstance fi)
        {
            XYZ       dir;
            CurveLoop loop  = ExporterIFCUtils.GetInstanceCutoutFromWall(fi.Document, fi.Host as Wall, fi, out dir);
            Curve     curve = loop.Where(x => x.GetEndPoint(0).Z == x.GetEndPoint(1).Z).OrderBy(x => x.GetEndPoint(0).Z).FirstOrDefault();

            return(curve);
        }
Example #2
0
        public PointLocation IsPointInside(XYZ point)
        {
            // Check if the point is outside of the loop bounding box
            if (point.X - Epsilon < MinX ||
                point.X + Epsilon > MaxX ||
                point.Y - Epsilon < MinY ||
                point.Y + Epsilon > MaxY)
            {
                return(PointLocation.Outside);
            }

            // Check if the point is on the loop
            if (_loop2d.Any(curve => curve.Distance(point) < Epsilon))
            {
                return(PointLocation.OnTheEdge);
            }

            // Create a Line that starts from point and ends outside of the loop. Adding non-integer
            // values decreases the chances of special cases, where line passes through loop
            // endpoints. These cases can still happen and are managed by the function, but using a
            // different offset costs nothing and may help staying out of trouble. (The trouble
            // could show up when a point doesn't really lay on a line, or two points are not exactly
            // the identical. Using Epsilon helps a little, but, again, when the distance between two
            // points is exactly Epsilon, here comes the trouble.)
            var line = Line.CreateBound(point, new XYZ(MaxX + 0.1234, MaxY + 0.3456, 0));

            // Count the number of intersections between the line just created and the loop.
            // If the number of intersection is odd, then point is inside the loop.
            // Discard the solutions where the intersection is the edge start point, because these
            // intersections have already been counted when intersecting the end point of the
            // previous segments.
            var nIntersections = _loop2d
                                 .Where(edge => edge.Intersect(line) == SetComparisonResult.Overlap)
                                 .Count(edge => line.Distance(edge.GetEndPoint(0)) > Epsilon);

            return(nIntersections % 2 == 1 ? PointLocation.Inside : PointLocation.Outside);
        }
Example #3
0
        static private void GetOpeningSize(Wall elHost, Element elInsert, out double width, out double height, out double thickness)
        {
            width     = 0;
            height    = 0;
            thickness = elHost.Width;
            if (elInsert is FamilyInstance)
            {
                FamilyInstance fi  = elInsert as FamilyInstance;
                XYZ            dir = new XYZ();
                try
                {
                    CurveLoop curve       = ExporterIFCUtils.GetInstanceCutoutFromWall(elHost.Document, elHost, fi, out dir);
                    Curve     widthCurve  = curve.Where(x => x.GetEndPoint(0).Z == x.GetEndPoint(1).Z).FirstOrDefault();
                    Curve     heightCurve = curve.Where(x => x.GetEndPoint(0).X == x.GetEndPoint(1).X&& x.GetEndPoint(0).Z != x.GetEndPoint(1).Z).FirstOrDefault();
                    width  = widthCurve != null ? widthCurve.Length : 0;
                    height = heightCurve != null ? heightCurve.Length : 0;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    Parameter wp  = fi.LookupParameter("Ширина");
                    Parameter wpp = fi.LookupParameter("Примерная ширина");
                    Parameter hp  = fi.LookupParameter("Высота");
                    Parameter hpp = fi.LookupParameter("Примерная высота");

                    if (wp != null)
                    {
                        width = wp.AsDouble();
                    }
                    else if (wpp != null)
                    {
                        width = wpp.AsDouble();
                    }
                    else
                    {
                        width = 0;
                    }

                    if (hp != null)
                    {
                        height = hp.AsDouble();
                    }
                    else if (hpp != null)
                    {
                        height = hpp.AsDouble();
                    }
                    else
                    {
                        height = 0;
                    }
                }
            }
            else if (elInsert is Wall)
            {
                var hIns  = elInsert.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                var hHost = elHost.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                var l     = elInsert.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();

                if (hIns < hHost)
                {
                    width  = l;
                    height = hIns;
                }
                else
                {
                    width  = l;
                    height = hHost;
                }
            }
            else if (elInsert is Opening)
            {
                XYZ min = (elInsert as Opening).BoundaryRect[0];
                XYZ max = (elInsert as Opening).BoundaryRect[1];

                width  = min.X != max.X ? Math.Abs(max.X - min.X) : Math.Abs(max.Y - min.Y);
                height = Math.Abs(max.Z - min.Z);
            }
        }