public void Execute(UpdaterData data)
        {
            Document         doc  = data.GetDocument();
            List <ElementId> list = data.GetAddedElementIds().ToList();

            list.AddRange(data.GetModifiedElementIds());
            IList <Element> first = (from ElementId id in list
                                     select doc.GetElement(id)).ToList();
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(doc);
            IList <ElementId>      list2        = (from Element pZ in projectZones
                                                   select pZ.get_Id()).ToList();
            Parameter val = (from FamilyInstance pZ in projectZones
                             let param = pZ.LookupParameter("Name")
                                         where param != null
                                         select param).First();
            Definition zoneNameDef = val.get_Definition();

            foreach (Element item in first.Except((IEnumerable <Element>)projectZones))
            {
                BoundingBoxXYZ val2 = item.get_BoundingBox(null);
                if (val2 != null)
                {
                    BoundingBoxIntersectsFilter val3   = new BoundingBoxIntersectsFilter(ToOutline(val2));
                    IList <Element>             source = new FilteredElementCollector(doc, (ICollection <ElementId>)list2).WherePasses(val3).ToElements();
                    IEnumerable <string>        values = from Element zone in source
                                                         let name = zone.get_Parameter(zoneNameDef).AsString()
                                                                    where !string.IsNullOrWhiteSpace(name)
                                                                    select name;
                    string text = string.Join(", ", values);
                    item.LookupParameter("Zone").Set(text);
                }
            }
        }
Exemplo n.º 2
0
        public List <Outline> GetWallsOutlineList()
        {
            List <Outline> wallsOutlineList = new List <Outline>();

            BoundingBoxXYZ bb = m_room.get_BoundingBox(null);

            Outline outline = new Outline(bb.Min, bb.Max);

            BoundingBoxIntersectsFilter roomIntersectionFilter = new BoundingBoxIntersectsFilter(outline);

            FilteredElementCollector wallsCollector
                = new FilteredElementCollector(m_doc)
                  .WhereElementIsNotElementType()
                  .OfCategory(BuiltInCategory.OST_Walls)
                  .OfClass(typeof(Wall))
                  .WherePasses(roomIntersectionFilter);

            foreach (Element wallElem in wallsCollector)
            {
                Wall wallInstance = wallElem as Wall;

                if (wallInstance.LevelId.IntegerValue == m_level.Id.IntegerValue)
                {
                    BoundingBoxXYZ wallBB = wallInstance.get_BoundingBox(m_view);

                    Outline wallOutline = new Outline(wallBB.Min, wallBB.Max);

                    wallsOutlineList.Add(wallOutline);
                }
            }

            return(wallsOutlineList);
        }
Exemplo n.º 3
0
        public List <Outline> GetColumnsOutlineList()
        {
            List <Outline> coulumnsOutlineList = new List <Outline>();

            BoundingBoxXYZ bb = m_room.get_BoundingBox(null);

            Outline outline = new Outline(bb.Min, bb.Max);

            BoundingBoxIntersectsFilter roomIntersectionFilter = new BoundingBoxIntersectsFilter(outline);

            ElementCategoryFilter columnsCategoryfilter           = new ElementCategoryFilter(BuiltInCategory.OST_Columns);
            ElementCategoryFilter structuralColumnsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);

            LogicalOrFilter columnInstancesFilter = new LogicalOrFilter(columnsCategoryfilter, structuralColumnsCategoryfilter);

            FilteredElementCollector columnsCollector
                = new FilteredElementCollector(m_doc)
                  .WhereElementIsNotElementType()
                  .OfClass(typeof(FamilyInstance))
                  .WherePasses(columnInstancesFilter)
                  .WherePasses(roomIntersectionFilter);

            foreach (Element columnElem in columnsCollector)
            {
                FamilyInstance fi = columnElem as FamilyInstance;

                BoundingBoxXYZ columnBB = columnElem.get_BoundingBox(m_view);

                Outline columnOutline = new Outline(columnBB.Min, columnBB.Max);

                coulumnsOutlineList.Add(columnOutline);
            }

            return(coulumnsOutlineList);
        }
Exemplo n.º 4
0
        public List <Outline> GetDoorsOutlineList()
        {
            List <Outline> doorsOutlineList = new List <Outline>();

            BoundingBoxXYZ bb = m_room.get_BoundingBox(null);

            Outline outline = new Outline(bb.Min, bb.Max);

            BoundingBoxIntersectsFilter roomIntersectionFilter = new BoundingBoxIntersectsFilter(outline);

            FilteredElementCollector doorsCollector
                = new FilteredElementCollector(m_doc)
                  .WhereElementIsNotElementType()
                  .OfCategory(BuiltInCategory.OST_Doors)
                  .OfClass(typeof(FamilyInstance))
                  .WherePasses(roomIntersectionFilter);

            foreach (Element doorElem in doorsCollector)
            {
                FamilyInstance doorInstance = doorElem as FamilyInstance;

                if (doorElem.LevelId.IntegerValue == m_level.Id.IntegerValue && doorInstance.Room.Id.IntegerValue == m_room.Id.IntegerValue)
                {
                    BoundingBoxXYZ doorBB = doorInstance.get_BoundingBox(m_view);

                    Outline doorOutline = new Outline(doorBB.Min, doorBB.Max);

                    doorsOutlineList.Add(doorOutline);
                }
            }

            return(doorsOutlineList);
        }
Exemplo n.º 5
0
        protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Reference r           = _activeUIDocument.Selection.PickObject(ObjectType.Element);
            var       element     = _activeDocument.GetElement(r.ElementId);
            var       boundingBox = element.get_BoundingBox(_activeDocument.ActiveView);
            var       outLine     = new Outline(boundingBox.Min, boundingBox.Max);
            var       bbFilter    = new BoundingBoxIntersectsFilter(outLine);
            FilteredElementCollector collector  = new FilteredElementCollector(_activeDocument, _activeDocument.ActiveView.Id);
            ICollection <ElementId>  idsExclude = new List <ElementId>();

            idsExclude.Add(element.Id);
            collector.Excluding(idsExclude).WherePasses(bbFilter);
            int    nCount = 0;
            string report = string.Empty;

            foreach (Element e in collector)
            {
                string name = e.Name;
                report += "\nName = " + name
                          + " Element Id: " + e.Id.ToString();
                nCount++;
            }

            TaskDialog.Show(
                "Bounding Box + View + Exclusion Filter", "Found " + nCount.ToString() + " elements whose bounding box intersects" + report);
            return(Result.Succeeded);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check Element Intersect With Element Selected By BoundingBox
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            Element element = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));

            ExclusionFilter excludedFilter = new ExclusionFilter(new List <ElementId>()
            {
                element.Id
            });
            BoundingBoxXYZ bbxyz   = element.get_BoundingBox(doc.ActiveView);
            Outline        outline = new Outline(bbxyz.Min, bbxyz.Max);
            BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline);
            IList <Element>             eleIntersect    = new FilteredElementCollector(doc)
                                                          .WhereElementIsNotElementType()
                                                          .WherePasses(excludedFilter)
                                                          .WherePasses(intersectFilter).ToElements()
                                                          .Where(x => x.Category.Name != "Cameras")
                                                          .Where(x => !string.IsNullOrEmpty(x.Name)).ToList();
            StringBuilder sb = new StringBuilder();

            if (eleIntersect.Any())
            {
                foreach (Element e in eleIntersect)
                {
                    sb.AppendLine($"Name:{e.Name}-Category:{e.Category.Name}-Id:{e.Id}");
                }
            }
            MessageBox.Show($"Element Intersect : \n{sb}");
            return(Result.Succeeded);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get all furniture elements inside a room.
        /// </summary>
        /// <param name="room"></param>
        /// <returns>
        /// Returns a List with those elements.
        /// </returns>
        private static List <string> GetFurniture(Room room)
        {
            Document       doc                 = room.Document;
            BoundingBoxXYZ boundingBox         = room.get_BoundingBox(null);
            Outline        outline             = new Outline(boundingBox.Min, boundingBox.Max);
            BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);

            FilteredElementCollector collector
                = new FilteredElementCollector(doc)
                  .WhereElementIsNotElementType()
                  .WhereElementIsViewIndependent()
                  .OfClass(typeof(FamilyInstance))
                  .WherePasses(filter);

            int           roomid = room.Id.IntegerValue;
            List <string> elementsInsideTheRoom = new List <string>();

            foreach (FamilyInstance instance in collector)
            {
                if (instance.Room != null)
                {
                    if (instance.Room.Id.IntegerValue.Equals(roomid))
                    {
                        elementsInsideTheRoom.Add(instance.Name);
                    }
                }
            }
            return(elementsInsideTheRoom);
        }
