Пример #1
0
        protected void CheckDefaultSharedParameters()
        {
            bool done = true;

            done &= SharedParameterUtils.AddSharedParameter(doc, "ТеррНИИ_Идентификатор отделки пола",
                                                            new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            done &= SharedParameterUtils.AddSharedParameter(doc, "ТеррНИИ_Идентификатор потолка",
                                                            new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            done &= SharedParameterUtils.AddSharedParameter(doc, "ТеррНИИ_Номер помещения",
                                                            new BuiltInCategory[] { BuiltInCategory.OST_Floors, BuiltInCategory.OST_Ceilings }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            done &= SharedParameterUtils.AddSharedParameter(doc, "ТеррНИИ_Номера всех помещений",
                                                            new BuiltInCategory[] { BuiltInCategory.OST_Floors, BuiltInCategory.OST_Ceilings }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS, isIntance: false);
        }
Пример #2
0
        public static bool MirroredIndicator(FamilyInstance el)
        {
            Document doc       = el.Document;
            string   paramName = "ТеррНИИ_Элемент отзеркален";
            int      value     = el.Mirrored ? 1 : 0;

            using (Transaction tr = new Transaction(doc, "Индикатор отзеркаливания"))
            {
                tr.Start();
                SharedParameterUtils.AddSharedParameter(doc, paramName,
                                                        new BuiltInCategory[] { (BuiltInCategory)el.Category.Id.IntegerValue }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
                el.LookupParameter(paramName).Set(value);
                tr.Commit();
            }
            return(el.Mirrored);
        }
Пример #3
0
        protected bool CheckDefaultSharedParameters()
        {
            bool done = true;

            using (Transaction tr = new Transaction(doc, "Добавление общих параметров"))
            {
                tr.Start();
                //Проверяем наличие необходимых параметров в проекте
                done &= SharedParameterUtils.AddSharedParameter(doc, spaceNumberParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_DuctTerminal, BuiltInCategory.OST_MechanicalEquipment }, BuiltInParameterGroup.PG_IDENTITY_DATA);

                done &= SharedParameterUtils.AddSharedParameter(doc, exhaustSystemParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_MEPSpaces }, BuiltInParameterGroup.PG_MECHANICAL_AIRFLOW);

                done &= SharedParameterUtils.AddSharedParameter(doc, supplySystemParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_MEPSpaces }, BuiltInParameterGroup.PG_MECHANICAL_AIRFLOW);

                done &= SharedParameterUtils.AddSharedParameter(doc, spaceTemperatureParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_MEPSpaces }, BuiltInParameterGroup.PG_ENERGY_ANALYSIS);
                done &= SharedParameterUtils.AddSharedParameter(doc, spacePowerParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_MechanicalEquipment }, BuiltInParameterGroup.PG_ENERGY_ANALYSIS);

                /*
                 * Эти параметры должны быть внутри семейства, нет смысла назначать их всей категории
                 *
                 *  done &= CustomSharedParameter.AddSharedParameter(doc, thermalPowerParameterName, "ADSK_Main_MEP", true,
                 *      new BuiltInCategory[] { BuiltInCategory.OST_MechanicalEquipment }, BuiltInParameterGroup.PG_MECHANICAL);
                 *
                 *  done &= CustomSharedParameter.AddSharedParameter(doc, airflowParameterName, "ADSK_Main_MEP", true,
                 *      new BuiltInCategory[] { BuiltInCategory.OST_DuctTerminal }, BuiltInParameterGroup.PG_MECHANICAL_AIRFLOW);
                 */

                done &= SharedParameterUtils.AddSharedParameter(doc, skipParameterName,
                                                                new BuiltInCategory[] { BuiltInCategory.OST_DuctTerminal, BuiltInCategory.OST_MechanicalEquipment }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
                tr.Commit();
            }
            return(done);
        }
