Exemplo n.º 1
0
        public static UV Evaluate(Plane plane, XYZ point)
        {
            if (!IsPointInPlane(plane, point))
            {
                point = GetProjectPoint(plane, point);
            }
            Plane  planeOx = Plane.CreateByOriginAndBasis(plane.Origin, plane.XVec, plane.Normal);
            Plane  planeOy = Plane.CreateByOriginAndBasis(plane.Origin, plane.YVec, plane.Normal);
            double lenX    = GetSignedDistance(planeOy, point);
            double lenY    = GetSignedDistance(planeOx, point);

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    double tLenX  = lenX * Math.Pow(-1, i + 1);
                    double tLenY  = lenY * Math.Pow(-1, j + 1);
                    XYZ    tPoint = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(plane.Origin, plane.XVec, tLenX), plane.YVec, tLenY);
                    if (GeomUtil.IsEqual(tPoint, point))
                    {
                        return(new UV(tLenX, tLenY));
                    }
                }
            }
            throw new Exception("Code complier should never be here!");
        }
        public void GetParameters()
        {
            Document doc  = Wall.Document;
            WallType type = Wall.WallType;

            Width = type.LookupParameter("Width").AsDouble();

            LocationCurve lc = Wall.Location as LocationCurve;
            Curve         c  = lc.Curve;

            Parameter boP = Wall.LookupParameter("Base Offset");

            c = GeomUtil.OffsetCurve(c, XYZ.BasisZ, boP.AsDouble());
            List <XYZ> ps = new List <XYZ> {
                c.GetEndPoint(0), c.GetEndPoint(1)
            };

            ps.Sort(new ZYXComparer());

            DrivingCurve = Line.CreateBound(ps[0], ps[1]);
            Length       = DrivingCurve.Length;

            Parameter uhP = Wall.LookupParameter("Unconnected Height");

            Height = uhP.AsDouble();
        }
Exemplo n.º 3
0
        public static Polygon GetPolygonFromFaceFamilyInstance(FamilyInstance fi)
        {
            GeometryElement geoElem = fi.get_Geometry(new Options {
                ComputeReferences = true
            });
            List <Curve> cs = new List <Curve>();

            foreach (GeometryObject geoObj in geoElem)
            {
                GeometryInstance geoIns = geoObj as GeometryInstance;
                if (geoIns == null)
                {
                    continue;
                }
                Transform tf = geoIns.Transform;
                foreach (GeometryObject geoSymObj in geoIns.GetSymbolGeometry())
                {
                    Curve c = geoSymObj as Line;
                    if (c != null)
                    {
                        cs.Add(GeomUtil.TransformCurve(c, tf));
                    }
                }
            }
            if (cs.Count < 3)
            {
                throw new Exception("Incorrect input curve!");
            }
            return(new Polygon(cs));
        }
Exemplo n.º 4
0
        public static XYZ GetProjectPoint(Plane plane, XYZ point)
        {
            double d = GetSignedDistance(plane, point);
            XYZ    q = GeomUtil.AddXYZ(point, GeomUtil.MultiplyVector(plane.Normal, d));

            return(IsPointInPlane(plane, q) ? q : GeomUtil.AddXYZ(point, GeomUtil.MultiplyVector(plane.Normal, -d)));
        }
Exemplo n.º 5
0
        public static XYZ Evaluate(Plane p, UV point)
        {
            XYZ pnt = p.Origin;

            pnt = GeomUtil.OffsetPoint(pnt, p.XVec, point.U);
            pnt = GeomUtil.OffsetPoint(pnt, p.YVec, point.V);
            return(pnt);
        }
Exemplo n.º 6
0
 public static Plane GetPlaneWithBasisY(PlanarFace f, XYZ vecY)
 {
     if (!GeomUtil.IsEqual(GeomUtil.DotMatrix(vecY, f.FaceNormal), 0))
     {
         throw new Exception("VecY is not perpendicular with Normal!");
     }
     return(Plane.CreateByOriginAndBasis(f.Origin, GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecY, f.FaceNormal)), vecY));
 }