Exemplo n.º 8
0
        //回傳有碰到ele的BoundingBox的牆或版
        public IList <Element> GetBoundingBoxIntersectsElements(Element ele, String elementType)
        {
            Document doc = ele.Document;
            //--去除ele本身過濾器
            List <ElementId> excludedElementID = new List <ElementId>();

            excludedElementID.Add(ele.Id);
            ExclusionFilter excludedFilter = new ExclusionFilter(excludedElementID);
            //--邊界框相交過濾器
            BoundingBoxXYZ boundingBoxOfEle             = ele.get_BoundingBox(doc.ActiveView);
            Outline        outline                      = ExtendBoundingBox(boundingBoxOfEle);
            BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline);

            //--建立圖元過濾器
            FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);

            switch (elementType)
            {
            case "floor":
                collector.OfClass(typeof(Floor)).WhereElementIsNotElementType().WherePasses(excludedFilter).WherePasses(intersectFilter);
                break;

            case "wall":
                collector.OfClass(typeof(Wall)).WhereElementIsNotElementType().WherePasses(intersectFilter);
                break;

            default:
                MessageBox.Show("依照設定參數回傳有碰到ele的牆或版錯誤", "錯誤訊息");
                break;
            }

            IList <Element> intersectElement = collector.ToElements();

            return(intersectElement);
        }
Exemplo n.º 9
0
        public static IList <IList <BoundarySegment> > GetFurniture(Room room)
        {
            BoundingBoxXYZ bb      = room.get_BoundingBox(null);
            Outline        outline = new Outline(bb.Min, bb.Max);

            bb.Transform.ScaleBasis(1.2);
            BoundingBoxIntersectsFilter filter
                = new BoundingBoxIntersectsFilter(outline);

            Document doc = room.Document;

            // Todo: add category filters and other
            // properties to narrow down the results

            FilteredElementCollector collector
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(FamilyInstance))
                  .WhereElementIsElementType()

                  .WherePasses(filter);

            string roomname = room.Name;

            //List<Element> result = new List<Element>();

            //foreach (FamilyInstance fi in collector)
            //{
            //    result.Add(fi);
            //}

            var result = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

            return(result);
        }
        public static IEnumerable <T> FindIntersectingElementByPosition <T>(Element element) where T : Element
        {
            IEnumerable <T> collected = null;

            try
            {
                var doc     = element.Document;
                var box     = element.get_BoundingBox(null);
                var outline = new Outline(box.Min, box.Max);
                var filter  = new BoundingBoxIntersectsFilter(outline);
                collected = new FilteredElementCollector(doc).WherePasses(filter).OfType <T>();
            }

            catch (ArgumentException e)
            {
                LoggingService.LogError($"Unable to capture intersecting elements using this types of element: {element.Category.Name}", e);
                return(collected);
            }

            catch (Exception e)
            {
                LoggingService.LogError($"Unable to capture any elements because of a fatal error ", e);
                return(collected);
            }

            return(collected);
        }
Exemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            Autodesk.Revit.UI.Selection.Selection selElement = uidoc.Selection;
            ICollection <ElementId> elementIds = selElement.GetElementIds();

            foreach (ElementId elementId in elementIds)
            {
                Element        elem = doc.GetElement(elementId);
                BoundingBoxXYZ bbx  = elem.get_BoundingBox(null);
                //從元件取得「邊界長方體」(包覆元件邊界的長方體,如果元件本身是長方體,就會完全包覆)
                //OutLine是一條線,此處等於直接拿包覆長方體的對角線來定義它
                Outline outline = new Outline(bbx.Min, bbx.Max);//Min及Max各是一個點,都能存取XYZ座標
                BoundingBoxIntersectsFilter filterIntersection = new BoundingBoxIntersectsFilter(outline);
                //這個過濾器會取得「所有和這個BoundingBox相交的BoundingBox,並且傳回其所代表之元件」
                IList <Element> Intersects =
                    new FilteredElementCollector(doc).WherePasses(filterIntersection).WhereElementIsNotElementType().ToElements();

                StringBuilder sb = new StringBuilder("這個元件是" + elem.Category.Name + ":" + elem.Id + ":" + elem.Name + ",");
                sb.AppendLine("和它相鄰的元件有:");

                foreach (Element eleFiltered in Intersects)
                {
                    try //這邊需要用try包起來,因為我發現有些Element似乎是沒有Category.Name的,這會發生空參考錯誤
                    {
                        sb.AppendLine(eleFiltered.Category.Name + ":" + eleFiltered.Id + ":" + eleFiltered.Name);
                        //印出相鄰元件資訊
                    }
                    catch (Exception ex)
                    { }
                }
                sb.AppendLine("=======");
                MessageBox.Show(sb.ToString());
            } //end foreach
        }     //end fun
Exemplo n.º 12
0
        private List <FamilyInstance> GetDevice(Document doc, Element wall, BuiltInCategory category)
        {
            BoundingBoxIntersectsFilter filter      = Filter(wall, doc);
            List <FamilyInstance>       devicesList = new List <FamilyInstance>();

            if (filter != null)
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc)
                                                     .OfClass(typeof(FamilyInstance))
                                                     .OfCategory(category)
                                                     .WherePasses(filter);

                string temp = string.Empty;
                foreach (FamilyInstance instance in collector)
                {
                    // if (instance.LevelId == selectedLevel.Id)
                    {
                        devicesList.Add(instance);
                        temp += instance.Id + " " + instance.Name + "\n";
                    }
                }

                // if (!string.IsNullOrEmpty(temp))
                // TaskDialog.Show("Selected Devices", temp);
            }

            return(devicesList);
        }
Exemplo n.º 13
0
        private IList <Element> GetElementsOnLevels(Document targetDoc, BuiltInCategory targetCategory, Level targetLowerLevel, Level targetUpperLevel)
        {
            //if target lower level is null, we will check everything lower than the first level
            //if target upper level is null, we will check everything upper than the last level

            IList <Element> elementList = new List <Element>();

            double minElevation = -99999;
            double maxElevation = 99999;

            if (targetLowerLevel != null)
            {
                minElevation = targetLowerLevel.Elevation;
            }

            if (targetUpperLevel != null)
            {
                maxElevation = targetUpperLevel.Elevation;
            }

            BoundingBoxXYZ selectBox = new BoundingBoxXYZ();

            XYZ minPoint = new XYZ(-99999, -99999, minElevation + Utils.ConvertM.cmToFeet(1));
            XYZ maxPoint = new XYZ(99999, 99999, maxElevation - Utils.ConvertM.cmToFeet(1));

            double temMin = Utils.ConvertM.feetToM(minPoint.Z);
            double temMax = Utils.ConvertM.feetToM(maxPoint.Z);

            Outline selectOutline = new Outline(minPoint, maxPoint);
            BoundingBoxIntersectsFilter bbInsideFilter = new BoundingBoxIntersectsFilter(selectOutline);

            elementList = new FilteredElementCollector(targetDoc).OfCategory(targetCategory).WherePasses(bbInsideFilter).ToList();

            return(elementList);
        }