Пример #4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            uidoc = commandData.Application.ActiveUIDocument;
            doc   = uidoc.Document;
            string horFamilyName = "ТеррНИИ_УГО_3D_Теплоизоляция зигзаг";
            string verFamilyName = "ТеррНИИ_УГО_3D_Теплоизоляция зигзаг_Вертикальный";
            string familyFolder  = @"L:\REVIT\Семейства\ТеррНИИ\Условники\3D";
            string familyType    = "-";

            // получаем объекты для штриховки и задаем параметры
            var elems = GetElements();

            if (elems == null)
            {
                return(Result.Cancelled);
            }
            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Загрузка семейства");
                FamilySymbol horZigzagSymbol = FamilyInstanceUtils.FindOpeningFamily(doc, horFamilyName, familyFolder, familyType);
                FamilySymbol verZigzagSymbol = FamilyInstanceUtils.FindOpeningFamily(doc, verFamilyName, familyFolder, familyType);
                tr.Commit();

                tr.Start("Добавление общих параметров");
                var systemParamName = "ТеррНИИ_Наименование системы";
                var idParamName     = "ТеррНИИ_Идентификатор";
                // добавляем общие параметры, в который будем копировать марку и систему

                SharedParameterUtils.AddSharedParameter(doc, systemParamName,
                                                        new BuiltInCategory[] { BuiltInCategory.OST_GenericModel },
                                                        BuiltInParameterGroup.PG_TEXT);
                SharedParameterUtils.AddSharedParameter(doc, idParamName,
                                                        new BuiltInCategory[] { BuiltInCategory.OST_GenericModel },
                                                        BuiltInParameterGroup.PG_ADSK_MODEL_PROPERTIES);

                tr.Commit();

                tr.Start("Рисование штриховок");
                // проверяем какие штриховки уже есть в проекте и удаляем если есть обновляемые
                List <ElementId>      toDelete = new List <ElementId>();
                List <string>         elemsIds = elems.Select(x => x.Id.IntegerValue.ToString()).ToList();
                List <FamilyInstance> fills    = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance))
                                                 .Cast <FamilyInstance>().Where(x => x.Symbol.FamilyName == horFamilyName || x.Symbol.FamilyName == verFamilyName).ToList();
                foreach (FamilyInstance i in fills)
                {
                    var param = i.LookupParameter(idParamName);
                    if (param != null && elemsIds.Contains(param.AsString()))
                    {
                        toDelete.Add(i.Id);
                    }
                }
                doc.Delete(toDelete);

                foreach (MEPCurve e in elems)
                {
                    Curve ductCurve = (e.Location as LocationCurve).Curve;
                    Level level     = e.ReferenceLevel;

                    var dir = GeometryUtils.GetDuctOrientation(e.ConnectorManager);

                    XYZ pt1         = ductCurve.GetEndPoint(0);
                    XYZ pt2         = ductCurve.GetEndPoint(1);
                    XYZ project_pt1 = new XYZ(pt1.X, pt1.Y, level.Elevation);
                    XYZ project_pt2 = new XYZ(pt2.X, pt2.Y, level.Elevation);

                    FamilyInstance fi = null;
                    try
                    {
                        if (dir == GeometryUtils.DuctOrientation.Horizontal)
                        {
                            Line line = Line.CreateBound(project_pt1, project_pt2);
                            fi = doc.Create.NewFamilyInstance(line, horZigzagSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                            fi.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(e.LevelOffset);
                        }
                        else if (dir == GeometryUtils.DuctOrientation.StraightVertical)
                        {
                            fi = doc.Create.NewFamilyInstance(project_pt1, verZigzagSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                            fi.LookupParameter("Длина").Set(
                                pt1.DistanceTo(pt2)
                                );
                            var offset = e.LookupParameter("Нижняя отметка").AsDouble();
                            fi.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(offset);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (Autodesk.Revit.Exceptions.ArgumentsInconsistentException)
                    {
                        continue;
                    }

                    // Вычисляем марку
                    string insul_type      = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE).AsString();
                    string insul_thickness = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS).AsValueString();

                    // вычисляем наименование системы
                    var    p = e.LookupParameter(systemParamName);
                    string element_system = p != null?p.AsString() : "";

                    // вычисляем смещение
                    Parameter ductWidth    = e.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
                    Parameter ductHeight   = e.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
                    Parameter ductDiameter = e.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM);
                    Parameter pipeDiameter = e.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);

                    double fillOffset = 0;
                    if (ductDiameter != null)
                    {
                        fillOffset = ductDiameter.AsDouble() / 2;
                    }
                    else if (pipeDiameter != null)
                    {
                        fillOffset = pipeDiameter.AsDouble() / 2;
                    }
                    else
                    {
                        fillOffset = ductWidth.AsDouble() > ductHeight.AsDouble() ? ductHeight.AsDouble() / 2 : ductWidth.AsDouble() / 2;
                    }

                    // Назначаем параметры
                    fi.LookupParameter("Марка").Set(insul_type + " " + insul_thickness);
                    fi.LookupParameter(systemParamName).Set(element_system);
                    //fi.LookupParameter("Смещение по Z").Set(fillOffset);
                    fi.LookupParameter(idParamName).Set(e.Id.IntegerValue.ToString());
                }
                tr.Commit();
            }
            return(Result.Succeeded);
        }