Exemplo n.º 7
0
 public static double GetSignedDistance(Curve line, XYZ point)
 {
     if (IsPointInLineOrExtend(ConvertLine(line), point))
     {
         return(0);
     }
     return(GeomUtil.GetLength(point, GetProjectPoint(line, point)));
 }
        public void GetPolygonsDefineFace()
        {
            Document doc = Column.Document;
            Curve    c   = DrivingCurve;

            List <XYZ> ps = new List <XYZ> {
                c.GetEndPoint(0), c.GetEndPoint(1)
            };
            Transform tf = Column.GetTransform();

            XYZ vecX = tf.BasisX;
            XYZ vecY = tf.BasisY;
            XYZ vecZ = tf.BasisZ;

            List <XYZ> cenWidthPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecX, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecX, -Width / 2),
                GeomUtil.OffsetPoint(ps[0], vecX, Width / 2), GeomUtil.OffsetPoint(ps[1], vecX, Width / 2)
            };

            cenWidthPoints.Sort(new ZYXComparer());
            XYZ temp = cenWidthPoints[2]; cenWidthPoints[2] = cenWidthPoints[3]; cenWidthPoints[3] = temp;

            List <XYZ> cenHeightPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecY, -Height / 2), GeomUtil.OffsetPoint(ps[1], vecY, -Height / 2),
                GeomUtil.OffsetPoint(ps[0], vecY, Height / 2), GeomUtil.OffsetPoint(ps[1], vecY, Height / 2)
            };

            cenHeightPoints.Sort(new ZYXComparer());
            temp = cenHeightPoints[2]; cenHeightPoints[2] = cenHeightPoints[3]; cenHeightPoints[3] = temp;

            ps = new List <XYZ> {
                (cenHeightPoints[0] + cenHeightPoints[3]) / 2, (cenHeightPoints[1] + cenHeightPoints[2]) / 2
            };
            List <XYZ> cenHozPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecX, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecX, -Width / 2),
                GeomUtil.OffsetPoint(ps[0], vecX, Width / 2), GeomUtil.OffsetPoint(ps[1], vecX, Width / 2)
            };

            cenHozPoints.Sort(new ZYXComparer());
            temp = cenHozPoints[2]; cenHozPoints[2] = cenHozPoints[3]; cenHozPoints[3] = temp;

            CentralVerticalHeightPolygon = new Polygon(cenHeightPoints);
            CentralVerticalWidthPolygon  = new Polygon(cenWidthPoints);
            CentralHorizontalPolygon     = new Polygon(cenHozPoints);

            vecX                = GeomUtil.UnitVector(GeomUtil.IsBigger(vecX, -vecX) ? vecX : -vecX);
            vecY                = GeomUtil.UnitVector(GeomUtil.IsBigger(vecY, -vecY) ? vecY : -vecY);
            vecZ                = GeomUtil.UnitVector(GeomUtil.IsBigger(vecZ, -vecZ) ? vecZ : -vecZ);
            TopPolygon          = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, Length / 2);
            BottomPolygon       = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, -Length / 2);
            FirstHeightPolygon  = GeomUtil.OffsetPolygon(CentralVerticalHeightPolygon, vecX, -Width / 2);
            SecondHeightPolygon = GeomUtil.OffsetPolygon(CentralVerticalHeightPolygon, vecX, Width / 2);
            FirstWidthPolygon   = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecY, -Height / 2);
            SecondWidthPolygon  = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecY, Height / 2);

            this.VecX = vecX; this.VecY = vecY; this.VecZ = vecZ;
        }
Exemplo n.º 9
0
        public static XYZ GetProjectPoint(Curve line, XYZ point)
        {
            if (IsPointInLineOrExtend(CheckGeometry.ConvertLine(line), point))
            {
                return(point);
            }
            XYZ   vecL = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0));
            XYZ   vecP = GeomUtil.SubXYZ(point, line.GetEndPoint(0));
            Plane p    = Plane.CreateByOriginAndBasis(line.GetEndPoint(0), GeomUtil.UnitVector(vecL), GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecL, vecP)));

            return(GetProjectPoint(p, point));
        }
Exemplo n.º 10
0
 int IComparer <XYZ> .Compare(XYZ first, XYZ second)
 {
     if (GeomUtil.IsEqual(first.X, second.X))
     {
         if (GeomUtil.IsEqual(first.Y, second.Y))
         {
             return(0); // Equal
         }
         return((first.Y > second.Y) ? 1 : -1);
     }
     return((first.X > second.X) ? 1 : -1);
 }