Exemplo n.º 14
0
        public unsafe static IList <Element> GetIntersectBoundingBoxElems(Document doc, Element elem)
        {
            IntPtr ptr = new IntPtr();
            void * pv  = ptr.ToPointer();

            BoundingBoxXYZ bndBx = elem.get_Geometry
                                       (new Options {
                IncludeNonVisibleObjects = true
            }).GetBoundingBox();

            BoundingBoxIntersectsFilter bndBxFlt =
                new BoundingBoxIntersectsFilter(new Outline(bndBx.Min, bndBx.Max), 1);

            IList <ElementFilter> strElemFilters =
                new List <ElementFilter> {
                new ElementCategoryFilter(BuiltInCategory.OST_Columns),
                new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming),
                new ElementCategoryFilter(BuiltInCategory.OST_Floors),
                new ElementCategoryFilter(BuiltInCategory.OST_Walls)
            };

            LogicalOrFilter anyStrElemFlt =
                new LogicalOrFilter(strElemFilters);

            IList <Element> elements = new FilteredElementCollector(doc)
                                       .WherePasses(bndBxFlt)
                                       .WherePasses(anyStrElemFlt)
                                       .ToElements()
                                       .ToList();

            return(elements);
        }
Exemplo n.º 15
0
        //----------------------------------------------------------
        public static List <Element> intersection_framing(Document doc, Element element)
        {
            List <Element> elements = new List <Element>();

            try
            {
                BoundingBoxXYZ bb      = element.get_BoundingBox(doc.ActiveView);
                Outline        outline = new Outline(bb.Min, bb.Max);
                BoundingBoxIntersectsFilter bbfilter   = new BoundingBoxIntersectsFilter(outline);
                FilteredElementCollector    collectors = new FilteredElementCollector(doc, doc.ActiveView.Id);
                ICollection <ElementId>     idsExclude = new List <ElementId>();
                idsExclude.Add(element.Id);
                var collector = collectors.Excluding(idsExclude).WherePasses(bbfilter).ToElements();

                foreach (Element ele in collector)
                {
                    if (ele.LookupParameter("Name") != null && ele.LookupParameter("LevelPart") != null)
                    {
                        if (ele.Category.Name != "Structural Framing" && ele.Category.Name != "Floors")
                        {
                            elements.Add(ele);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(elements);
        }
        public IList <FamilyInstance> FindConn(Document doc, FamilyInstance instance)
        {
            IList <FamilyInstance> list = new List <FamilyInstance>();
            var Frame = doc.GetElement((from x in instance.GetSubComponentIds() where doc.GetElement(x).Name.Contains("Frame") select x).First()) as FamilyInstance;
            List <FamilyInstance> source = new List <FamilyInstance>();

            foreach (var i in Frame.GetSubComponentIds())
            {
                FamilyInstance gh = doc.GetElement(i) as FamilyInstance;
                source.Add(gh);
            }
            foreach (FamilyInstance familyInstance in source)
            {
                BoundingBoxXYZ boundingBoxXYZ       = familyInstance.get_BoundingBox(doc.ActiveView);
                Outline        outline              = new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max);
                BoundingBoxIntersectsFilter filter  = new BoundingBoxIntersectsFilter(outline);
                BoundingBoxIsInsideFilter   filter2 = new BoundingBoxIsInsideFilter(outline);
                LogicalOrFilter             filter3 = new LogicalOrFilter(filter, filter2);
                FilteredElementCollector    filteredElementCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);
                ICollection <ElementId>     ids = filteredElementCollector.OfClass(typeof(FamilyInstance)).WherePasses(filter3).ToElementIds();
                IList <Solid>    list2          = this.AllSolids(familyInstance);
                List <ElementId> nestedIds      = this.GetNestedIds(doc, ids);
                foreach (Solid solid in list2)
                {
                    IList <FamilyInstance> fromList = this.IntersectPart(doc, solid, nestedIds);
                    this.AddListFamilyInstance(fromList, list);
                }
            }
            return(list);
        }
Exemplo n.º 17
0
            private static int[, ,] _record = new int[4, 2, _numLevel];              //Global Recorder : [X1/X2/Y1/Y2,W27/W30,levels]

            private static void GetIntersectBeams()
            {
                FilteredElementCollector    tempCollector = new FilteredElementCollector(_doc);
                ElementStructuralTypeFilter BeamFilter    = new ElementStructuralTypeFilter(StructuralType.Beam);

                _intersectedBeams.Clear();
                //Do not consider lower beams
                XYZ left = new XYZ(_columnBox.Min.X - ErrorCTRL_BoundingBox,
                                   _columnBox.Min.Y - ErrorCTRL_BoundingBox, 0.5 * (_myLevel.GetElevation(_bottom_floor) + _myLevel.GetElevation(_bottom_floor + 1)));
                XYZ right = new XYZ(_columnBox.Max.X + ErrorCTRL_BoundingBox,
                                    _columnBox.Max.Y + ErrorCTRL_BoundingBox, _columnBox.Max.Z + ErrorCTRL_BoundingBox);
                Outline outline = new Outline(left, right);
                BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline);

                tempCollector.WherePasses(bbfilter).WherePasses(BeamFilter);
                foreach (FamilyInstance beam in tempCollector)
                {
                    if (beam.StructuralMaterialType == StructuralMaterialType.Steel)
                    {
                        _intersectedBeams.Add(beam);
                    }
                    else
                    {
                        _abandonWriter.WriteAbandonment(beam, AbandonmentTable.SteelJoint_BeamNotSteel);
                    }
                }
            }
Exemplo n.º 18
0
        public static IList <Element> GetWallsIntersectBoundingBox(Document doc, Element elem)
        {
            ExclusionFilter exclusionFilter =
                new ExclusionFilter(new List <ElementId> {
                elem.Id
            });

            ElementParameterFilter elementParameterFilter =
                new ElementParameterFilter(ParameterFilterRuleFactory
                                           .CreateEqualsRule(new ElementId(BuiltInParameter.WALL_BASE_CONSTRAINT), elem.LevelId), true);

            BoundingBoxXYZ bndBx = elem.get_Geometry
                                       (new Options {
                IncludeNonVisibleObjects = true
            }).GetBoundingBox();

            BoundingBoxIntersectsFilter bndBxFlt =
                new BoundingBoxIntersectsFilter(new Outline(bndBx.Min, bndBx.Max), 0.1);

            IList <Element> elements = new FilteredElementCollector(doc)
                                       .WherePasses(exclusionFilter)
                                       .OfClass(typeof(Wall))
                                       .WherePasses(bndBxFlt)
                                       .WherePasses(elementParameterFilter)
                                       .ToElements()
                                       .ToList();

            return(elements);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Detects the collision or clash between two elements. By analyzing the geometry intersection of an element (Element A) against other element (Element B)
        /// </summary>
        /// <param name="doc">Active revit document</param>
        /// <param name="geometryElement">Geometry element from which the intersection will be verified (Element B)</param>
        /// <param name="element">Element to verify the presence of intersection (Element A)</param>
        /// <returns>A Boolean flag that indicates whether or not there is a clash between elements. True = Clash detected. False = No clash detected</returns>
        public static bool getClashWithSolid(Document doc, GeometryElement geometryElement, Element element)
        {
            // Elements list, This list contains the Id's of element A
            List <ElementId> elementsList = new List <ElementId>();

            elementsList.Add(element.Id);

            bool clashOutputFlag = false;

            //Look for each solid in linked model
            foreach (GeometryObject geomObj in geometryElement)
            {
                // If solid is present we perform a solid intersection filter.
                // and later, perform a filter iteration with the element to clash (Element A vs Element B)
                if (geomObj is Solid)
                {
                    Solid solidObject = geomObj as Solid;
                    ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(solidObject);
                    FilteredElementCollector     collector = new FilteredElementCollector(doc, elementsList).WherePasses(elementIntersectsSolidFilter);

                    // If collector count is zero, this means that Solid intersection can't be possible with the given element (ie: Fabrication Parts).
                    if (collector.Count() == 0 && !fabparts.Contains(element.Category.Id))
                    {
                        BoundingBoxXYZ bbox    = geometryElement.GetBoundingBox();
                        Outline        outline = new Outline(bbox.Min, bbox.Max);
                        BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(outline);
                        collector = new FilteredElementCollector(doc, elementsList).WherePasses(bbFilter);
                    }

                    foreach (var item in collector)
                    {
                        clashOutputFlag = true;
                        break;
                    }
                }

                // If a Geometry instance is present. We implement a BoundingBox intersect filter over the Geometry of element A
                // and later, perform a Filter iteration with the element to clash (Element A vs Element B)
                if (geomObj is GeometryInstance)
                {
                    BoundingBoxXYZ bbox    = geometryElement.GetBoundingBox();
                    Outline        outline = new Outline(bbox.Min, bbox.Max);
                    BoundingBoxIntersectsFilter bbFilter  = new BoundingBoxIntersectsFilter(outline);
                    FilteredElementCollector    collector = new FilteredElementCollector(doc, elementsList).WherePasses(bbFilter);
                    foreach (var item in collector)
                    {
                        clashOutputFlag = true;
                        break;
                    }
                }

                if (!clashOutputFlag)
                {
                    break;
                }
            }

            return(clashOutputFlag);
        }
Exemplo n.º 20
0
        private IList <Element> GetFilteredElementsFromView(Document doc, View view)
        {
            FilteredElementCollector val    = new FilteredElementCollector(doc, view.get_Id());
            IList <Element>          levels = GetLevels(doc);

            string[] array = new string[levels.Count];
            for (int i = 0; i < levels.Count; i++)
            {
                array[i] = levels[i].get_Name();
            }
            affectedRangeForm = new AffectedViewRangeForm(array, doc.GetUnits());
            affectedRangeForm.ShowDialog();
            if (affectedRangeForm.DialogResult != DialogResult.OK)
            {
                return(null);
            }
            int    topLevelIndex     = affectedRangeForm.TopLevelIndex;
            int    bottomLevelIndex  = affectedRangeForm.BottomLevelIndex;
            double topOffset         = affectedRangeForm.TopOffset;
            double bottomOffset      = affectedRangeForm.BottomOffset;
            bool   isTopUnlimited    = affectedRangeForm.IsTopUnlimited;
            bool   isBottomUnlimited = affectedRangeForm.IsBottomUnlimited;
            bool   excludeColumns    = affectedRangeForm.ExcludeColumns;
            double num;

            if (isTopUnlimited)
            {
                num = 1.7976931348623157E+308;
            }
            else
            {
                double num2 = levels[topLevelIndex].LookupParameter("Elevation").AsDouble();
                num = num2 + bottomOffset;
            }
            double num3;

            if (isBottomUnlimited)
            {
                num3 = -1.7976931348623157E+308;
            }
            else
            {
                double num4 = levels[bottomLevelIndex].LookupParameter("Elevation").AsDouble();
                num3 = num4 + bottomOffset;
            }
            XYZ     val2 = new XYZ(-1.7976931348623157E+308, -1.7976931348623157E+308, num3);
            XYZ     val3 = new XYZ(1.7976931348623157E+308, 1.7976931348623157E+308, num);
            Outline val4 = new Outline(val2, val3);
            BoundingBoxIntersectsFilter val5 = new BoundingBoxIntersectsFilter(val4);

            val.WherePasses(val5);
            if (excludeColumns)
            {
                ElementCategoryFilter val6 = new ElementCategoryFilter(-2001330, true);
                val.WherePasses(val6);
            }
            return(val.ToElements());
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            bool test_strange_intersect_result = true;

            if (test_strange_intersect_result)
            {
                TestIntersect(doc);
                return(Result.Succeeded);
            }

            Element e = Util.SelectSingleElement(
                uidoc, "a junction box");

            BoundingBoxXYZ bb = e.get_BoundingBox(null);

            Outline outLne = new Outline(bb.Min, bb.Max);

            // Use a quick bounding box filter - axis aligned

            ElementQuickFilter fbb
                = new BoundingBoxIntersectsFilter(outLne);

            FilteredElementCollector conduits
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(Conduit))
                  .WherePasses(fbb);

            // How many elements did we find?

            int nbb = conduits.GetElementCount();

            // Use a slow intersection filter - exact results

            ElementSlowFilter intersect_junction
                = new ElementIntersectsElementFilter(e);

            conduits = new FilteredElementCollector(doc)
                       .OfClass(typeof(Conduit))
                       .WherePasses(intersect_junction);

            // How many elements did we find?

            int nintersect = conduits.GetElementCount();

            Debug.Assert(nintersect <= nbb,
                         "expected element intersection to be stricter"
                         + "than bounding box containment");

            return(Result.Succeeded);
        }
Exemplo n.º 22
0
        public List <IntersectionMepCurve> GetIntersections()
        {
            linkedDocInstance = DocumentUtils.ChooseLinkedDoc(doc);
            if (linkedDocInstance == null)
            {
                return(new List <IntersectionMepCurve>());
            }
            else
            {
                var       progress = new UI.ProgressBar("Поиск пересечений...", hosts.Count());
                Transform tr       = DocumentUtils.GetCorrectionTransform(linkedDocInstance);
                List <IntersectionMepCurve> intersectionList = new List <IntersectionMepCurve>();
                foreach (HostObject host in hosts)
                {
                    List <Face> hostFaces = GeometryUtils.GetFaces(host);
                    if (hostFaces.Count > 0)
                    {
                        BoundingBoxXYZ bb                  = host.get_BoundingBox(null);
                        Outline        outline             = new Outline(tr.OfPoint(bb.Min), tr.OfPoint(bb.Max));
                        BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);

                        List <MEPCurve> meps = new FilteredElementCollector(linkedDoc)
                                               .OfClass(typeof(MEPCurve))
                                               .WherePasses(filter)
                                               .Cast <MEPCurve>()
                                               .ToList();

                        foreach (MEPCurve m in meps)
                        {
                            Curve mepCurve = GeometryUtils.FindDuctCurve(m.ConnectorManager);
                            if (mepCurve != null)
                            {
                                XYZ[] interPts = (from wallFace in hostFaces select FindFaceIntersection(mepCurve, wallFace)).ToArray();
                                if (interPts.Any(x => x != null))
                                {
                                    XYZ pt = interPts.First(x => x != null);
                                    try
                                    {
                                        IntersectionMepCurve i = new IntersectionMepCurve(host, m, pt, linkedDocInstance);
                                        intersectionList.Add(i);
                                    }
                                    catch (NotImplementedException)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    progress.StepUp();
                }
                progress.Close();
                return(intersectionList);
            }
        }
Exemplo n.º 23
0
        //(9.03,10.13,0) --> (-14.59,10.13,0)
        //(-14.59,10.13,0) --> (-14.59,1.93,0)
        //(-14.59,1.93,0) --> (-2.45,1.93,0)
        //(-2.45,1.93,0) --> (-2.45,-3.98,0)
        //(-2.45,-3.98,0) --> (9.03,-3.98,0)
        //(9.03,-3.98,0) --> (9.03,10.13,0)
        //(0.98,-0.37,0) --> (0.98,1.93,0)
        //(0.98,1.93,0) --> (5.57,1.93,0)
        //(5.57,1.93,0) --> (5.57,-0.37,0)
        //(5.57,-0.37,0) --> (0.98,-0.37,0)

        //(9.03,10.13) --> (-14.59,10.13)
        //(-14.59,10.13) --> (-14.59,1.93)
        //(-14.59,1.93) --> (-2.45,1.93)
        //(-2.45,1.93) --> (-2.45,-3.98)
        //(-2.45,-3.98) --> (9.03,-3.98)
        //(9.03,-3.98) --> (9.03,10.13)
        //(0.98,-0.37) --> (0.98,1.93)
        //(0.98,1.93) --> (5.57,1.93)
        //(5.57,1.93) --> (5.57,-0.37)
        //(5.57,-0.37) --> (0.98,-0.37)

        //Room Rooms <212639 Room 1> has 2 loops:
        //  0: (2753,3087), (-4446,3087), (-4446,587), (-746,587), (-746,-1212), (2753,-1212)
        //  1: (298,-112), (298,587), (1698,587), (1698,-112)
        #endregion // Get room boundary loops

        #region Get furniture contained in given room
        /// <summary>
        /// Return the element ids of all furniture and
        /// equipment family instances contained in the
        /// given room.
        /// </summary>
        static List <Element> GetFurniture(Room room)
        {
            BoundingBoxXYZ bb = room.get_BoundingBox(null);

            Outline outline = new Outline(bb.Min, bb.Max);

            BoundingBoxIntersectsFilter filter
                = new BoundingBoxIntersectsFilter(outline);

            Document doc = room.Document;

            // Todo: add category filters and other
            // properties to narrow down the results

            // what categories of family instances
            // are we interested in?

            BuiltInCategory[] bics = new BuiltInCategory[] {
                BuiltInCategory.OST_Furniture,
                BuiltInCategory.OST_PlumbingFixtures,
                BuiltInCategory.OST_SpecialityEquipment
            };

            LogicalOrFilter categoryFilter
                = new LogicalOrFilter(bics
                                      .Select <BuiltInCategory, ElementFilter>(
                                          bic => new ElementCategoryFilter(bic))
                                      .ToList <ElementFilter>());

            FilteredElementCollector familyInstances
                = new FilteredElementCollector(doc)
                  .WhereElementIsNotElementType()
                  .WhereElementIsViewIndependent()
                  .OfClass(typeof(FamilyInstance))
                  .WherePasses(categoryFilter)
                  .WherePasses(filter);

            int roomid = room.Id.IntegerValue;

            List <Element> a = new List <Element>();

            foreach (FamilyInstance fi in familyInstances)
            {
                if (null != fi.Room &&
                    fi.Room.Id.IntegerValue.Equals(roomid))
                {
                    Debug.Assert(fi.Location is LocationPoint,
                                 "expected all furniture to have a location point");

                    a.Add(fi);
                }
            }
            return(a);
        }
Exemplo n.º 24
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get UIdocument
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            //Get Document
            Document doc = uidoc.Document;

            try
            {
                //Get elements of Category
                var eles = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)
                           .WhereElementIsNotElementType()
                           .ToElements();

                using (var tran = new Transaction(doc, "Calculator Formwork Area for Element"))
                {
                    tran.Start();
                    foreach (var ele in eles)
                    {
                        //Get BoundingBox from Element
                        BoundingBoxXYZ boundingBox = ele.get_BoundingBox(null);
                        //Get Outline
                        Outline outline = new Outline(boundingBox.Min, boundingBox.Max);
                        BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);
                        //BoundingBoxIntersectsFilter invertFilter = new BoundingBoxIntersectsFilter(outline,true);

                        var eleIntersect = new FilteredElementCollector(doc)
                                           .WhereElementIsNotElementType()
                                           .WherePasses(filter)
                                           .ToElements();

                        foreach (var item in eleIntersect)
                        {
                            var joined = JoinGeometryUtils.AreElementsJoined(doc, ele, item);
                            if (joined == true)
                            {
                                JoinGeometryUtils.UnjoinGeometry(doc, ele, item);
                                //JoinGeometryUtils.JoinGeometry(doc, ele, item);
                                //JoinGeometryUtils.SwitchJoinOrder(doc, ele, item);
                            }
                            JoinGeometryUtils.JoinGeometry(doc, ele, item);
                            //JoinGeometryUtils.SwitchJoinOrder(doc, ele, item);
                        }
                    }
                    tran.Commit();
                }
                return(Result.Succeeded);
            }
            catch (Exception exception)
            {
                message = exception.Message;
                return(Result.Failed);
            }
        }
Exemplo n.º 25
0
        private static int DFS(IList <ElementId> columnIds, IList <ElementId> beamIds, out int num_IndividualColumn)
        {
            num_IndividualColumn = 0;
            List <Element>       columns    = (new FilteredElementCollector(_doc, columnIds)).OfClass(typeof(FamilyInstance)).ToList();
            List <Element>       beams      = (new FilteredElementCollector(_doc, beamIds)).OfClass(typeof(FamilyInstance)).ToList();
            int                  k          = 0;
            LinkedList <Element> open       = new LinkedList <Element>();
            HashSet <ElementId>  discovered = new HashSet <ElementId>();

            foreach (Element column in columns)
            {
                if (!discovered.Contains(column.Id))
                {
                    ++k;
                    open.AddFirst(column);
                    discovered.Add(column.Id);
                    while (open.Count != 0)
                    {
                        Element e = open.First();
                        open.RemoveFirst();
                        BoundingBoxXYZ bbXYZ    = e.get_BoundingBox(_doc.ActiveView);
                        XYZ            deltaXYZ = new XYZ(ErrorCTRL_BB, ErrorCTRL_BB, _maxBB.Max.Z);
                        BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(new Outline(bbXYZ.Min - deltaXYZ, bbXYZ.Max + deltaXYZ));
                        FilteredElementCollector    fec      = null;
                        if (((FamilyInstance)e).StructuralUsage == StructuralInstanceUsage.Column)
                        {
                            fec = new FilteredElementCollector(_doc, beamIds);
                            fec.WherePasses(bbFilter);
                            if (fec.Count() == 0)
                            {
                                ++num_IndividualColumn;
                                --k;
                            }
                        }
                        else
                        {
                            fec = new FilteredElementCollector(_doc, columnIds);
                            fec.WherePasses(bbFilter);
                        }

                        foreach (Element intersectedEle in fec)
                        {
                            if (!discovered.Contains(intersectedEle.Id))
                            {
                                open.AddFirst(intersectedEle);
                                discovered.Add(intersectedEle.Id);
                            }
                        }
                    }
                }
            }
            return(k);
        }
Exemplo n.º 26
0
        private BoundingBoxIntersectsFilter Filter(Room room)
        {
            BoundingBoxXYZ box = room.get_BoundingBox(null);

            if (box != null)
            {
                Outline outline = new Outline(box.Min, box.Max);
                BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);
                return(filter);
            }
            return(null);
        }
