Ejemplo n.º 1
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            PhaseArray xcom      = doc.Phases;
            Phase      lastPhase = xcom.get_Item(xcom.Size - 1);
            ElementId  idPhase   = lastPhase.Id;
            FinishForm MainForm  = new FinishForm(doc);

            MainForm.disFElements("Number");
            MainForm.ShowDialog();
            lastPhase = MainForm.retPhase;
            idPhase   = lastPhase.Id;



            FilterNumericRuleEvaluator evaluator   = new FilterNumericEquals();
            FilterableValueProvider    provider    = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED));
            FilterElementIdRule        fRule       = new FilterElementIdRule(provider, evaluator, idPhase);
            ElementParameterFilter     door_filter = new ElementParameterFilter(fRule);

            IList <Element> allWalls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
                                       .WhereElementIsNotElementType()
                                       .WherePasses(door_filter)
                                       .ToElements();

            List <Element> otdWalls   = allWalls.Where(x => x.Name.StartsWith("I__Отделка")).ToList();
            List <Room>    roomofWall = new List <Room>();



            using (Transaction tr = new Transaction(doc, "creating"))
            {
                tr.Start();
                foreach (Element i in otdWalls)
                {
                    BoundingBoxXYZ bBox = i.get_BoundingBox(null);

                    if (bBox != null)
                    {
                        XYZ origin = new XYZ((bBox.Max.X + bBox.Min.X) / 2, (bBox.Max.Y + bBox.Min.Y) / 2, (bBox.Max.Z + bBox.Min.Z) / 2);
                        try
                        {
                            i.setP("Помещение", doc.GetRoomAtPoint(origin, lastPhase).Number);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }



                tr.Commit();
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 2
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            FinishForm MainForm = new FinishForm(doc);

            MainForm.disFElements("New");
            MainForm.ShowDialog();

            double FT = 0.3048;


            Phase     lastPhase = MainForm.retPhase;
            ElementId idPhase   = lastPhase.Id;
            //Выбираем элементы в Ревите
            ICollection <ElementId> selectedElements = uidoc.Selection.GetElementIds();
            List <Room>             selectedRooms    = selectedElements.Select(x => doc.GetElement(x) as Room).ToList();

            //Находим граничные элементы помещения
            //SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();

            List <IList <IList <BoundarySegment> > > roomBounds = selectedRooms.Select(x => x.GetBoundarySegments(new SpatialElementBoundaryOptions())).ToList();

            //foreach (var r in selectedRooms)
            //{
            //    roomBounds.Add(r.GetBoundarySegments(options));
            //}

            //Получаем элементы границ и несоединенные кривые
            List <Element> roomElems = new List <Element>();
            List <List <List <Curve> > > disjoinedCurves = new List <List <List <Curve> > >();

            foreach (IList <IList <BoundarySegment> > rb in roomBounds)
            {
                List <List <Curve> > tempCrvList = new List <List <Curve> >();
                foreach (var closedCrv in rb)
                {
                    List <Curve> tempCCCrvList = new List <Curve>();
                    foreach (var elem in closedCrv)
                    {
                        tempCCCrvList.Add(elem.GetCurve());
                        if (doc.GetElement(elem.ElementId) == null)//Если элемент косячный
                        {
                            roomElems.Add(null);
                        }
                        else
                        {
                            roomElems.Add(doc.GetElement(elem.ElementId));
                        }
                    }
                    tempCrvList.Add(tempCCCrvList);
                }
                disjoinedCurves.Add(tempCrvList);
            }

            //Соединяем кривые в полилинии
            List <List <CurveLoop> > joinedCurvesUnfl = new List <List <CurveLoop> >();

            foreach (var d in disjoinedCurves)
            {
                List <CurveLoop> tempList = d.Select(x => CurveLoop.Create(x)).ToList();
                joinedCurvesUnfl.Add(tempList);
            }

            //Check the sense of polycurve
            foreach (var j in joinedCurvesUnfl)
            {
                foreach (CurveLoop crv in j)
                {
                    if (crv.GetPlane().Normal.Z < 0)
                    {
                        crv.Flip();
                    }
                }
            }
            List <string> getRoomNumbers = new List <string>();

            List <List <Room> > repeatedRoomsUnfl = new List <List <Room> >();
            int count = 0;

            foreach (var j in joinedCurvesUnfl)
            {
                List <Room> tempList = new List <Room>();

                foreach (CurveLoop crv in j)
                {
                    tempList.Add(selectedRooms.ElementAt(count));
                }
                repeatedRoomsUnfl.Add(tempList);
                count += 1;
            }

            List <Room> repeatedRoomsFl = GenericList <Room> .Flatten(repeatedRoomsUnfl);

            List <CurveLoop> joinedCurvesFl = GenericList <CurveLoop> .Flatten(joinedCurvesUnfl);

            List <string>  wHeights     = new List <string>();
            List <Element> wTypes       = new List <Element>();
            List <Element> allWallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType)).ToList();

            //GlobalParameter OTD_Main;
            //using (Transaction tryGlobal = new Transaction(doc, "defineGlobal"))
            //{
            //    tryGlobal.Start();

            //    if (GlobalParametersManager.FindByName(doc, "ОТД_Основная") != ElementId.InvalidElementId)
            //    {
            //        OTD_Main = doc.GetElement(GlobalParametersManager.FindByName(doc, "ОТД_Основная")) as GlobalParameter;
            //    }
            //    else
            //    {
            //        OTD_Main = GlobalParameter.Create(doc, "ОТД_Основная", ParameterType.Text);

            //    }

            //    tryGlobal.Commit();
            //}
            string s_OTD_Main = MainForm.wTypeBoxes[0];

            //string s_OTD_Main = ((StringParameterValue)OTD_Main.GetValue()).Value;
            //wTypes.Add(MainForm.wTypeBoxes)
            foreach (Element wt in allWallTypes)
            {
                if (wt.Name == s_OTD_Main)
                {
                    wTypes.Add(wt);
                }
            }
            //foreach (Room r in repeatedRoomsFl)
            //{
            //    //wHeights.Add(r.getP(s_OTD_Main));
            //    //allWallTypes.Where(x => x.Name == r.getP("setFFF")).ToList();
            //    foreach (Element wt in allWallTypes)
            //    {
            //        if (wt.Name==r.getP(s_OTD_Main))
            //        {
            //            wTypes.Add(wt);
            //        }
            //    }
            //}

            //Level of each room
            List <Level> levels = repeatedRoomsFl.Select(x => x.Level).ToList();

            //Create offset curve
            List <CurveLoop> offsetedCurves = new List <CurveLoop>();
            DisplayUnitType  docLengthUnit  = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;

            count = 0;
            foreach (CurveLoop j in joinedCurvesFl)
            {
                double valueWith = wTypes[0].get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsDouble();
                //double value = UnitUtils.Convert(valueWith, DisplayUnitType.DUT_DECIMAL_FEET, docLengthUnit);
                double    value = valueWith / FT;
                CurveLoop gg    = CurveLoop.CreateViaOffset(j, (valueWith * (0.5)), j.GetPlane().Normal);

                if (repeatedRoomsFl[count].IsPointInRoom(gg.GetCurveLoopIterator().Current.GetEndPoint(0)) == true)
                {
                    offsetedCurves.Add(gg);
                }
                else
                {
                    //offsetedCurves.Add(gg);
                    try
                    {
                        offsetedCurves.Add(CurveLoop.CreateViaOffset(j, (valueWith * (-0.5)), j.GetPlane().Normal));
                    }
                    catch (Exception)
                    {
                    }
                }
                count += 1;
            }

            List <List <Curve> > explodedCurves = new List <List <Curve> >();

            foreach (CurveLoop oc in offsetedCurves)
            {
                List <Curve> tempList = new List <Curve>();
                foreach (Curve i in oc)
                {
                    tempList.Add(i);
                }

                explodedCurves.Add(tempList);
            }

            List <Wall> walls = new List <Wall>();

            using (Transaction tr = new Transaction(doc, "PerimetralWall"))
            {
                tr.Start();
                count = 0;
                foreach (List <Curve> group in explodedCurves)
                {
                    foreach (Curve crv in group)
                    {
                        Wall w = Wall.Create(doc, crv, wTypes[0].Id, levels[count].Id, 2 / FT, 0, false, false);
                        walls.Add(w);
                    }

                    count += 1;
                }
                count = 0;
                foreach (Wall w in walls)
                {
                    w.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0);
                    w.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set(2);
                    w.DemolishedPhaseId = lastPhase.Id;
                    //w.setP("Помещение", repeatedRoomsFl[count].Number);
                    count += 1;
                }
                count = 0;

                /*
                 * foreach (Element r in roomElems)
                 * {
                 *  try
                 *  {
                 *      JoinGeometryUtils.JoinGeometry(doc, walls[count], r);
                 *  }
                 *  catch (Exception)
                 *  {
                 *
                 *
                 *  }
                 *  count += 1;
                 * }
                 */

                tr.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 3
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp     = commandData.Application;
            UIDocument    uidoc     = uiapp.ActiveUIDocument;
            Application   app       = uiapp.Application;
            Document      doc       = uidoc.Document;
            PhaseArray    xcom      = doc.Phases;
            Phase         lastPhase = xcom.get_Item(xcom.Size - 1);
            ElementId     idPhase   = lastPhase.Id;
            FilterNumericRuleEvaluator evaluator = new FilterNumericEquals();

            GlobalParameter GlobePar2 = GlobalParametersManager.FindByName(doc, "FinData") != ElementId.InvalidElementId ?
                                        doc.GetElement(GlobalParametersManager.FindByName(doc, "FinData")) as GlobalParameter :null;
            FinishForm MainForm = new FinishForm(doc);

            MainForm.ShowDialog();
            using (Transaction tr = new Transaction(doc, "setGP"))
            {
                tr.Start();
                GlobalParameter GlobePar = GlobalParametersManager.FindByName(doc, "FinData") != ElementId.InvalidElementId ?
                                           doc.GetElement(GlobalParametersManager.FindByName(doc, "FinData")) as GlobalParameter :
                                           GlobalParameter.Create(doc, "FinData", ParameterType.Text);
                GlobePar.SetValue(new StringParameterValue(string.Join("|", MainForm.wTypeBoxes)));
                //int MoreThenOneLevel = ((IntegerParameterValue)GlobePar.GetValue()).Value;
                tr.Commit();
            }

            lastPhase = MainForm.retPhase;
            idPhase   = lastPhase.Id;

            List <SharedParameterElement> shParamElements = new FilteredElementCollector(doc)
                                                            .OfClass(typeof(SharedParameterElement))
                                                            .Cast <SharedParameterElement>()
                                                            .ToList();
            //Фильтр: Помещения на последней стадии
            FilterableValueProvider providerRoom = new ParameterValueProvider(new ElementId((int)BuiltInParameter.ROOM_PHASE_ID));
            FilterElementIdRule     rRule        = new FilterElementIdRule(providerRoom, evaluator, idPhase);
            ElementParameterFilter  room_filter  = new ElementParameterFilter(rRule);
            //FilterableValueProvider provRoomSchool = new ParameterValueProvider(shParam.Id);
            FilterStringRuleEvaluator StrEvaluator = new FilterStringEquals();
            IList <Element>           rooms        = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
                                                     .WhereElementIsNotElementType()
                                                     .WherePasses(room_filter)
                                                     //.WherePasses(roomSc_filter)
                                                     .ToElements();

            //Фильтр: Стены созданные на последней стадии
            FilterableValueProvider provider    = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED));
            FilterElementIdRule     fRule       = new FilterElementIdRule(provider, evaluator, idPhase);
            ElementParameterFilter  door_filter = new ElementParameterFilter(fRule);

            IList <Element> allWalls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
                                       .WhereElementIsNotElementType()
                                       .WherePasses(door_filter)
                                       .ToElements();

            //Фильтр: экземпляры дверей
            List <FamilyInstance> doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors)
                                          .WhereElementIsNotElementType()
                                          .Cast <FamilyInstance>()
                                          .ToList();


            foreach (Element e in rooms)
            {
                RoomFinishing.Rooms.Add(new RoomFinishing(e));
            }
            RoomFinishing.Rooms = RoomFinishing.Rooms.OrderBy(x => x.Num).ToList();

            List <GhostWall> cWalls = new List <GhostWall>();

            foreach (Element wall in allWalls)
            {
                if (wall.LookupParameter("Помещение").AsString() != null & wall.LookupParameter("Помещение").AsString() != "")
                {
                    cWalls.Add(new GhostWall(wall, MainForm.LocType));
                }
            }

            foreach (GhostWall w in cWalls)
            {
                foreach (RoomFinishing r in RoomFinishing.Rooms)
                {
                    if (r.Num == w.Room)
                    {
                        if (w.typeName == MainForm.LocType.Name)
                        {
                            r.unitLocalWallVal += w.Area;
                            r.LocalWallText     = w.sostav;
                        }
                        else if (w.typeName == MainForm.ColType.Name)
                        {
                            r.unitKolonWallVal += w.Area;
                            r.KolonWallText     = w.sostav;
                        }
                        else
                        {
                            r.unitMainWallVal += w.Area;
                        }
                        if (w.countNewW)
                        {
                            r.unitNewWallVal += w.Area;
                        }
                    }
                }
            }


            //Плинтус
            foreach (FamilyInstance d in doors)
            {
                foreach (RoomFinishing r in RoomFinishing.Rooms)
                {
                    try
                    {
                        if (d.get_FromRoom(lastPhase).Id == r.Id | d.get_ToRoom(lastPhase).Id == r.Id)
                        {
                            r.Perimeter -= d.LookupParameter("сп_Ширина проёма").AsDouble();
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            RoomFinishing.makeFinish(MainForm);
            RoomFinishing.makeFloor(MainForm.splitLevel);
            using (Transaction tr = new Transaction(doc, "otdelka"))
            {
                tr.Start();
                GlobalParameter GlobePar = GlobalParametersManager.FindByName(doc, "НесколькоЭтажей") != ElementId.InvalidElementId ?
                                           doc.GetElement(GlobalParametersManager.FindByName(doc, "НесколькоЭтажей")) as GlobalParameter :
                                           GlobalParameter.Create(doc, "НесколькоЭтажей", ParameterType.YesNo);
                int MoreThenOneLevel = ((IntegerParameterValue)GlobePar.GetValue()).Value;

                int withNames = MainForm.withnames;
                MoreThenOneLevel = MainForm.levels;

                RoomFinishing.FinishTableCommit(doc, MainForm);
                RoomFinishing.FloorTableCommit(MoreThenOneLevel, withNames, doc);

                tr.Commit();
            }
            TaskDialog msg = new TaskDialog("Info");

            msg.MainInstruction = $"Выполнен расчет отделки для стадии \"{MainForm.retPhase.Name}\"";
            msg.Show();
            return(Result.Succeeded);
        }