예제 #1
0
        public static RebarInfoFloor GetDefault(Document doc)
        {
            RebarBarType bartype = new FilteredElementCollector(doc)
                                   .WhereElementIsElementType()
                                   .OfClass(typeof(RebarBarType))
                                   .Cast <RebarBarType>()
                                   .First();
            string bartypename = bartype.Name;

            RebarInfoFloor info = new RebarInfoFloor();

            info.rebarTypeName = bartypename;


            return(info);
        }
예제 #2
0
        public DialogWindowFloor(RebarInfoFloor Info, List <string> rebarTypes)
        {
            InitializeComponent();

            rif = Info;

            comboBoxType.DataSource        = rebarTypes;
            comboBoxType.Text              = Info.rebarTypeName;
            numInterval.Value              = (decimal)(Info.interval * 304.8);
            numCoverBottom.Value           = (decimal)(Info.bottomCover * 304.8);
            numCoverTop.Value              = (decimal)(Info.topCover * 304.8);
            checkBoxUseDirection.Checked   = Info.useDirection;
            checkBoxTurnTopBars.Checked    = Info.turnTopBars;
            checkBoxTurnBottomBars.Checked = Info.turnBottomBars;
            this.Text = "Армирование плит v" + System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("FloorAreaRebar"));
            Debug.WriteLine("Floor reinforcement start");
            App.ActivateConfigFolder();
            Document     doc    = commandData.Application.ActiveUIDocument.Document;
            Selection    sel    = commandData.Application.ActiveUIDocument.Selection;
            List <Floor> floors = new List <Floor>();

            foreach (ElementId id in sel.GetElementIds())
            {
                Element elem = doc.GetElement(id);
                if (elem is Floor)
                {
                    floors.Add(elem as Floor);
                }
            }
            Debug.WriteLine("Selected floors: " + floors.Count);
            if (floors.Count == 0)
            {
                message = "Выберите плиты для армирования";
                return(Result.Failed);
            }

            ElementId areaTypeId = SupportDocumentGetter.GetDefaultArea(doc).Id;

            Debug.WriteLine("AreaTypeId: " + areaTypeId.IntegerValue);
            RebarCoverType zeroCover = SupportDocumentGetter.GetRebarCoverType(doc, 0);

            Debug.WriteLine("Zero cover type id: " + zeroCover.Id.IntegerValue);

            List <string> rebarTypes = SupportDocumentGetter.GetRebarTypes(doc);

            Debug.WriteLine("Rebar types: " + rebarTypes.Count);

            if (floors.Count == 0)
            {
                message = "Нет подходящих перекрытий для армирования";
                return(Result.Failed);
            }

            foreach (Floor fl in floors)
            {
                Parameter floorIsStructuralParam = fl.get_Parameter(BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL);
                if (floorIsStructuralParam != null)
                {
                    if (floorIsStructuralParam.AsInteger() != 1)
                    {
                        elements.Insert(fl);
                    }
                }
            }
            Debug.WriteLine("Structural floors: " + (floors.Count - elements.Size));
            if (elements.Size > 0)
            {
                message = "Найдены не несущие плиты, армирование не будет выполнено";
                return(Result.Failed);
            }

            string         floorPath  = System.IO.Path.Combine(App.localFolder, "floor.xml");
            RebarInfoFloor rif        = null;
            XmlSerializer  serializer = new XmlSerializer(typeof(RebarInfoFloor));

            if (System.IO.File.Exists(floorPath))
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(floorPath))
                {
                    try
                    {
                        rif = (RebarInfoFloor)serializer.Deserialize(reader);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Unable to deserialize, create new one: " + ex.Message);
                        rif = RebarInfoFloor.GetDefault(doc);
                    }
                    if (rif == null)
                    {
                        Debug.WriteLine("Deserialize error: " + floorPath);
                        throw new Exception("Не удалось десериализовать: " + floorPath);
                    }
                }
            }
            else
            {
                Debug.WriteLine("No xml file, create new one");
                rif = RebarInfoFloor.GetDefault(doc);
            }

            DialogWindowFloor form = new DialogWindowFloor(rif, rebarTypes);

            form.ShowDialog();
            if (form.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                Debug.WriteLine("Cancelled by user");
                return(Result.Cancelled);
            }

            if (File.Exists(floorPath))
            {
                Debug.WriteLine("File is deleted: " + floorPath);
                File.Delete(floorPath);
            }
            using (FileStream writer = new FileStream(floorPath, FileMode.OpenOrCreate))
            {
                serializer.Serialize(writer, form.rif);
                Debug.WriteLine("New file is created: " + floorPath);
            }

            List <string> rebarMessages = new List <string>();

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Армирование плит");

                foreach (Floor floor in floors)
                {
                    Debug.WriteLine("Current reinforcement floor: " + floor.Id.IntegerValue);
                    List <string> curRebarMessages = RebarWorkerFloor.Generate(doc, floor, rif, areaTypeId);
                    rebarMessages.AddRange(curRebarMessages);
                }
                t.Commit();
            }

            if (rebarMessages.Count > 0)
            {
                foreach (string msg in rebarMessages)
                {
                    message += msg + System.Environment.NewLine;
                }
                Debug.WriteLine("Errors: " + message);
                return(Result.Failed);
            }
            Debug.WriteLine("All done");
            return(Result.Succeeded);
        }
        public static List <string> Generate(Document doc, Floor floor, RebarInfoFloor rif, ElementId areaTypeId)
        {
            Debug.WriteLine("RebarWorkerFloor is started");
            List <string> messages = new List <string>();
            MyRebarType   mrt      = new MyRebarType(doc, rif.rebarTypeName);

            if (mrt.isValid == false)
            {
                messages.Add("Не удалось получить тип стержня " + rif.rebarTypeName);
            }
            double interval        = rif.interval;
            double topCoverUser    = rif.topCover;
            double bottomCoverUser = rif.bottomCover;

            RebarCoverType coverTop    = doc.GetElement(floor.get_Parameter(BuiltInParameter.CLEAR_COVER_TOP).AsElementId()) as RebarCoverType;
            RebarCoverType coverBottom = doc.GetElement(floor.get_Parameter(BuiltInParameter.CLEAR_COVER_BOTTOM).AsElementId()) as RebarCoverType;

            if (coverTop == null)
            {
                Debug.WriteLine("Top cover is null");
                coverTop = coverBottom;
            }
            if (coverBottom == null)
            {
                Debug.WriteLine("Bottom cover is null");
                coverBottom = coverTop;
            }

            Debug.WriteLine("Rebar cover types id, top: " + coverTop.Id.IntegerValue + ", bottom: " + coverBottom.Id.IntegerValue);

#if R2017 || R2018 || R2019 || R2020 || R2021
            double diam = mrt.bartype.BarDiameter;
#else
            double diam = mrt.bartype.BarNominalDiameter;
#endif

            double topCoverDir1 = topCoverUser - coverTop.CoverDistance;
            double topCoverDir2 = topCoverDir1 + diam;
            if (rif.turnTopBars)
            {
                topCoverDir1 += diam;
                topCoverDir2 -= diam;
            }

            double bottomCoverDir1 = bottomCoverUser - coverBottom.CoverDistance;
            double bottomCoverDir2 = bottomCoverDir1 + diam;
            if (rif.turnBottomBars)
            {
                bottomCoverDir1 += diam;
                bottomCoverDir2 -= diam;
            }


            List <Curve> curves = SupportGeometry.GetFloorOuterBoundary(floor);
            Debug.WriteLine("Boundary curves count: " + curves.Count);

            XYZ direction = new XYZ(1, 0, 0);

            if (rif.useDirection)
            {
                double    angle           = floor.SpanDirectionAngle;
                Transform rotateTransform = Transform.CreateRotationAtPoint(new XYZ(0, 0, 1), angle, new XYZ(0, 0, 0));
                Line      horizontal      = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                Curve     rotatedCurve    = horizontal.CreateTransformed(rotateTransform);
                direction = rotatedCurve.GetEndPoint(1);
            }
            Debug.WriteLine("Direction: " + direction.ToString());

            AreaReinforcement arTopX = AreaReinforcement
                                       .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(1);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_1_GENERIC).Set(interval);
            arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_TOP_OFFSET).Set(topCoverDir1);
            arTopX.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("верх X фон");
            Debug.WriteLine("Top X is created");

            AreaReinforcement arTopY = AreaReinforcement
                                       .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(1);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_2_GENERIC).Set(interval);
            arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_TOP_OFFSET).Set(topCoverDir2);
            arTopY.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("верх Y фон");
            Debug.WriteLine("Top Y is created");

            AreaReinforcement arBottomX = AreaReinforcement
                                          .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(1);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_1_GENERIC).Set(interval);
            arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_BOTTOM_OFFSET).Set(bottomCoverDir1);
            arBottomX.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("низ X фон");
            Debug.WriteLine("Bottom X is created");

            AreaReinforcement arBottomY = AreaReinforcement
                                          .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(1);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_2_GENERIC).Set(interval);
            arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_BOTTOM_OFFSET).Set(bottomCoverDir2);
            arBottomY.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("низ Y фон");
            Debug.WriteLine("Bottom Y is created");

            return(messages);
        }