Exemplo n.º 27
0
        private static int DFS(IList<ElementId> columnIds, IList<ElementId> beamIds, out int num_IndividualColumn)
        {
            num_IndividualColumn = 0;
            List<Element> columns = (new FilteredElementCollector(_doc, columnIds)).OfClass(typeof(FamilyInstance)).ToList();
            List<Element> beams = (new FilteredElementCollector(_doc, beamIds)).OfClass(typeof(FamilyInstance)).ToList();
            int k = 0;
            LinkedList<Element> open = new LinkedList<Element>();
            HashSet<ElementId> discovered = new HashSet<ElementId>();
            foreach(Element column in columns)
            {
                if (!discovered.Contains(column.Id))
                {
                    ++k;
                    open.AddFirst(column);
                    discovered.Add(column.Id);
                    while (open.Count != 0)
                    {
                        Element e = open.First();
                        open.RemoveFirst();
                        BoundingBoxXYZ bbXYZ = e.get_BoundingBox(_doc.ActiveView);
                        XYZ deltaXYZ = new XYZ(ErrorCTRL_BB, ErrorCTRL_BB, _maxBB.Max.Z);
                        BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(new Outline(bbXYZ.Min - deltaXYZ, bbXYZ.Max + deltaXYZ));
                        FilteredElementCollector fec = null;
                        if (((FamilyInstance)e).StructuralUsage == StructuralInstanceUsage.Column)
                        {
                            fec = new FilteredElementCollector(_doc, beamIds);
                            fec.WherePasses(bbFilter);
                            if (fec.Count() == 0)
                            {
                                ++num_IndividualColumn;
                                --k;
                            }
                        }
                        else
                        {
                            fec = new FilteredElementCollector(_doc, columnIds);
                            fec.WherePasses(bbFilter);
                        }

                        foreach (Element intersectedEle in fec)
                        {
                            if (!discovered.Contains(intersectedEle.Id))
                            {
                                open.AddFirst(intersectedEle);
                                discovered.Add(intersectedEle.Id);
                            }
                        }
                    }
                }
            }
            return k;
        }
