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;
        }
        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;
        }
Ejemplo n.º 4
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);
        }