Пример #5
0
        static public void Calculate(Room room)
        {
            if (room == null)
            {
                return;
            }
            Document doc = room.Document;
            string   openingAreaParameterName          = "ADSK_Площадь проемов";
            string   doorOpeningWidthParameterName     = "ТеррНИИ_Ширина дверных проемов";
            string   openingFinishingAreaParameterName = "ТеррНИИ_Площадь проемов отделка";
            string   finishingHeightParameterName      = "ТеррНИИ_Высота отделки помещения";
            string   finishingPerimeterParameterName   = "ТеррНИИ_Периметр отделки";
            string   slopeAreaParameterName            = "ТеррНИИ_Площадь откосов";
            string   doorOpeningPlaneAreaParameterName = "ТеррНИИ_Площадь проемов в плане";

            SharedParameterUtils.AddSharedParameter(doc, openingAreaParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, doorOpeningWidthParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, openingFinishingAreaParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, finishingPerimeterParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, slopeAreaParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, doorOpeningPlaneAreaParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_ANALYSIS_RESULTS);
            SharedParameterUtils.AddSharedParameter(doc, finishingHeightParameterName,
                                                    new BuiltInCategory[] { BuiltInCategory.OST_Rooms }, BuiltInParameterGroup.PG_CONSTRAINTS);

            if (room == null || room.Location == null || room.Area.Equals(0))
            {
                return;
            }

            SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions()
            {
                SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
            };
            double roomHeight               = room.UnboundedHeight;
            double finishingHeight          = room.LookupParameter(finishingHeightParameterName).AsDouble();
            double allOpeningsArea          = 0;
            double allOpeningsFinishingArea = 0;
            double doorOpeningsWidth        = 0;
            double finishingPerimeter       = 0;
            double allOpeningsSlope         = 0;
            double doorOpeningPlaneArea     = 0;

            List <ElementId> usedOpenings = new List <ElementId>();

            foreach (var boundary in room.GetBoundarySegments(opt))
            {
                foreach (var segment in boundary)
                {
                    finishingPerimeter += segment.GetCurve().Length;
                    if (segment.ElementId.IntegerValue == -1)
                    {
                        continue;
                    }
                    double segLength = segment.GetCurve().Length;
                    string catName   = doc.GetElement(segment.ElementId).Category.Name;
                    if (catName == "<Разделитель помещений>")
                    {
                        double area = segLength * roomHeight;
                        allOpeningsArea          += area;
                        allOpeningsFinishingArea += area * finishingHeight / roomHeight;
                        doorOpeningsWidth        += segLength;
                    }
                    else if (catName == "Стены")
                    {
                        Wall wall = doc.GetElement(segment.ElementId) as Wall;
                        if (wall == null)
                        {
                            continue;
                        }
                        WallType wallType = doc.GetElement(wall.GetTypeId()) as WallType;
                        if (wallType.Kind == WallKind.Curtain)
                        {
                            double wallHeight        = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                            double curtainRoomHeight = wallHeight <= roomHeight ? wallHeight : roomHeight;
                            double area = segLength * curtainRoomHeight;
                            allOpeningsArea          += area;
                            allOpeningsFinishingArea += area * finishingHeight / roomHeight;
                            doorOpeningsWidth        += segment.GetCurve().Length;
                            allOpeningsSlope          = (segLength + 2 * curtainRoomHeight) * wall.Width / 2;
                        }
                        else
                        {
                            IEnumerable <ElementId> insertsIds = wall.FindInserts(true, false, true, true).Where(x => IsElementCollideRoom(room, doc.GetElement(x)));

                            foreach (ElementId insertId in insertsIds)
                            {
                                if (usedOpenings.Contains(insertId))
                                {
                                    continue;
                                }

                                Element opening = doc.GetElement(insertId) as Element;
                                double  openingWidth;
                                double  openingHeight;
                                double  openingThickness;
                                GetOpeningSize(wall, opening, out openingWidth, out openingHeight, out openingThickness);

                                // Проверяем, чтобы ширина отверстия не была больше самой комнаты
                                openingWidth = openingWidth > segLength ? segLength : openingWidth;

                                double openingArea  = openingWidth * openingHeight;
                                double openingSlope = (openingWidth + openingHeight * 2) * openingThickness / 2;

                                Parameter p = opening.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET) ?? opening.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM);
                                double    itemBottomOffset     = p.AsDouble();
                                double    roomBottomOffset     = room.get_Parameter(BuiltInParameter.ROOM_LOWER_OFFSET).AsDouble();
                                double    openingFinishingArea = 0;
                                if (finishingHeight + roomBottomOffset >= itemBottomOffset + openingHeight)
                                {
                                    openingFinishingArea = openingArea;
                                }
                                else if (finishingHeight + roomBottomOffset > itemBottomOffset)
                                {
                                    openingFinishingArea = openingArea * (finishingHeight + roomBottomOffset - itemBottomOffset) / openingHeight;
                                }

                                allOpeningsArea          += openingArea;
                                allOpeningsFinishingArea += openingFinishingArea;
                                allOpeningsSlope         += openingSlope;
                                if (itemBottomOffset == roomBottomOffset)
                                {
                                    doorOpeningsWidth    += openingWidth;
                                    doorOpeningPlaneArea += openingWidth * wall.Width / 2;
                                }
                                usedOpenings.Add(insertId);
                            }
                        }
                    }
                }
            }
            room.LookupParameter(openingAreaParameterName).Set(allOpeningsArea);
            room.LookupParameter(openingFinishingAreaParameterName).Set(allOpeningsFinishingArea);
            room.LookupParameter(doorOpeningWidthParameterName).Set(doorOpeningsWidth);
            room.LookupParameter(finishingPerimeterParameterName).Set(finishingPerimeter);
            room.LookupParameter(slopeAreaParameterName).Set(allOpeningsSlope);
            room.LookupParameter(doorOpeningPlaneAreaParameterName).Set(doorOpeningPlaneArea);
        }