Exemplo n.º 28
0
        private BoundingBoxIntersectsFilter Filter(Element wall, Document doc)
        {
            BoundingBoxXYZ box = wall.get_BoundingBox(null);

            if (box != null)
            {
                // TaskDialog.Show("BoundingBox", box.Min.ToString());
                Outline outline = new Outline(box.Min, box.Max);
                BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(outline);
                return(filter);
            }
            return(null);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Gets the elements which intersects with input element
        /// </summary>
        /// <param name="doc">Acitve Revit Document</param>
        /// <param name="activeView">Active View</param>
        /// <param name="element">Input element for bounding box</param>
        /// <returns>List of elements that intersects with input element</returns>
        public static IList <Element> GetBouindingBoxIntersect(Document doc, View activeView, Element element)
        {
            BoundingBoxXYZ boundingBox = element.get_BoundingBox(activeView);
            Outline        outline     = new Outline(boundingBox.Min, boundingBox.Max);

            BoundingBoxIntersectsFilter ıntersectsFilter = new BoundingBoxIntersectsFilter(outline);

            // Apply bounding box filter to the Filtered Element Collector
            // This filter collect structural framings which pass the filter and convert to the element
            IList <Element> intersects = new FilteredElementCollector(doc)
                                         .OfCategory(BuiltInCategory.OST_StructuralFraming).WherePasses(ıntersectsFilter).ToElements();

            return(intersects);
        }
Exemplo n.º 30
0
        private List <int> FindMass(AreaProperties ap)
        {
            List <int> massIds = new List <int>();

            try
            {
                Outline outline = new Outline(minXYZ, maxXYZ);
                BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline);
                BoundingBoxIsInsideFilter   insideFilter    = new BoundingBoxIsInsideFilter(outline);
                LogicalOrFilter             orFilter        = new LogicalOrFilter(intersectFilter, insideFilter);

                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_Mass);

                IList <Element> elements = collector.WherePasses(orFilter).ToElements();

                foreach (Element element in elements)
                {
#if RELEASE2015 || RELEASE2016 || RELEASE2017
                    Parameter parameter = element.LookupParameter("Building Function");
#else
                    Parameter parameter = element.get_Parameter("Building Function");
#endif

                    if (null != parameter)
                    {
                        MassProperties mp = new MassProperties(element);
                        if (mp.GrossFloorArea != 0 && null != mp.Centroid)
                        {
                            if (null != ap.BaseFace.Project(mp.Centroid))
                            {
                                mp.AreaId      = ap.AreaId;
                                mp.PlotCode    = ap.PlotCode;
                                mp.DistricCode = ap.DistricCode;
                                if (!massDictionary.ContainsKey(mp.MassId))
                                {
                                    massDictionary.Add(mp.MassId, mp);
                                }
                                massIds.Add(mp.MassId);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find mass instances within an area object.\n" + ex.Message, "FARCacalculator:FindMass", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(massIds);
        }
Exemplo n.º 31
0
        public static void joinGeoByTwoCategories(Document doc, BuiltInCategory firstCategory, BuiltInCategory secondCategory)
        {
            FilteredElementCollector coll = new FilteredElementCollector(doc);
            // 篩選條件牆的篩選器
            ElementCategoryFilter filterFirstCategory   = new ElementCategoryFilter(firstCategory);
            IList <Element>       FirstCategoryElements = coll.WherePasses(filterFirstCategory)
                                                          .WhereElementIsNotElementType().ToElements();

            //因為元件接合要做寫入改動,因此要將它放入交易
            //針對所有元件作自動接合
            foreach (Element firstElement in FirstCategoryElements)
            {
                BoundingBoxXYZ bbx = firstElement.get_BoundingBox(null);
                //從第一元件取得「邊界長方體」(包覆元件邊界的長方體,如果元件本身是長方體,就會完全包覆)
                //OutLine是一條線,此處等於直接拿包覆長方體的對角線來定義它
                Outline outline = new Outline(bbx.Min, bbx.Max);//Min及Max各是一個點,都能存取XYZ座標
                BoundingBoxIntersectsFilter filterIntersection = new BoundingBoxIntersectsFilter(outline);
                //這個過濾器會取得「所有和這個BoundingBox相交的BoundingBox,並且傳回其所代表之元件」
                ElementCategoryFilter filterSecondCategory = new ElementCategoryFilter(secondCategory);
                //然後在相交元件當中,我只想先處理第一類別與第二類別的相交,所以需要再一個篩選器
                LogicalAndFilter andfilter = new LogicalAndFilter(filterIntersection, filterSecondCategory); //用交集篩選器將它們組合起來

                IList <Element> adjacents = new FilteredElementCollector(doc).WherePasses(andfilter).
                                            WhereElementIsNotElementType().ToElements();
                //以上一行選取所有和第一元件相鄰,而且屬於第二類別的元件,把整個doc放進Collector後再濾出通過篩選器的元件
                foreach (Element secondElement in adjacents)
                {
                    //MessageBox.Show(secondElement.Id + "\n" + secondElement.Category.Name); //debug
                    Transaction trans = new Transaction(doc);
                    try
                    {
                        trans.Start("join");                                                               //開始交易(接合)
                        if (JoinGeometryUtils.AreElementsJoined(doc, firstElement, secondElement) == true) //如果兩個元件已接合
                        {
                            JoinGeometryUtils.UnjoinGeometry(doc, firstElement, secondElement);            //先解除接合,因為我假設它不是我要的結果
                        }
                        //以上那個動作有點近似我們在Revit裡頭除了「接合」、「取消接合」以外,也可以「改變接合順序」
                        JoinGeometryUtils.JoinGeometry(doc, firstElement, secondElement); //再重新接合,但原本就處於未接合的元件也會被接合
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.ToString());
                    }
                    finally //這裡刻意讓finally陳述句登場,只是強調無論如何都要做交易的commit
                    {
                        trans.Commit();
                    }
                } //end inner foreach
            }     //end outer foreach
        }         //end fun
Exemplo n.º 32
0
            public static bool Recognization(Floor slab)
            {
                _slab = slab;
                XYZ minAdj = new XYZ(-ErrorCTRL_SlabBB, -ErrorCTRL_SlabBB, -ErrorCTRL_SlabBB);
                XYZ maxAdj = new XYZ(ErrorCTRL_SlabBB, ErrorCTRL_SlabBB, -ErrorCTRL_SlabBB);
                BoundingBoxXYZ bbXYZ = slab.get_BoundingBox(_doc.ActiveView);
                BoundingBoxIntersectsFilter bbif =
                    new BoundingBoxIntersectsFilter(new Outline(bbXYZ.Min + minAdj, bbXYZ.Max + maxAdj));
                if ((new FilteredElementCollector(_doc)).WherePasses(bbif).
                    WherePasses(new ElementStructuralTypeFilter(StructuralType.Beam)).Count() != 0)
                    return false;
                _columns = (new FilteredElementCollector(_doc)).WherePasses(bbif).OfCategory(BuiltInCategory.OST_Columns).ToList();

                Level level = (Level)_doc.GetElement(slab.get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM).AsElementId());
                double offset = slab.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).AsDouble();
                bool isFound;
                _floor = _myLevel.GetFloor(out isFound, level, offset);
                if (!isFound)
                {
                    _abandonWriter.WriteAbandonment(slab, AbandonmentTable.LevelNotFound);
                    return false;
                }

                if (_doc.GetElement(slab.FloorType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()).Name
                            == _addiInfo.materialTypes[(byte)PGMaterialType.PrestressConcrete])
                    _isPrestress = true;
                else _isPrestress = false;
                return true;
            }
Exemplo n.º 33
0
        private static bool TryGetFGCode(out string FGCode)
        {
            FGCode = "";
            int ds_type = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_FrameType];
            int ds_crossSection = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_CrossSection];
            if((ds_type == 0 && 5 <= ds_crossSection) || (ds_type == 1 && ds_crossSection <= 4))
            {
                _abandonWriter.WriteAbandonment(null, AbandonmentTable.BracedFrame_TypeCrossConflict);
                return false;
            }
            else
            {
                int ds_brace = 0;
                int ds_plf = 0;
                if (_Braces.Count != 0)
                {
                    int numOverlap = 0;
                    int numColumn = 0;
                    FamilyInstance brace = (FamilyInstance)_Braces.First();
                    Curve curve = (brace.Location as LocationCurve).Curve;
                    XYZ p0 = curve.GetEndPoint(0);
                    XYZ p1 = curve.GetEndPoint(1);
                    XYZ deltaXYZ = new XYZ(ErrorCTRL_Overlap, ErrorCTRL_Overlap, ErrorCTRL_Overlap);
                    BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(
                        new Outline(brace.get_BoundingBox(_doc.ActiveView).Min - deltaXYZ, brace.get_BoundingBox(_doc.ActiveView).Max + deltaXYZ));
                    FilteredElementCollector fec = new FilteredElementCollector(_doc);
                    fec.WherePasses(bbFilter).WherePasses(new ElementStructuralTypeFilter(StructuralType.Brace));
                    foreach (Element brace2 in fec)
                    {
                        if (brace2.Id != brace.Id)
                        {
                            Curve curve2 = (brace2.Location as LocationCurve).Curve;
                            XYZ p2_0 = curve2.GetEndPoint(0);
                            XYZ p2_1 = curve2.GetEndPoint(1);
                            if (IsTheSamePoint(p2_0, p0) || IsTheSamePoint(p2_0, p1)) ++numOverlap;
                            if (IsTheSamePoint(p2_1, p0) || IsTheSamePoint(p2_1, p1)) ++numOverlap;
                            break;
                        }
                    }
                    fec = new FilteredElementCollector(_doc);
                    fec.WherePasses(bbFilter).WherePasses(new ElementStructuralTypeFilter(StructuralType.Column));
                    numColumn = fec.Count();
                    if (numOverlap == 1 && numColumn == 1) ds_brace = 1;    //Chevron
                    else if (numOverlap == 2) ds_brace = 3;                 //X
                    else ds_brace = 2;                                      //single

                    try
                    {
                        IList<Parameter> paras = brace.Symbol.GetParameters("A");
                        double area = paras.First().AsDouble();
                        if (area == 0.0) throw new Exception();
                        else
                        {
                            double plf = area * density_steel;
                            if (plf <= 40.0) ds_plf = 0;
                            else if (100.0 <= plf) ds_plf = 2;
                            else ds_plf = 1;
                        }
                    }
                    catch
                    {
                        ds_plf = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_PLF];
                    }

                }
                else
                {
                    ds_brace = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_Brace];
                    ds_plf = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_PLF];
                }
                if (ds_crossSection != 8)
                {
                    FGCode = "B1033.0";
                    FGCode += ds_crossSection.ToString() + ds_brace.ToString() + ConstSet.Alphabet[ds_plf];
                }
                else
                {
                    FGCode = "B1033.1";
                    if (ds_brace == 3)
                    {
                        _abandonWriter.WriteAbandonment(null, AbandonmentTable.BracedFrame_BRBwXBrace);
                        return false;
                    }
                    else
                    {
                        FGCode += (ds_brace - 1).ToString() + "1" + ConstSet.Alphabet[ds_plf];
                    }
                }
                return true;
            }
        }
