예제 #1
0
        void RoomFinish(UIDocument UIDoc, Transaction tx)
        {
            Document doc = UIDoc.Document;

            tx.Start(Tools.LangResMan.GetString("roomFinishes_transactionName", Tools.Cult));

            //Load the selection form
            RoomsFinishesControl userControl = new RoomsFinishesControl(UIDoc);

            userControl.InitializeComponent();

            if (userControl.ShowDialog() == true)
            {
                //Select wall types
                WallType plinte      = userControl.SelectedWallType;
                WallType newWallType = userControl.DuplicatedWallType;

                //Get all finish properties
                double height = userControl.BoardHeight;

                //Select Rooms in model
                IEnumerable <Room> ModelRooms = userControl.SelectedRooms;

                //List<Wall> addedWalls = new List<Wall>();
                List <KeyValuePair <Wall, Wall> > addedWalls = new List <KeyValuePair <Wall, Wall> >();
                IList <ElementId> addedWallsIds = new List <ElementId>();

                //Loop on all rooms to get boundaries
                foreach (Room currentRoom in ModelRooms)
                {
                    ElementId roomLevelId = currentRoom.LevelId;

                    SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();
                    opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

                    IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundarySegmentArray = currentRoom.GetBoundarySegments(opt);
                    if (null == boundarySegmentArray)  //the room may not be bound
                    {
                        continue;
                    }

                    foreach (IList <Autodesk.Revit.DB.BoundarySegment> boundarySegArr in boundarySegmentArray)
                    {
                        if (0 == boundarySegArr.Count)
                        {
                            continue;
                        }
                        else
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in boundarySegArr)
                            {
                                Wall      currentWall       = Wall.Create(doc, boundarySegment.GetCurve(), newWallType.Id, roomLevelId, height, 0, false, false);
                                Parameter wallJustification = currentWall.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM);
                                wallJustification.Set(2);

                                Wall baseWall = doc.GetElement(boundarySegment.ElementId) as Wall;

                                addedWalls.Add(new KeyValuePair <Wall, Wall>(currentWall, baseWall));
                                addedWallsIds.Add(currentWall.Id);
                            }
                        }
                    }
                }

                FailureHandlingOptions options = tx.GetFailureHandlingOptions();

                options.SetFailuresPreprocessor(new PlintePreprocessor());
                // Now, showing of any eventual mini-warnings will be postponed until the following transaction.
                tx.Commit(options);

                tx.Start(Tools.LangResMan.GetString("roomFinishes_transactionName", Tools.Cult));

                Wall.ChangeTypeId(doc, addedWallsIds, plinte.Id);

                foreach (KeyValuePair <Wall, Wall> addedWallPair in addedWalls)
                {
                    Parameter wallJustification = addedWallPair.Key.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM);
                    wallJustification.Set(3);

                    //Join both wall
                    if (userControl.JoinWall)
                    {
                        JoinGeometryUtils.JoinGeometry(doc, addedWallPair.Key, addedWallPair.Value);
                    }
                }

                doc.Delete(newWallType.Id);

                tx.Commit();
            }
            else
            {
                tx.RollBack();
            }
        }
예제 #2
0
        void RoomFinish(UIDocument uiDoc, Transaction tx)
        {
            Document doc = uiDoc.Document;

            tx.Start(Tools.LangResMan.GetString("roomFinishes_transactionName", Tools.Cult));

            //Load the selection form
            RoomsFinishesControl userControl = new RoomsFinishesControl(uiDoc);

            userControl.InitializeComponent();

            if (userControl.ShowDialog() == true)
            {
                //Select wall types
                WallType plinte      = userControl.SelectedWallType;
                WallType newWallType = userControl.DuplicatedWallType;

                //Get all finish properties
                double height = userControl.BoardHeight;

                //Select Rooms in model
                IEnumerable <Room> modelRooms = userControl.SelectedRooms;

                Dictionary <ElementId, ElementId> skirtingDictionary = new Dictionary <ElementId, ElementId>();
                List <KeyValuePair <Wall, Wall> > addedWalls         = new List <KeyValuePair <Wall, Wall> >();

                //Loop on all rooms to get boundaries
                foreach (Room currentRoom in modelRooms)
                {
                    ElementId roomLevelId = currentRoom.LevelId;

                    SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();
                    opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

                    IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundarySegmentArray = currentRoom.GetBoundarySegments(opt);
                    if (null == boundarySegmentArray)  //the room may not be bound
                    {
                        continue;
                    }

                    foreach (IList <Autodesk.Revit.DB.BoundarySegment> boundarySegArr in boundarySegmentArray)
                    {
                        if (0 == boundarySegArr.Count)
                        {
                            continue;
                        }
                        else
                        {
                            foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in boundarySegArr)
                            {
                                //Check if the boundary is a room separation lines
                                Element boundaryElement = doc.GetElement(boundarySegment.ElementId);

                                if (boundaryElement == null)
                                {
                                    continue;
                                }

                                Categories categories            = doc.Settings.Categories;
                                Category   RoomSeparetionLineCat = categories.get_Item(BuiltInCategory.OST_RoomSeparationLines);

                                if (boundaryElement.Category.Id != RoomSeparetionLineCat.Id)
                                {
                                    Wall      currentWall       = Wall.Create(doc, boundarySegment.GetCurve(), newWallType.Id, roomLevelId, height, 0, false, false);
                                    Parameter wallJustification = currentWall.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM);
                                    wallJustification.Set(2);

                                    skirtingDictionary.Add(currentWall.Id, boundarySegment.ElementId);
                                }
                            }
                        }
                    }
                }

                FailureHandlingOptions options = tx.GetFailureHandlingOptions();

                options.SetFailuresPreprocessor(new PlintePreprocessor());
                // Now, showing of any eventual mini-warnings will be postponed until the following transaction.
                tx.Commit(options);

                tx.Start(Tools.LangResMan.GetString("roomFinishes_transactionName", Tools.Cult));

                List <ElementId> addedIds = new List <ElementId>(skirtingDictionary.Keys);
                foreach (ElementId addedSkirtingId in addedIds)
                {
                    if (doc.GetElement(addedSkirtingId) == null)
                    {
                        skirtingDictionary.Remove(addedSkirtingId);
                    }
                }

                Wall.ChangeTypeId(doc, skirtingDictionary.Keys, plinte.Id);

                //Join both wall
                if (userControl.JoinWall)
                {
                    foreach (ElementId skirtingId in skirtingDictionary.Keys)
                    {
                        Wall skirtingWall = doc.GetElement(skirtingId) as Wall;

                        if (skirtingWall != null)
                        {
                            Parameter wallJustification = skirtingWall.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM);
                            wallJustification.Set(3);
                            Wall baseWall = doc.GetElement(skirtingDictionary[skirtingId]) as Wall;

                            if (baseWall != null)
                            {
                                JoinGeometryUtils.JoinGeometry(doc, skirtingWall, baseWall);
                            }
                        }
                    }
                }

                doc.Delete(newWallType.Id);

                tx.Commit();
            }
            else
            {
                tx.RollBack();
            }
        }