Exemplo n.º 11
0
 public static bool IsPointInLineOrExtend(Line line, XYZ point)
 {
     if (GeomUtil.IsEqual(point, line.GetEndPoint(0)) || GeomUtil.IsEqual(point, line.GetEndPoint(1)))
     {
         return(true);
     }
     if (GeomUtil.IsSameOrOppositeDirection(GeomUtil.SubXYZ(point, line.GetEndPoint(0)), GeomUtil.SubXYZ(point, line.GetEndPoint(1))))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 12
0
 private void GetPositionType()
 {
     if (GeomUtil.IsSameOrOppositeDirection(polygon.Normal, multiPolygon.Normal))
     {
         if (multiPolygon.SurfacePolygon.CheckXYZPointPosition(polygon.ListXYZPoint[0]) != PointComparePolygonResult.NonPlanar)
         {
             PositionType = PolygonCompareMultiPolygonPositionType.Planar;
             return;
         }
         PositionType = PolygonCompareMultiPolygonPositionType.Parallel; return;
     }
     PositionType = PolygonCompareMultiPolygonPositionType.NonPlarnar; return;
 }
Exemplo n.º 13
0
 int IComparer <XYZ> .Compare(XYZ first, XYZ second)
 {
     // first compare z coordinate, then y coordiante, at last x coordinate
     if (GeomUtil.IsEqual(first.Z, second.Z))
     {
         if (GeomUtil.IsEqual(first.Y, second.Y))
         {
             if (GeomUtil.IsEqual(first.X, second.X))
             {
                 return(0); // Equal
             }
             return((first.X > second.X) ? 1 : -1);
         }
         return((first.Y > second.Y) ? 1 : -1);
     }
     return((first.Z > second.Z) ? 1 : -1);
 }
Exemplo n.º 14
0
        public static void CreateModelLine(Document doc, SketchPlane sp, Curve c)
        {
            if (sp != null)
            {
                doc.Create.NewModelCurve(c, sp);
                return;
            }
            if (GeomUtil.IsSameOrOppositeDirection(GetDirection(c), XYZ.BasisZ))
            {
                sp = SketchPlane.Create(doc, Plane.CreateByOriginAndBasis(c.GetEndPoint(0), XYZ.BasisZ, XYZ.BasisX));
                CreateModelLine(doc, sp, c);
                return;
            }
            XYZ vecY = GetDirection(c).CrossProduct(XYZ.BasisZ);

            sp = SketchPlane.Create(doc, Plane.CreateByOriginAndBasis(c.GetEndPoint(0), GeomUtil.UnitVector(GetDirection(c)), GeomUtil.UnitVector(vecY)));
            CreateModelLine(doc, sp, c);
            return;
        }
Exemplo n.º 15
0
        public static Polygon OffsetPolygon(Polygon polygon, double distance, bool isInside = true)
        {
            List <XYZ> points = new List <XYZ>();

            for (int i = 0; i < polygon.ListXYZPoint.Count; i++)
            {
                XYZ vec = null;
                if (i == 0)
                {
                    Curve c1 = Line.CreateBound(polygon.ListXYZPoint[polygon.ListXYZPoint.Count - 1], polygon.ListXYZPoint[i]);
                    Curve c2 = Line.CreateBound(polygon.ListXYZPoint[i], polygon.ListXYZPoint[i + 1]);

                    vec = polygon.Normal.CrossProduct(GetDirection(c1)) + polygon.Normal.CrossProduct(GetDirection(c2));
                    //vec = polygon.Normal.CrossProduct(GetDirection(c2));
                }
                else if (i == polygon.ListXYZPoint.Count - 1)
                {
                    Curve c1 = Line.CreateBound(polygon.ListXYZPoint[i - 1], polygon.ListXYZPoint[i]);
                    Curve c2 = Line.CreateBound(polygon.ListXYZPoint[i], polygon.ListXYZPoint[0]);
                    vec = polygon.Normal.CrossProduct(GetDirection(c1)) + polygon.Normal.CrossProduct(GetDirection(c2));
                    //vec = polygon.Normal.CrossProduct(GetDirection(c2));
                }
                else
                {
                    Curve c1 = Line.CreateBound(polygon.ListXYZPoint[i - 1], polygon.ListXYZPoint[i]);
                    Curve c2 = Line.CreateBound(polygon.ListXYZPoint[i], polygon.ListXYZPoint[i + 1]);
                    vec = polygon.Normal.CrossProduct(GetDirection(c1)) + polygon.Normal.CrossProduct(GetDirection(c2));
                    //vec = polygon.Normal.CrossProduct(GetDirection(c2));
                }
                XYZ temp = null;
                if (isInside)
                {
                    temp = GeomUtil.OffsetPoint(polygon.ListXYZPoint[i], vec, distance * Math.Sqrt(2));
                }
                else
                {
                    temp = GeomUtil.OffsetPoint(polygon.ListXYZPoint[i], -vec, distance * Math.Sqrt(2));
                }
                //temp = (polygon.CheckXYZPointPosition(temp) == PointComparePolygonResult.Inside) ? temp : GeomUtil.OffsetPoint(polygon.ListXYZPoint[i], -vec, distance);
                points.Add(temp);
            }
            return(new Polygon(points));
        }
Exemplo n.º 16
0
        public static PointComparePolygonResult PointComparePolygon(UV p, List <UV> polygon)
        {
            bool check1 = IsPointInPolygon(p, polygon);

            for (int i = 0; i < polygon.Count; i++)
            {
                if (GeomUtil.IsEqual(p, polygon[i]))
                {
                    return(PointComparePolygonResult.Node);
                }

                UV vec1 = GeomUtil.SubXYZ(p, polygon[i]);
                UV vec2 = null;
                if (i != polygon.Count - 1)
                {
                    if (GeomUtil.IsEqual(p, polygon[i + 1]))
                    {
                        continue;
                    }
                    vec2 = GeomUtil.SubXYZ(p, polygon[i + 1]);
                }
                else
                {
                    if (GeomUtil.IsEqual(p, polygon[0]))
                    {
                        continue;
                    }
                    vec2 = GeomUtil.SubXYZ(p, polygon[0]);
                }
                if (GeomUtil.IsOppositeDirection(vec1, vec2))
                {
                    return(PointComparePolygonResult.Boundary);
                }
            }
            if (check1)
            {
                return(PointComparePolygonResult.Inside);
            }
            return(PointComparePolygonResult.Outside);
        }
Exemplo n.º 17
0
        public static View CreateFloorCallout(Document doc, List <View> views, string level, BoundingBoxXYZ bb, string viewName, double offset)
        {
            ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                 .Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.FloorPlan == x.ViewFamily);
            XYZ max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(bb.Max, XYZ.BasisX, offset), XYZ.BasisY, offset), XYZ.BasisZ, offset);
            XYZ min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(bb.Min, -XYZ.BasisX, offset), -XYZ.BasisY, offset), -XYZ.BasisZ, offset);

            bb = new BoundingBoxXYZ {
                Max = max, Min = min
            };
            View   pv    = null;
            string s     = string.Empty;
            bool   check = false;

            foreach (View v in views)
            {
                try
                {
                    s = v.LookupParameter("Associated Level").AsString();
                    if (s == level)
                    {
                        pv = v; check = true; break;
                    }
                }
                catch
                {
                    continue;
                }
            }
            if (!check)
            {
                throw new Exception("Invalid level name!");
            }
            View vs = ViewSection.CreateCallout(doc, pv.Id, vft.Id, min, max);

            vs.CropBox = bb;
            vs.Name    = viewName;
            return(vs);
        }