Exemplo n.º 34
0
 private static void Process()
 {
     if (_StruColumns.Count() * _StruBeams.Count() == 0) return;
     string FGCode;
     if (!TryGetFGCode(out FGCode)) return;
     int floorNum = MyLevel.GetLevelNum() - 1;
     int[] num = new int[floorNum];
     int totalNum = 0;
     for (int i = 0; i < floorNum; ++i)
     {
         int n, m, k;
         double lowerLevel = _myLevel.GetElevation(i);
         double upperLevel = _myLevel.GetElevation(i + 1);
         double deltaHi = upperLevel - lowerLevel;
         double columnLL = lowerLevel + deltaHi * 0.3;
         double columnUL = upperLevel - deltaHi * 0.3;
         XYZ columnBottom = new XYZ(_maxBB.Min.X, _maxBB.Min.Y, columnLL);
         XYZ columnTop = new XYZ(_maxBB.Max.X, _maxBB.Max.Y, columnUL);
         BoundingBoxIntersectsFilter columnBBFilter = new BoundingBoxIntersectsFilter(new Outline(columnBottom, columnTop));
         FilteredElementCollector columnFec = new FilteredElementCollector(_doc, _StruColumns);
         columnFec.WherePasses(columnBBFilter);
         double beamLL = lowerLevel + deltaHi * 0.7;
         double beamUL = upperLevel + deltaHi * 0.3;
         XYZ beamBottom = new XYZ(_maxBB.Min.X, _maxBB.Min.Y, beamLL);
         XYZ beamTop = new XYZ(_maxBB.Max.X, _maxBB.Max.Y, beamUL);
         BoundingBoxIntersectsFilter beamBBFilter = new BoundingBoxIntersectsFilter(new Outline(beamBottom, beamTop));
         FilteredElementCollector beamFec = new FilteredElementCollector(_doc, _StruBeams);
         beamFec.WherePasses(beamBBFilter);
         if (columnFec.Count() * beamFec.Count() == 0) continue;
         GetNMK(columnFec.ToElementIds().ToList(), beamFec.ToElementIds().ToList(), out n, out m, out k);
         num[i] = m - n + k;
         totalNum += num[i];
     }
     if (totalNum != 0)
     {
         PGItem pgItem = new PGItem();
         pgItem.Code = FGCode;
         pgItem.direction = Direction.Undefined;
         pgItem.PGName = "支撑刚架";
         pgItem.PinYinSuffix = "ZhiChengGangJia";
         pgItem.Price = _addiInfo.prices[(byte)PGComponents.BracedFrame];
         if (pgItem.Price == 0.0) pgItem.IfDefinePrice = false;
         else pgItem.IfDefinePrice = true;
         for (int i = 0; i < floorNum; ++i)
         {
             pgItem.Num[i] = num[i];
         }
         _PGItems.Add(pgItem);
     }
 }
