Ejemplo n.º 1
0
        /// <summary>
        /// Nhận vào 2 tham số, trả về null khi tạo 4 mặt đứng bằng instance thuộc lớp ElevationMarker
        /// </summary>
        /// <param name="uiDoc"></param>
        /// <param name="myRoom"></param>
        private void createElevationByRoom(UIDocument uiDoc, Room myRoom)
        {
            // Set active document
            Document doc = uiDoc.Document;

            List <ViewSection> myListViewSecton = new List <ViewSection>();

            ElevationMarker myELM = null;

            BoundingBoxXYZ myRoomBB = null;

            XYZ minPointBB = null;
            XYZ maxPointBB = null;

            XYZ minPointBb = null;

            XYZ OriginPoint2 = null;

            double minY = myRoom.Level.Elevation - 1;                           // offset - 1
            double maxY = myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1; //offset + 1

            using (Transaction trans0 = new Transaction(doc, "add elevation"))
            {
                // Start Transaction
                trans0.Start();

                // Get parameter of room
                double myLevel = myRoom.Level.Elevation;

                // Get BoundingBoxXYZ of the room.
                myRoomBB = myRoom.get_BoundingBox(null);

                maxPointBB = myRoomBB.Max;
                minPointBB = myRoomBB.Min;

                //Set Origin View Point as rooms Location Point
                LocationPoint lcPointRoom = myRoom.Location as LocationPoint;
                XYZ           originPoint = lcPointRoom.Point;

                // Get Center Point of room to make reference Point of views
                OriginPoint2 = new XYZ((maxPointBB.X + minPointBB.X) / 2, (maxPointBB.Y + minPointBB.Y) / 2, originPoint.Z);

                // second parameter in contructor ElevationMarker
                ViewFamilyType vft = new FilteredElementCollector(doc)
                                     .OfClass(typeof(ViewFamilyType))
                                     .Cast <ViewFamilyType>()
                                     .FirstOrDefault <ViewFamilyType>(x =>
                                                                      ViewFamily.Elevation == x.ViewFamily);

                ElementId myEleId = vft.Id;


                // Create 1 ElevationMaker with scale = 1:40, type View = Elevation
                myELM = ElevationMarker.CreateElevationMarker(doc, myEleId, originPoint, 40);

                // Set max and Min Elevation of View (axis Y of Section Views), offset = 1 feet;


                // Commit 1
                trans0.Commit();
            }

            string roomsName = myRoom.Name.ToString();

            for (int i = 0; i < 4; i++)

            {
                #region section0

                if (i == 0)
                {
                    using (Transaction trans1 = new Transaction(doc, "create sec 0"))
                    {
                        trans1.Start();


                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);


                        //string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                        elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();

                        elevationView.CropBoxActive = true;

                        elevationView.DisplayStyle = DisplayStyle.Realistic;

                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);


                        // Case 1: LeftView
                        myCrop.Min            = new XYZ(myRoomBB.Min.Y - 1, minY, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myRoomBB.Max.Y + 1, maxY, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans1.Commit();
                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }

                #endregion


                #region section1
                else if (i == 1)
                {
                    using (Transaction trans2 = new Transaction(doc, "create sec 1"))
                    {
                        trans2.Start();

                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);


                        //string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                        elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();

                        elevationView.CropBoxActive = true;

                        elevationView.DisplayStyle = DisplayStyle.Realistic;

                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);

                        //Case 2: Above View
                        myCrop.Min = new XYZ(myRoomBB.Min.X - 1, minY, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myRoomBB.Max.X + 1, maxY, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style	for View
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans2.Commit();
                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }

                #endregion


                #region section2
                else if (i == 2)
                {
                    using (Transaction trans3 = new Transaction(doc, "create sec 2"))
                    {
                        trans3.Start();


                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);


                        //string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                        elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();

                        elevationView.CropBoxActive = true;

                        elevationView.DisplayStyle = DisplayStyle.Realistic;

                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);


                        //
                        double XMin = -(Math.Abs(maxPointBB.Y - minPointBB.Y) / 2) - 1;
                        double XMax = +(Math.Abs(maxPointBB.Y - minPointBB.Y) / 2) + 1;

                        myCrop.Min = new XYZ(XMin - OriginPoint2.Y, minY, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myCrop.Min.X + myRoomBB.Max.Y - myRoomBB.Min.Y + 2, maxY, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans3.Commit();


                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }

                #endregion


                #region section3


                else
                {
                    using (Transaction trans4 = new Transaction(doc, "create sec 3"))
                    {
                        trans4.Start();

                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);


                        //string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                        elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();

                        elevationView.CropBoxActive = true;

                        elevationView.DisplayStyle = DisplayStyle.Realistic;

                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);



                        myCrop.Min            = new XYZ(myRoomBB.Min.X - 1 - 2 * (OriginPoint2.X), minY, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myCrop.Min.X + myRoomBB.Max.X - myRoomBB.Min.X + 2, maxY, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans4.Commit();

                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }
                #endregion
            }

            #region change setting graphic
            foreach (ViewSection mySec in myListViewSecton)
            {
                setStyleCropBoxFromView(uiDoc, mySec);
            }
            #endregion
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private void createElevationByRoom2(Room myRoom)
        {
            // Set active document
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            // List View Section

            List <ViewSection> myListViewSecton = new List <ViewSection>();

            ElevationMarker myELM = null;

            BoundingBoxXYZ myRoomBB = null;

            XYZ minPointBB = null;
            XYZ maxPointBB = null;

            XYZ minPointBb = null;

            XYZ OriginPoint2 = null;

//			XYZ OriginPoint = null;


            using (Transaction trans0 = new Transaction(doc, "Create a new Elevation Marker"))
            {
                trans0.Start();
                // Show parameter of picked room

                BoundingBoxXYZ roomBounding = myRoom.get_BoundingBox(null);

                minPointBb = roomBounding.Min;

                // Get parameter of room
                double myLevel = myRoom.Level.Elevation;
                myRoomBB = myRoom.get_BoundingBox(null);

                maxPointBB = myRoomBB.Max;
                minPointBB = myRoomBB.Min;

                LocationPoint lcPointRoom = myRoom.Location as LocationPoint;

                XYZ originPoint = lcPointRoom.Point;

                OriginPoint2 = new XYZ((maxPointBB.X + minPointBb.X) / 2, (maxPointBB.Y + minPointBb.Y) / 2, originPoint.Z);

                // second parameter in contructor ElevationMarker
                ViewFamilyType vft = new FilteredElementCollector(doc)
                                     .OfClass(typeof(ViewFamilyType))
                                     .Cast <ViewFamilyType>()
                                     .FirstOrDefault <ViewFamilyType>(x =>
                                                                      ViewFamily.Elevation == x.ViewFamily);

                ElementId myEleId = vft.Id;



                // Tao 1 ElevationMaker
                myELM = ElevationMarker.CreateElevationMarker(doc, myEleId, originPoint, 40);



                myRoomBB.Min = new XYZ(myRoomBB.Min.X, myRoomBB.Min.Y, myRoom.Level.Elevation);
                myRoomBB.Max = new XYZ(myRoomBB.Max.X, myRoomBB.Max.Y, myRoom.Level.Elevation + 1);
                trans0.Commit();
            }

//			string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);
            string roomsName = myRoom.Name.ToString();

            for (int i = 0; i < 4; i++)

            {
                if (i == 0)
                {
                    using (Transaction trans1 = new Transaction(doc, "create sec 0"))
                    {
                        trans1.Start();

                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);
                        elevationView.Name          = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();
                        elevationView.CropBoxActive = true;
                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);

                        myCrop.Min            = new XYZ(myRoomBB.Min.Y - 1, myRoom.Level.Elevation - 1, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myRoomBB.Max.Y + 1, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans1.Commit();

                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }
                else if (i == 1)
                {
                    using (Transaction trans2 = new Transaction(doc, "create sec 1"))
                    {
                        trans2.Start();
                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);
                        elevationView.Name          = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();
                        elevationView.CropBoxActive = true;
                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);

                        myCrop.Min = new XYZ(myRoomBB.Min.X - 1, myRoom.Level.Elevation - 1, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myRoomBB.Max.X + 1, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans2.Commit();

                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }

                // mai xu li
                else if (i == 2)
                {
                    using (Transaction trans3 = new Transaction(doc, "create sec 2"))
                    {
                        trans3.Start();
                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);
                        elevationView.Name          = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();
                        elevationView.CropBoxActive = true;
                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);


                        double XMin = -(Math.Abs(maxPointBB.Y - minPointBb.Y) / 2) - 1;
                        double XMax = +(Math.Abs(maxPointBB.Y - minPointBb.Y) / 2) + 1;

                        myCrop.Min = new XYZ(XMin - OriginPoint2.Y, myRoom.Level.Elevation - 1, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myCrop.Min.X + myRoomBB.Max.Y - myRoomBB.Min.Y + 2, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1, myCrop.Max.Z);

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;


                        elevationView.CropBox = myCrop;

                        trans3.Commit();

                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }

                else
                {
                    using (Transaction trans4 = new Transaction(doc, "create sec 3"))
                    {
                        trans4.Start();
                        ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);
                        elevationView.Name          = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();
                        elevationView.CropBoxActive = true;
                        BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);

                        myCrop.Min            = new XYZ(myRoomBB.Min.X - 1 - 2 * (OriginPoint2.X), myRoom.Level.Elevation - 1, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myCrop.Min.X + myRoomBB.Max.X - myRoomBB.Min.X + 2, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;

                        trans4.Commit();

                        //add View to List View
                        myListViewSecton.Add(elevationView);
                    }
                }
            }