Exemplo n.º 18
0
        public static RebarHookOrientation GetHookOrient(Autodesk.Revit.DB.XYZ curveVec, Autodesk.Revit.DB.XYZ normal, Autodesk.Revit.DB.XYZ hookVec)
        {
            Autodesk.Revit.DB.XYZ tempVec = normal;

            for (int i = 0; i < 4; i++)
            {
                tempVec = GeomUtil.CrossMatrix(tempVec, curveVec);
                if (GeomUtil.IsSameDirection(tempVec, hookVec))
                {
                    if (i == 0)
                    {
                        return(RebarHookOrientation.Right);
                    }
                    else if (i == 2)
                    {
                        return(RebarHookOrientation.Left);
                    }
                }
            }

            throw new Exception("Can't find the hook orient according to hook direction.");
        }
Exemplo n.º 19
0
        int IComparer <Element> .Compare(Element x, Element y)
        {
            XYZ loc1 = null;
            XYZ loc2 = null;

            if (x is Wall)
            {
                WallGeometryInfo wgi = new WallGeometryInfo(x as Wall); loc1 = wgi.TopPolygon.CentralXYZPoint;
            }
            if (x is FamilyInstance)
            {
                ColumnGeometryInfo cgi = new ColumnGeometryInfo(x as FamilyInstance); loc1 = cgi.TopPolygon.CentralXYZPoint;
            }
            if (y is Wall)
            {
                WallGeometryInfo wgi = new WallGeometryInfo(y as Wall); loc2 = wgi.TopPolygon.CentralXYZPoint;
            }
            if (y is FamilyInstance)
            {
                ColumnGeometryInfo cgi = new ColumnGeometryInfo(y as FamilyInstance); loc2 = cgi.TopPolygon.CentralXYZPoint;
            }
            loc1 = new XYZ(loc1.X, loc1.Y, 0); loc2 = new XYZ(loc2.X, loc2.Y, 0);
            if (Plane != null)
            {
                loc1 = CheckGeometry.GetProjectPoint(Plane, loc1); loc2 = CheckGeometry.GetProjectPoint(Plane, loc2);
            }

            if (GeomUtil.IsEqual(loc1.X, loc2.X))
            {
                if (GeomUtil.IsEqual(loc1.Y, loc2.Y))
                {
                    return(0); // Equal
                }
                return((loc1.Y > loc2.Y) ? 1 : -1);
            }
            return((loc1.X > loc2.X) ? 1 : -1);
        }