Exemplo n.º 35
0
        /// <summary>
        /// Return the element ids of all furniture and 
        /// equipment family instances contained in the 
        /// given room.
        /// </summary>
        static List<Element> GetFurniture( Room room )
        {
            BoundingBoxXYZ bb = room.get_BoundingBox( null );

              Outline outline = new Outline( bb.Min, bb.Max );

              BoundingBoxIntersectsFilter filter
            = new BoundingBoxIntersectsFilter( outline );

              Document doc = room.Document;

              // Todo: add category filters and other
              // properties to narrow down the results

              // what categories of family instances
              // are we interested in?

              BuiltInCategory[] bics = new BuiltInCategory[] {
            BuiltInCategory.OST_Furniture,
            BuiltInCategory.OST_PlumbingFixtures,
            BuiltInCategory.OST_SpecialityEquipment
              };

              LogicalOrFilter categoryFilter
            = new LogicalOrFilter( bics
              .Select<BuiltInCategory,ElementFilter>(
            bic => new ElementCategoryFilter( bic ) )
              .ToList<ElementFilter>() );

              FilteredElementCollector familyInstances
            = new FilteredElementCollector( doc )
              .WhereElementIsNotElementType()
              .WhereElementIsViewIndependent()
              .OfClass( typeof( FamilyInstance ) )
              .WherePasses( categoryFilter )
              .WherePasses( filter );

              int roomid = room.Id.IntegerValue;

              List<Element> a = new List<Element>();

              foreach( FamilyInstance fi in familyInstances )
              {
            if( null != fi.Room
              && fi.Room.Id.IntegerValue.Equals( roomid ) )
            {
              Debug.Assert( fi.Location is LocationPoint,
            "expected all furniture to have a location point" );

              a.Add( fi );
            }
              }
              return a;
        }