//			TaskDialog.Show("abc", "my List view create: " + myListViewSecton.Count().ToString());

            foreach (ViewSection mySec in myListViewSecton)
            {
//				using (Transaction trans11 = new Transaction(doc, "Chang style for cropBox"))
//				{
//					trans11.Start();

                setStyleCropBoxFromView(mySec);

//					trans11.Commit();

//				}
            }
        }
Ejemplo n.º 4
0
        private void createElevationByRoom(Room myRoom)
        {
            // Set active document
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            // List View Section

//			List<ViewSection> myListViewSecton = null;

            using (Transaction trans = new Transaction(doc, "add elevation"))
            {
                trans.Start();

                // Show parameter of picked room

                BoundingBoxXYZ roomBounding = myRoom.get_BoundingBox(null);

                XYZ minPointBb = roomBounding.Min;


//				TaskDialog.Show("Min point", Math.Round(minPointBb.X,0).ToString() + "," + Math.Round(minPointBb.Y,0).ToString()+"," + minPointBb.Z.ToString());
//				TaskDialog.Show("Max point", Math.Round(minPointBb.X,0).ToString() + "," + Math.Round(minPointBb.Y,0).ToString()+"," + minPointBb.Z.ToString());

                // Get parameter of room
                double         myLevel  = myRoom.Level.Elevation;
                BoundingBoxXYZ myRoomBB = myRoom.get_BoundingBox(null);

                XYZ maxPointBB = myRoomBB.Max;
                XYZ minPointBB = myRoomBB.Min;



//				TaskDialog.Show("abc","Level: " + myLevel.ToString() + "Min: " + minPointBB.ToString());

                LocationPoint lcPointRoom = myRoom.Location as LocationPoint;

                XYZ originPoint = lcPointRoom.Point;

                XYZ OriginPoint2 = new XYZ((maxPointBB.X + minPointBb.X) / 2, (maxPointBB.Y + minPointBb.Y) / 2, originPoint.Z);

                // second parameter in contructor ElevationMarker
                ViewFamilyType vft = new FilteredElementCollector(doc)
                                     .OfClass(typeof(ViewFamilyType))
                                     .Cast <ViewFamilyType>()
                                     .FirstOrDefault <ViewFamilyType>(x =>
                                                                      ViewFamily.Elevation == x.ViewFamily);

                ElementId myEleId = vft.Id;


                // Tao 1 ElevationMaker
                ElevationMarker myELM = ElevationMarker.CreateElevationMarker(doc, myEleId, originPoint, 40);


                myRoomBB.Min = new XYZ(myRoomBB.Min.X, myRoomBB.Min.Y, myRoom.Level.Elevation);
                myRoomBB.Max = new XYZ(myRoomBB.Max.X, myRoomBB.Max.Y, myRoom.Level.Elevation + 1);

//				TaskDialog.Show("Abc", myRoom.Level.Elevation.ToString());

                for (int i = 0; i < 4; i++)

                {
                    ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);

                    string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                    elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();
//					TaskDialog.Show("abc", myELM.Name.ToString());
                    elevationView.CropBoxActive = true;

                    // Set style
//					setStyleCropBoxFromView(elevationView);

                    BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);
                    if (i == 0)
                    {
                        myCrop.Min            = new XYZ(myRoomBB.Min.Y - 1, myRoom.Level.Elevation - 0.5, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myRoomBB.Max.Y + 1, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 0.5, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;


//						doc.ActiveView.SetElementOverrides(elevationView.Id,ogs);
                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }
                    else if (i == 1)
                    {
                        myCrop.Min = new XYZ(myRoomBB.Min.X - 1, myRoom.Level.Elevation - 0.5, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myRoomBB.Max.X + 1, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 0.5, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }

                    // mai xu li
                    else if (i == 2)
                    {
                        double XMin = -(Math.Abs(maxPointBB.Y - minPointBb.Y) / 2) - 1;
                        double XMax = +(Math.Abs(maxPointBB.Y - minPointBb.Y) / 2) + 1;

                        myCrop.Min = new XYZ(XMin - OriginPoint2.Y, myRoom.Level.Elevation - 0.5, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myCrop.Min.X + myRoomBB.Max.Y - myRoomBB.Min.Y + 2, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 0.5, myCrop.Max.Z);

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;


                        elevationView.CropBox = myCrop;
                    }

                    else
                    {
                        myCrop.Min            = new XYZ(myRoomBB.Min.X - 1 - 2 * (OriginPoint2.X), myRoom.Level.Elevation - 0.5, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myCrop.Min.X + myRoomBB.Max.X - myRoomBB.Min.X + 2, myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 0.5, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }
                }
                trans.Commit();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Nhận vào 2 tham số, trả về null khi tạo 4 mặt đứng bằng instance thuộc lớp ElevationMarker
        /// </summary>
        /// <param name="uiDoc"></param>
        /// <param name="myRoom"></param>
        private void createElevationByRoom(UIDocument uiDoc, Room myRoom)
        {
            // Set active document
            Document doc = uiDoc.Document;

            using (Transaction trans = new Transaction(doc, "add elevation"))
            {
                // Start Transaction
                trans.Start();


                // Get parameter of room
                double myLevel = myRoom.Level.Elevation;

                // Get BoundingBoxXYZ of the room.
                BoundingBoxXYZ myRoomBB = myRoom.get_BoundingBox(null);

                XYZ maxPointBB = myRoomBB.Max;
                XYZ minPointBB = myRoomBB.Min;

                //Set Origin View Point as rooms Location Point
                LocationPoint lcPointRoom = myRoom.Location as LocationPoint;
                XYZ           originPoint = lcPointRoom.Point;

                // Get Center Point of room to make reference Point of views
                XYZ OriginPoint2 = new XYZ((maxPointBB.X + minPointBB.X) / 2, (maxPointBB.Y + minPointBB.Y) / 2, originPoint.Z);

                // second parameter in contructor ElevationMarker
                ViewFamilyType vft = new FilteredElementCollector(doc)
                                     .OfClass(typeof(ViewFamilyType))
                                     .Cast <ViewFamilyType>()
                                     .FirstOrDefault <ViewFamilyType>(x =>
                                                                      ViewFamily.Elevation == x.ViewFamily);

                ElementId myEleId = vft.Id;


                // Create 1 ElevationMaker with scale = 1:40, type View = Elevation
                ElevationMarker myELM = ElevationMarker.CreateElevationMarker(doc, myEleId, originPoint, 40);

                // Set max and Min Elevation of View (axis Y of Section Views), offset = 1 feet;

                double minY = myRoom.Level.Elevation - 1;                           // offset - 1
                double maxY = myRoom.UpperLimit.Elevation + myRoom.LimitOffset + 1; //offset + 1

                for (int i = 0; i < 4; i++)

                {
                    ViewSection elevationView = myELM.CreateElevation(doc, doc.ActiveView.Id, i);


                    string roomsName = myRoom.Name.Substring(0, myRoom.Name.Length - 1 - myRoom.Number.ToString().Length);

                    elevationView.Name = roomsName.ToUpper() + ", Section ".ToUpper() + i.ToString().ToUpper();

                    elevationView.CropBoxActive = true;

                    elevationView.DisplayStyle = DisplayStyle.Realistic;

                    BoundingBoxXYZ myCrop = elevationView.get_BoundingBox(null);
                    if (i == 0)
                    {
                        // Case 1: LeftView
                        myCrop.Min            = new XYZ(myRoomBB.Min.Y - 1, minY, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myRoomBB.Max.Y + 1, maxY, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }
                    else if (i == 1)
                    {
                        //Case 2: Above View
                        myCrop.Min = new XYZ(myRoomBB.Min.X - 1, minY, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myRoomBB.Max.X + 1, maxY, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style	for View
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }

                    // Case 3, 4 make OriginPoint2 as reference Point
                    else if (i == 2)
                    {
                        //
                        double XMin = -(Math.Abs(maxPointBB.Y - minPointBB.Y) / 2) - 1;
                        double XMax = +(Math.Abs(maxPointBB.Y - minPointBB.Y) / 2) + 1;

                        myCrop.Min = new XYZ(XMin - OriginPoint2.Y, minY, myCrop.Min.Z);
                        myCrop.Max = new XYZ(myCrop.Min.X + myRoomBB.Max.Y - myRoomBB.Min.Y + 2, maxY, myCrop.Max.Z);

                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }

                    else
                    {
                        myCrop.Min            = new XYZ(myRoomBB.Min.X - 1 - 2 * (OriginPoint2.X), minY, myCrop.Min.Z);
                        myCrop.Max            = new XYZ(myCrop.Min.X + myRoomBB.Max.X - myRoomBB.Min.X + 2, maxY, myCrop.Max.Z);
                        elevationView.CropBox = myCrop;

                        // Set visual style
                        elevationView.DisplayStyle = DisplayStyle.HLR;
                    }
                }
                trans.Commit();
            }
        }