Exemplo n.º 20
0
 public static bool IsPointInPlane(Plane plane, XYZ point)
 {
     return(GeomUtil.IsEqual(GetSignedDistance(plane, point), 0) ? true : false);
 }
Exemplo n.º 21
0
        public static ViewSection CreateWallSection(Document linkedDoc, Document doc, Polygon directPolygon, ElementId id, string viewName, double offset)
        {
            Element e = linkedDoc.GetElement(id);

            if (!(e is Wall))
            {
                throw new Exception("Element is not a wall!");
            }
            Wall wall = (Wall)e;
            Line line = (wall.Location as LocationCurve).Curve as Line;

            ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily);

            XYZ        p1 = line.GetEndPoint(0), p2 = line.GetEndPoint(1);
            List <XYZ> ps = new List <XYZ> {
                p1, p2
            }; ps.Sort(new ZYXComparer());

            p1 = ps[0]; p2 = ps[1];

            BoundingBoxXYZ bb = wall.get_BoundingBox(null);
            double         minZ = bb.Min.Z, maxZ = bb.Max.Z;

            double l = GeomUtil.GetLength(GeomUtil.SubXYZ(p2, p1));
            double h = maxZ - minZ;
            double w = wall.WallType.Width;

            XYZ tfMin = new XYZ(-l / 2 - offset, minZ - offset, -w - offset);
            XYZ tfMax = new XYZ(l / 2 + offset, maxZ + offset, w + offset);

            XYZ wallDir = GeomUtil.UnitVector(p2 - p1);
            XYZ upDir   = XYZ.BasisZ;
            XYZ viewDir = GeomUtil.CrossMatrix(wallDir, upDir);

            XYZ midPoint  = (p1 + p2) / 2;
            XYZ pMidPoint = GetProjectPoint(directPolygon.Plane, midPoint);

            XYZ pPnt = GeomUtil.OffsetPoint(pMidPoint, viewDir, w * 10);

            if (GeomUtil.IsBigger(GeomUtil.GetLength(pMidPoint, directPolygon.CentralXYZPoint), GeomUtil.GetLength(pPnt, directPolygon.CentralXYZPoint)))
            {
                wallDir = -wallDir;
                upDir   = XYZ.BasisZ;
                viewDir = GeomUtil.CrossMatrix(wallDir, upDir);
            }
            else
            {
            }

            pPnt = GeomUtil.OffsetPoint(p1, wallDir, offset);
            XYZ min = null, max = null;

            if (GeomUtil.IsBigger(GeomUtil.GetLength(GeomUtil.SubXYZ(pPnt, midPoint)), GeomUtil.GetLength(GeomUtil.SubXYZ(p1, midPoint))))
            {
                min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, wallDir, offset), -viewDir, offset);
                max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, -wallDir, offset), viewDir, offset);
            }
            else
            {
                min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, -wallDir, offset), -viewDir, offset);
                max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, wallDir, offset), viewDir, offset);
            }
            min = new XYZ(min.X, min.Y, minZ - offset);
            max = new XYZ(max.X, max.Y, maxZ + offset);

            Transform tf = Transform.Identity;

            tf.Origin = (p1 + p2) / 2;
            tf.BasisX = wallDir;
            tf.BasisY = XYZ.BasisZ;
            tf.BasisZ = GeomUtil.CrossMatrix(wallDir, upDir);

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ()
            {
                Transform = tf, Min = tfMin, Max = tfMax
            };
            ViewSection vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);

            tf  = vs.get_BoundingBox(null).Transform.Inverse;
            max = tf.OfPoint(max);
            min = tf.OfPoint(min);
            double maxx = 0, maxy = 0, maxz = 0, minx = 0, miny = 0, minz = 0;

            if (max.Z > min.Z)
            {
                maxz = max.Z;
                minz = min.Z;
            }
            else
            {
                maxz = min.Z;
                minz = max.Z;
            }


            if (Math.Round(max.X, 4) == Math.Round(min.X, 4))
            {
                maxx = max.X;
                minx = minz;
            }
            else if (max.X > min.X)
            {
                maxx = max.X;
                minx = min.X;
            }

            else
            {
                maxx = min.X;
                minx = max.X;
            }

            if (Math.Round(max.Y, 4) == Math.Round(min.Y, 4))
            {
                maxy = max.Y;
                miny = minz;
            }
            else if (max.Y > min.Y)
            {
                maxy = max.Y;
                miny = min.Y;
            }

            else
            {
                maxy = min.Y;
                miny = max.Y;
            }

            BoundingBoxXYZ sectionView = new BoundingBoxXYZ();

            sectionView.Max = new XYZ(maxx, maxy, maxz);
            sectionView.Min = new XYZ(minx, miny, minz);

            vs.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(ElementId.InvalidElementId);

            vs.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(0);

            vs.CropBoxActive  = true;
            vs.CropBoxVisible = true;

            doc.Regenerate();

            vs.CropBox = sectionView;
            vs.Name    = viewName;
            return(vs);
        }