Exemplo n.º 36
0
 //floor starts from 0
 private static void GetNMK(IList<ElementId> columnIds, IList<ElementId> beamIds, out int n, out int m, out int k)
 {
     int num_IndividualColumn;
     k = DFS(columnIds, beamIds, out num_IndividualColumn);
     FilteredElementCollector beamFec = new FilteredElementCollector(_doc, beamIds);
     beamFec.OfClass(typeof(FamilyInstance));
     n = columnIds.Count() - num_IndividualColumn;
     m = beamFec.Count();
     foreach (Element beam in beamFec)
     {
         BoundingBoxXYZ beamBB = beam.get_BoundingBox(_doc.ActiveView);
         XYZ deltaXYZ = new XYZ(ErrorCTRL_BB, ErrorCTRL_BB, ErrorCTRL_BB);
         BoundingBoxIntersectsFilter beamBBFilter = new BoundingBoxIntersectsFilter(new Outline(beamBB.Min - deltaXYZ, beamBB.Max + deltaXYZ));
         FilteredElementCollector fec = new FilteredElementCollector(_doc, columnIds);
         int delta = fec.WherePasses(beamBBFilter).Count() - 2;
         if (delta < 0) delta = -1;      //net of cantilever beam or illegal unsupported beam
         m += delta;
     }
 }
        // from RevitAPI.chm description of BoundingBoxIntersectsFilter Class
        // case 1260682 [Find walls in a specific area]
        void f2()
        {
            // Use BoundingBoxIntersects filter to find
              // elements with a bounding box that intersects
              // the given outline.

              // Create a Outline, uses a minimum and maximum
              // XYZ point to initialize the outline.

              Outline myOutLn = new Outline(
            XYZ.Zero, new XYZ( 100, 100, 100 ) );

              // Create a BoundingBoxIntersects filter with
              // this Outline

              BoundingBoxIntersectsFilter filter
            = new BoundingBoxIntersectsFilter( myOutLn );

              // Apply the filter to the elements in the
              // active document.  This filter excludes all
              // objects derived from View and objects
              // derived from ElementType

              FilteredElementCollector collector
            = new FilteredElementCollector( _doc );

              IList<Element> elements =
            collector.WherePasses( filter ).ToElements();

              // Find all walls which don't intersect with
              // BoundingBox: use an inverted filter to match
              // elements.  Use shortcut command OfClass()
              // to find walls only

              BoundingBoxIntersectsFilter invertFilter
            = new BoundingBoxIntersectsFilter( myOutLn,
              true ); // inverted filter

              collector = new FilteredElementCollector( _doc );

              IList<Element> notIntersectWalls
            = collector.OfClass( typeof( Wall ) )
              .WherePasses( invertFilter ).ToElements();
        }
Exemplo n.º 38
0
 private static bool TryGetFGCode(out string FGCode)
 {
     FGCode = "B1049.0";
     XYZ adj = new XYZ(0, 0 , ErrorCTRL_SlabBB);
     bool hasDropPanel = false;
     foreach (Element column in _columns)
     {
         BoundingBoxXYZ bbXYZ = column.get_BoundingBox(_doc.ActiveView);
         BoundingBoxIntersectsFilter bbif = new BoundingBoxIntersectsFilter(new Outline(bbXYZ.Min + adj, bbXYZ.Max + adj));
         FilteredElementCollector fec = new FilteredElementCollector(_doc);
         fec.WherePasses(bbif).OfCategory(BuiltInCategory.OST_Floors);
         foreach (Floor f in fec)
         {
             if (f.Id != _slab.Id)
             {
                 hasDropPanel = true;
                 break;
             }
         }
     }
     if (!_isPrestress && !hasDropPanel)
     {
         if (ds_shearRein == 0)
             FGCode += "0" + (ds_VgVo + 1).ToString() + ConstSet.Alphabet[ds_contiRein];
         else
         {
             if (ds_VgVo == 0)
             {
                 _abandonWriter.WriteAbandonment(_slab, AbandonmentTable.FlatSlab_ReinVgVoConflict);
                 return false;
             }
             FGCode += "1" + ds_VgVo.ToString();
         }
     }
     else if (_isPrestress)
     {
         if (ds_shearRein == 0)
         {
             if (ds_VgVo == 0)
             {
                 _abandonWriter.WriteAbandonment(_slab, AbandonmentTable.FlatSlab_ReinVgVoConflict);
                 return false;
             }
             FGCode += "2" + ds_VgVo.ToString() + ConstSet.Alphabet[ds_contiRein];
         }
         else
         {
             int temp = ds_VgVo == 0 ? 1 : ds_VgVo;
             FGCode += "3" + temp.ToString();
         }
     }
     else
     {
          int temp = ds_VgVo == 0 ? 1 : ds_VgVo;
          FGCode += "4" + temp.ToString() + ConstSet.Alphabet[ds_contiRein];
     }
     return true;
 }