Esempio n. 1
0
        public static List <Revit.Elements.Element> CreateWallSweep(List <Revit.Elements.Wall> Walls, Revit.Elements.Element TypeElement, string SweepOrReveal, bool IsVertical, double Offset = 1000)
        {
            var doc            = DocumentManager.Instance.CurrentDBDocument;
            var WallSweeps     = new List <Revit.Elements.Element>();
            var wallSweepTypes = new Dictionary <string, Autodesk.Revit.DB.WallSweepType>();

            wallSweepTypes.Add("Sweep", WallSweepType.Sweep);
            wallSweepTypes.Add("Reveal", WallSweepType.Reveal);
            var wallSweepTypeId = TypeElement.InternalElement.Id;

            WallSweepInfo wallSweepInfo = new WallSweepInfo(wallSweepTypes[SweepOrReveal], IsVertical);

            wallSweepInfo.Distance = Offset / 304.8;

            TransactionManager.Instance.EnsureInTransaction(doc);

            foreach (var w in Walls)
            {
                var       wall      = w.InternalElement as Autodesk.Revit.DB.Wall;
                WallSweep wallSweep = WallSweep.Create(wall, wallSweepTypeId, wallSweepInfo);
                WallSweeps.Add(wallSweep.ToDSType(true));
            }

            TransactionManager.Instance.TransactionTaskDone();
            return(WallSweeps);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp     = commandData.Application;
            UIDocument    uidoc     = uiapp.ActiveUIDocument;
            Document      doc       = uidoc.Document;
            Selection     selection = uidoc.Selection;
            View          acview    = uidoc.ActiveView;

            try
            {
                Reference   reff          = selection.PickObject(ObjectType.Element, new MySelectionFilter <Room>(), "select a room");
                Room        room          = doc.GetElement(reff) as Room;
                ElementType wallSweepType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Cornices).WhereElementIsElementType().Cast <ElementType>().FirstOrDefault();

                if (wallSweepType != null)
                {
                    using (Transaction ts = new Transaction(doc, "创建踢脚线"))
                    {
                        ts.Start();
                        ElementType type = wallSweepType.Duplicate("踢脚线2");
                        SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions();
                        opts.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
                        IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundList = room.GetBoundarySegments(opts);
                        foreach (IList <BoundarySegment> bs in boundList)
                        {
                            foreach (BoundarySegment bs1 in bs)
                            {
                                Wall wall = doc.GetElement(bs1.ElementId) as Wall;
                                if (wall != null)
                                {
                                    WallSweepInfo info = new WallSweepInfo(WallSweepType.Sweep, false);
                                    // 墙的正反或者里面
                                    info.WallSide = WallSide.Exterior;
                                    // 距离墙底的高度
                                    info.Distance = 10 / 304.8;
                                    // 偏移距离
                                    info.WallOffset = 0;
                                    WallSweep.Create(wall, type.Id, info);
                                }
                            }
                        }
                        ts.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
            }



            return(Result.Succeeded);
        }