Exemplo n.º 22
0
 public static XYZ GetDirection(Curve c)
 {
     return(GeomUtil.UnitVector(GeomUtil.SubXYZ(c.GetEndPoint(1), c.GetEndPoint(0))));
 }
Exemplo n.º 23
0
        public static bool CreateListPolygon(List <Curve> listCurve, out List <Polygon> pls)
        {
            pls = new List <Polygon>();
            foreach (Curve c in listCurve)
            {
                List <Curve> cs = new List <Curve>();
                cs.Add(Line.CreateBound(c.GetEndPoint(0), c.GetEndPoint(1)));
                int i = 0; bool check = true;
                while (!GeomUtil.IsEqual(cs[0].GetEndPoint(0), cs[cs.Count - 1].GetEndPoint(1)))
                {
                    i++;
                    foreach (Curve c1 in listCurve)
                    {
                        XYZ pnt    = cs[cs.Count - 1].GetEndPoint(1);
                        XYZ prePnt = cs[cs.Count - 1].GetEndPoint(0);
                        if (GeomUtil.IsEqual(pnt, c1.GetEndPoint(0)))
                        {
                            if (GeomUtil.IsEqual(prePnt, c1.GetEndPoint(1)))
                            {
                                continue;
                            }
                            cs.Add(Line.CreateBound(c1.GetEndPoint(0), c1.GetEndPoint(1)));
                            break;
                        }
                        else if (GeomUtil.IsEqual(pnt, c1.GetEndPoint(1)))
                        {
                            if (GeomUtil.IsEqual(prePnt, c1.GetEndPoint(0)))
                            {
                                continue;
                            }
                            cs.Add(Line.CreateBound(c1.GetEndPoint(1), c1.GetEndPoint(0)));
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (i == 200)
                    {
                        check = false; break;
                    }
                }
                if (check)
                {
                    Polygon plgon = new Polygon(cs);

                    if (pls.Count == 0)
                    {
                        pls.Add(plgon);
                    }
                    else
                    {
                        check = true;
                        foreach (Polygon pl in pls)
                        {
                            if (pl == plgon)
                            {
                                check = false; break;
                            }
                        }
                        if (check)
                        {
                            pls.Add(plgon);
                        }
                    }
                }
            }
            if (pls.Count == 0)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 24
0
        public static double GetSignedDistance(Plane plane, XYZ point)
        {
            XYZ v = point - plane.Origin;

            return(Math.Abs(GeomUtil.DotMatrix(plane.Normal, v)));
        }
        public void GetPolygonsDefineFace()
        {
            LocationCurve lc = Beam.Location as LocationCurve;
            Curve         c  = lc.Curve;

            Length = c.Length;

            List <XYZ> ps = new List <XYZ> {
                c.GetEndPoint(0), c.GetEndPoint(1)
            };

            Parameter zJP  = Beam.LookupParameter("z Justification");
            Parameter zOP  = Beam.LookupParameter("z Offset Value");
            Parameter yJP  = Beam.LookupParameter("y Justification");
            Parameter yOP  = Beam.LookupParameter("y Offset Value");
            XYZ       vecX = ps[1] - ps[0];
            XYZ       vecY = XYZ.BasisZ.CrossProduct(vecX);

            int    zJ = zJP.AsInteger();
            double zO = zOP.AsDouble();

            switch (zJ)
            {
            case 0:
                ps[0] = GeomUtil.OffsetPoint(ps[0], XYZ.BasisZ, zO - Height / 2);
                ps[1] = GeomUtil.OffsetPoint(ps[1], XYZ.BasisZ, zO - Height / 2);
                break;

            case 1:
            case 2:
                ps[0] = GeomUtil.OffsetPoint(ps[0], XYZ.BasisZ, zO);
                ps[1] = GeomUtil.OffsetPoint(ps[1], XYZ.BasisZ, zO);
                break;

            case 3:
                ps[0] = GeomUtil.OffsetPoint(ps[0], XYZ.BasisZ, zO + Height / 2);
                ps[1] = GeomUtil.OffsetPoint(ps[1], XYZ.BasisZ, zO + Height / 2);
                break;
            }

            int    yJ = yJP.AsInteger();
            double yO = yOP.AsDouble();

            switch (yJ)
            {
            case 0:
                ps[0] = GeomUtil.OffsetPoint(ps[0], vecY, yO - Width / 2);
                ps[1] = GeomUtil.OffsetPoint(ps[1], vecY, yO - Width / 2);
                break;

            case 1:
            case 2:
                ps[0] = GeomUtil.OffsetPoint(ps[0], vecY, yO);
                ps[1] = GeomUtil.OffsetPoint(ps[1], vecY, yO);
                break;

            case 3:
                ps[0] = GeomUtil.OffsetPoint(ps[0], vecY, yO + Width / 2);
                ps[1] = GeomUtil.OffsetPoint(ps[1], vecY, yO + Width / 2);
                break;
            }

            ps.Sort(new ZYXComparer());
            List <XYZ> ps2 = new List <XYZ>()
            {
                ps[0], ps[1]
            }; ps2.Sort(new XYComparer());

            DrivingCurve = Line.CreateBound(ps2[0], ps2[1]);

            List <XYZ> cenVerPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], XYZ.BasisZ, -Height / 2), GeomUtil.OffsetPoint(ps[1], XYZ.BasisZ, -Height / 2),
                GeomUtil.OffsetPoint(ps[0], XYZ.BasisZ, Height / 2), GeomUtil.OffsetPoint(ps[1], XYZ.BasisZ, Height / 2)
            };

            cenVerPoints.Sort(new ZYXComparer());
            XYZ temp = cenVerPoints[2]; cenVerPoints[2] = cenVerPoints[3]; cenVerPoints[3] = temp;

            List <XYZ> cenHozPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecY, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, -Width / 2),
                GeomUtil.OffsetPoint(ps[0], vecY, Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, Width / 2)
            };

            cenHozPoints.Sort(new ZYXComparer());
            temp = cenHozPoints[2]; cenHozPoints[2] = cenHozPoints[3]; cenHozPoints[3] = temp;

            ps = new List <XYZ> {
                (cenVerPoints[0] + cenVerPoints[1]) / 2, (cenVerPoints[2] + cenVerPoints[3]) / 2
            };
            List <XYZ> cenSecPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecY, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, -Width / 2),
                GeomUtil.OffsetPoint(ps[0], vecY, Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, Width / 2)
            };

            cenSecPoints.Sort(new ZYXComparer());
            temp = cenSecPoints[2]; cenSecPoints[2] = cenSecPoints[3]; cenSecPoints[3] = temp;

            CentralHorizontalPolygon      = new Polygon(cenHozPoints);
            CentralVerticalLengthPolygon  = new Polygon(cenVerPoints);
            CentralVerticalSectionPolygon = new Polygon(cenSecPoints);

            vecX                 = GeomUtil.UnitVector(GeomUtil.IsBigger(vecX, -vecX) ? vecX : -vecX);
            vecY                 = GeomUtil.UnitVector(GeomUtil.IsBigger(vecY, -vecY) ? vecY : -vecY);
            TopPolygon           = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, XYZ.BasisZ, Height / 2);
            BottomPolygon        = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, XYZ.BasisZ, -Height / 2);
            FirstLengthPolygon   = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, -Width / 2);
            SecondLengthPolygon  = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, Width / 2);
            FirstSectionPolygon  = GeomUtil.OffsetPolygon(CentralVerticalSectionPolygon, vecX, -Length / 2);
            SecondSectionPolygon = GeomUtil.OffsetPolygon(CentralVerticalSectionPolygon, vecX, Length / 2);

            VecX = vecX; VecY = vecY; VecZ = XYZ.BasisZ;
        }
        public void GetPolygonsDefineFace()
        {
            Document doc = Wall.Document;
            Curve    c   = DrivingCurve;

            XYZ vecX = CheckGeometry.GetDirection(c);
            XYZ vecZ = XYZ.BasisZ;
            XYZ vecY = vecZ.CrossProduct(vecX);

            List <XYZ> ps = new List <XYZ> {
                c.GetEndPoint(0), c.GetEndPoint(1)
            };

            List <XYZ> cenLengthPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecZ, 0), GeomUtil.OffsetPoint(ps[1], vecZ, 0),
                GeomUtil.OffsetPoint(ps[0], vecZ, Height), GeomUtil.OffsetPoint(ps[1], vecZ, Height)
            };

            cenLengthPoints.Sort(new ZYXComparer());
            XYZ temp = cenLengthPoints[2]; cenLengthPoints[2] = cenLengthPoints[3]; cenLengthPoints[3] = temp;

            XYZ midPoint = (ps[0] + ps[1]) / 2;

            ps = new List <XYZ> {
                GeomUtil.OffsetPoint(midPoint, vecY, -Width / 2), GeomUtil.OffsetPoint(midPoint, vecY, Width / 2)
            };
            List <XYZ> cenWidthPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecZ, 0), GeomUtil.OffsetPoint(ps[1], vecZ, 0),
                GeomUtil.OffsetPoint(ps[0], vecZ, Height), GeomUtil.OffsetPoint(ps[1], vecZ, Height)
            };

            cenWidthPoints.Sort(new ZYXComparer());
            temp = cenWidthPoints[2]; cenWidthPoints[2] = cenWidthPoints[3]; cenWidthPoints[3] = temp;

            ps = new List <XYZ> {
                (cenLengthPoints[0] + cenLengthPoints[3]) / 2, (cenLengthPoints[1] + cenLengthPoints[2]) / 2
            };
            List <XYZ> cenHozPoints = new List <XYZ> {
                GeomUtil.OffsetPoint(ps[0], vecY, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, -Width / 2),
                GeomUtil.OffsetPoint(ps[0], vecY, Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, Width / 2)
            };

            cenHozPoints.Sort(new ZYXComparer());
            temp = cenHozPoints[2]; cenHozPoints[2] = cenHozPoints[3]; cenHozPoints[3] = temp;

            CentralVerticalLengthPolygon = new Polygon(cenLengthPoints);
            CentralVerticalWidthPolygon  = new Polygon(cenWidthPoints);
            CentralHorizontalPolygon     = new Polygon(cenHozPoints);

            vecX = GeomUtil.UnitVector(GeomUtil.IsBigger(vecX, -vecX) ? vecX : -vecX);
            vecY = GeomUtil.UnitVector(GeomUtil.IsBigger(vecY, -vecY) ? vecY : -vecY);
            vecZ = GeomUtil.UnitVector(GeomUtil.IsBigger(vecZ, -vecZ) ? vecZ : -vecZ);

            TopPolygon          = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, Height / 2);
            BottomPolygon       = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, -Height / 2);
            FirstLengthPolygon  = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, -Width / 2);
            SecondLengthPolygon = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, Width / 2);
            FirstWidthPolygon   = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecX, -Length / 2);
            SecondWidthPolygon  = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecX, Length / 2);

            this.VecX = vecX; this.VecY = vecY; this.VecZ = vecZ;
        }