示例#1
0
        public Wall GetHostWall(UIDocument uidoc, DoorInformation doorinfo)
        {
            Document doc        = uidoc.Document;
            View     activeview = uidoc.ActiveView;
            XYZ      point      = doorinfo.door_location;
            FilteredElementCollector wallcollector = new FilteredElementCollector(doc, activeview.Id);

            wallcollector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall)).WhereElementIsNotElementType();
            IEnumerable <Wall> selected = from ele in wallcollector
                                          let wall = ele as Wall
                                                     let locationcurve                                                          = (ele as Wall).Location as LocationCurve
                                                                                                let curve                       = locationcurve.Curve
                                                                                                                       let line = curve as Line
                                                                                                                                  let newline = Line.CreateBound(new XYZ(line.GetEndPoint(0).X, line.GetEndPoint(0).Y, point.Z), new XYZ(line.GetEndPoint(1).X, line.GetEndPoint(1).Y, point.Z))
                                                                                                                                                let intersectionresulttmp = newline.Project(point)
                                                                                                                                                                            let distance = intersectionresulttmp.Distance
                                                                                                                                                                                           where distance <= wall.Width
                                                                                                                                                                                           select wall;

            if (selected.Count() == 0)
            {
                TaskDialog.Show("wrong", "未找到墙."); return(null);
            }
            if (selected.Count() > 1)
            {
                TaskDialog.Show("wrong", "找到多个墙."); return(null);
            }
            Wall hostwall = selected.First();

            return(hostwall);
        }
示例#2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc      = commandData.Application.ActiveUIDocument;
            Document   doc        = commandData.Application.ActiveUIDocument.Document;
            View       activeview = uidoc.ActiveView;
            Level      level      = activeview.GenLevel;

            if (activeview.UpDirection.X != 0 || activeview.UpDirection.Z != 0)
            {
                TaskDialog.Show("wrong", "请在平面视图内使用");
            }

            ExternalEventHandler handler = new ExternalEventHandler();
            ExternalEvent        exevent = ExternalEvent.Create(handler);

            bool iscontinue = true;

            do
            {
                DoorInformation doorinfo = GetDoorInfo(uidoc);
                if (doorinfo == null)
                {
                    iscontinue = false;
                }
                else
                {
                    Wall hostwall = GetHostWall(uidoc, doorinfo);
                    if (hostwall == null)
                    {
                        TaskDialog.Show("wrong", "在找墙的时候遇到错误."); return(Result.Failed);
                    }

                    //creat door
                    FamilyInstance door = null;
                    using (Transaction transaction = new Transaction(doc))
                    {
                        transaction.Start("create the door");

                        door = doc.Create.NewFamilyInstance(doorinfo.door_location, doorinfo.door_symbol, hostwall, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                        transaction.Commit();
                    }
                }
            } while (iscontinue);



            return(Result.Succeeded);
        }
示例#3
0
        public DoorInformation GetDoorInfo(UIDocument uidoc)
        {
            Document doc = uidoc.Document;

            //selection
            DetaiLineFilter detaillinefilter = new DetaiLineFilter();
            TextFilter      textfilter       = new TextFilter();
            Reference       refdetailline1   = null;
            Reference       refdetailline2   = null;
            Reference       reftext          = null;

            try
            {
                refdetailline1 = uidoc.Selection.PickObject(ObjectType.Element, detaillinefilter, "选择第一根边线.");
                refdetailline2 = uidoc.Selection.PickObject(ObjectType.Element, detaillinefilter, "选择第二根边线.");
                reftext        = uidoc.Selection.PickObject(ObjectType.Element, textfilter, "选择门标记.");
            }
            catch
            {
                return(null);
            }

            List <Line> lines = new List <Line>();

            lines.Add((doc.GetElement(refdetailline1) as DetailLine).GeometryCurve as Line);
            lines.Add((doc.GetElement(refdetailline2) as DetailLine).GeometryCurve as Line);
            TextNote text = doc.GetElement(reftext) as TextNote;

            //get family and symbol
            string str = text.Text;

            str = ProcessString(str);
            Family          doorfamily   = GetDoorFamily(doc, str);
            FamilySymbol    doorsymbol   = GetDoorSymbol(doc, doorfamily, str);
            XYZ             doorlocation = GetLoaction(lines);
            DoorInformation doorinfo     = new DoorInformation(doorsymbol, doorlocation);

            return(doorinfo);
        }