public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            try
            {
                Reference pickedObj = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);

                if (pickedObj != null)
                {
                    ElementId elementId = pickedObj.ElementId;
                    Element   element   = doc.GetElement(elementId);

                    Options gOptions = new Options();
                    gOptions.DetailLevel = ViewDetailLevel.Fine;
                    GeometryElement geom = element.get_Geometry(gOptions);

                    Solid gSolid = null;

                    foreach (GeometryObject gObj in geom)
                    {
                        GeometryInstance gInst = gObj as GeometryInstance;

                        if (gInst != null)
                        {
                            GeometryElement gEle = gInst.GetInstanceGeometry();
                            foreach (GeometryObject gO in gEle)
                            {
                                gSolid = gO as Solid;
                            }
                        }
                    }

                    FilteredElementCollector     collector  = new FilteredElementCollector(doc);
                    ElementIntersectsSolidFilter filter     = new ElementIntersectsSolidFilter(gSolid);
                    ICollection <ElementId>      intersects = collector.OfCategory(BuiltInCategory.OST_Roofs)
                                                              .WherePasses(filter).ToElementIds();

                    uidoc.Selection.SetElementIds(intersects);
                }
                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
Example #2
0
        /// <summary>
        /// 通过Solid 使用BoundingBoxIntersectsFilter 过滤元素
        /// 速度慢,但是比较准确
        /// </summary>
        /// <param name="solid"></param>
        /// <param name="builtInCategory"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public static IList <Element> GetElementsBySolid(this Document document, Solid solid, BuiltInCategory builtInCategory, bool inverted = false)
        {
            if (solid == null)
            {
                return(new List <Element>());
            }

            var collector   = new FilteredElementCollector(document);
            var solidFilter = new ElementIntersectsSolidFilter(solid, inverted);
            var list        = collector.OfCategory(builtInCategory)
                              .WhereElementIsNotElementType()
                              .WherePasses(solidFilter).ToElements();

            return(list);
        }
        public static IEnumerable <ElementId> CastSphere(
            ModelInfo info, XYZ start_pt, double radius,
            BuiltInCategory bic = BuiltInCategory.INVALID, View view = null)
        {
            Solid sphere = CreateSphereAt(start_pt, radius);
            ElementIntersectsSolidFilter intersectSphere = new ElementIntersectsSolidFilter(sphere);
            FilteredElementCollector     coll;

            coll = view != null ? new FilteredElementCollector(info.DOC, view.Id) : new FilteredElementCollector(info.DOC);

            var intersection = bic == BuiltInCategory.INVALID ?
                               coll.WherePasses(intersectSphere).ToElementIds() :
                               coll.WherePasses(intersectSphere).OfCategory(bic).ToElementIds();

            return(intersection);
        }
Example #4
0
        private List <Ceiling> FindCeilings(Room room, Transform transformValue)
        {
            var ceilings = new List <Ceiling>();

            try
            {
                var roomSolid = FindRoomSolid(room, transformValue);
                if (null != roomSolid)
                {
                    var collector   = new FilteredElementCollector(Doc);
                    var solidFilter = new ElementIntersectsSolidFilter(roomSolid);
                    ceilings = collector.OfClass(typeof(Ceiling)).WherePasses(solidFilter).WhereElementIsNotElementType().ToElements().Cast <Ceiling>().ToList();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(room.Name + ": Cannot find ceilings from the selected rooms.\n" + ex.Message, "Find Ceilings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(ceilings);
        }
        /// <summary>
        /// Determine all neighbouring elements connected
        /// to the current element 'e', skipping all
        /// previously visited ones.
        /// </summary>
        void AddElementsIntersectingSphereAt(
            List <ElementId> neighbours,
            XYZ p,
            List <ElementId> visited,
            Document doc)
        {
            Solid sphere = CreateSphereAt(
                doc, p, _sphere_radius);

            ElementIntersectsSolidFilter intersectSphere
                = new ElementIntersectsSolidFilter(sphere);

            FilteredElementCollector collector
                = new FilteredElementCollector(doc)
                  .WhereElementIsCurveDriven()   // we work with the location curve
                  .OfCategory(_bic)
                  .Excluding(visited.Union <ElementId>(
                                 neighbours).ToList <ElementId>())
                  .WherePasses(intersectSphere);

            //.Excluding( neighbours.ConvertAll<ElementId>( x => x.Id ) )

            // The argument to Expluding must not be empty,
            // or an exception is thrown; therefore, union
            // the visited with the neighbours, since the
            // visited list is never empty.
            //.Excluding( neighbours )

            //foreach( Element e in collector )
            //{
            //  if( !visited.Contains( e.Id )
            //    && !neighbours.ConvertAll<ElementId>(
            //      x => x.Id ).Contains( e.Id ) )
            //  {
            //    neighbours.Add( e );
            //  }
            //}

            neighbours.AddRange(collector.ToElementIds());
        }
        /// <summary>
        /// 用于"碰瓷检测"的方法
        /// the funtion used to get the elements around a point by a solid
        /// </summary>
        /// <param name="pt0"></param>
        /// <returns></returns>
        public FilteredElementCollector GetElementCollectorAroundPoint(XYZ pt0)
        {
            //存放返回值的list
            IList <Element> list = new List <Element>();

            //"碰瓷"方块的边长
            double dBoxLength = 0.3;

            XYZ pt1 = new XYZ(pt0.X - dBoxLength / 2, pt0.Y - dBoxLength / 2, pt0.Z);
            XYZ pt2 = new XYZ(pt0.X + dBoxLength / 2, pt0.Y - dBoxLength / 2, pt0.Z);
            XYZ pt3 = new XYZ(pt0.X + dBoxLength / 2, pt0.Y + dBoxLength / 2, pt0.Z);
            XYZ pt4 = new XYZ(pt0.X - dBoxLength / 2, pt0.Y + dBoxLength / 2, pt0.Z);

            Line lineBottom = Line.CreateBound(pt1, pt2);
            Line lineRight  = Line.CreateBound(pt2, pt3);
            Line lineTop    = Line.CreateBound(pt3, pt4);
            Line lineLeft   = Line.CreateBound(pt4, pt1);

            CurveLoop profile = new CurveLoop();

            profile.Append(lineBottom);
            profile.Append(lineRight);
            profile.Append(lineTop);
            profile.Append(lineLeft);

            List <CurveLoop> loops = new List <CurveLoop>();

            loops.Add(profile);

            //拉伸生成方块
            XYZ   vector = new XYZ(0, 0, 1);//拉伸方向
            Solid solid  = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector, dBoxLength);

            FilteredElementCollector     collector   = new FilteredElementCollector(DocSet.doc);
            ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);

            collector.WherePasses(solidFilter);

            return(collector);
        }
Example #7
0
        /// <summary>
        ///     Returns intersection element list.
        /// </summary>
        /// <param name="room"></param>
        /// <param name="doc"></param>
        /// <param name="loc"></param>
        /// <returns></returns>
        public static List <Element> IntersectElementList(this SpatialElement room, Document doc, SpatialElementBoundaryLocation loc = default)
        {
            if (room is null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            var opt = new SpatialElementBoundaryOptions {
                SpatialElementBoundaryLocation = loc
            };
            var calc       = new SpatialElementGeometryCalculator(doc, opt);
            var solid      = calc.CalculateSpatialElementGeometry(room).GetGeometry();
            var instFilter = new FilteredElementCollector(doc).WhereElementIsNotElementType();
            var itstFilter = new ElementIntersectsSolidFilter(solid);

            return(instFilter.WherePasses(itstFilter).ToList());
        }
Example #8
0
        static IList <Element> GetIntersectSolidElems(Document doc, Element elem)
        {
            Solid solid = RvtGeometryUtils.GetSolid(elem);

            if (solid == null)
            {
                throw new System.ArgumentNullException("GetSolid(elem)==null");
            }
            FilteredElementCollector collector =
                new FilteredElementCollector(doc);
            ElementIntersectsSolidFilter intrudingElemFilter =
                new ElementIntersectsSolidFilter(solid, false);
            ExclusionFilter exclusionFilter =
                new ExclusionFilter(new List <ElementId> {
                elem.Id
            });

            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);

            ICollection <Element> envadingElems = collector
                                                  .WherePasses(exclusionFilter)
                                                  .WherePasses(intrudingElemFilter)
                                                  .WherePasses(anyStrElemFlt)
                                                  .WhereElementIsNotElementType()
                                                  .ToElements();

            return(envadingElems.ToList());
        }
Example #9
0
        public static IEnumerable <ElementId> ElementIdsByScopeBox(this Document document, string boxName, IEnumerable <ElementId> ids = null)
        {
            if (document == null)
            {
                return(null);
            }

            if (ids != null && !ids.Any())
            {
                return(new List <ElementId>());
            }

            Solid box = new FilteredElementCollector(document).OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_VolumeOfInterest).FirstOrDefault(x => x.Name == boxName)?.ToSolid();

            if (box == null && document.IsLinked)
            {
                Document hostDoc = document.HostDocument();
                box = new FilteredElementCollector(hostDoc).OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_VolumeOfInterest).FirstOrDefault(x => x.Name == boxName)?.ToSolid();
                if (box != null)
                {
                    Transform linkTransform = document.LinkTransform();
                    box = SolidUtils.CreateTransformed(box, linkTransform.Inverse);
                    BH.Engine.Reflection.Compute.RecordNote($"The Scope Box named {boxName} used to filter the elements was found in the document hosting the link document it was originally requested with.");
                }
            }

            if (box == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"Couldn't find a Scope Box named {boxName}.");
                return(new HashSet <ElementId>());
            }

            FilteredElementCollector     collector = ids == null ? new FilteredElementCollector(document) : new FilteredElementCollector(document, ids.ToList());
            ElementIntersectsSolidFilter filter    = new ElementIntersectsSolidFilter(box);

            return(collector.WherePasses(filter).ToElementIds());
        }
Example #10
0
        /// <summary>
        /// Find elements blocking egress
        /// </summary>
        /// <param name="egresses">The egresses to be detected</param>
        /// <returns>The detection result</returns>
        public XElement findBlockingElements(ICollection <Element> egresses)
        {
            // create a node that place all egresses.
            XElement egressesNode = new XElement("Egresses", new XAttribute("Name", "Egresses"));

            try
            {
                // find the elements blocking egress
                foreach (Element egressElement in egresses)
                {
                    XElement egressNode = new XElement("Egress",
                                                       new XAttribute("Name", egressElement.Name));

                    int count = 1;
                    IEnumerator <GeometryObject> Objects = egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).GetEnumerator();
                    Objects.MoveNext();
                    GeometryInstance             gi       = Objects.Current as GeometryInstance;
                    IEnumerator <GeometryObject> Objects1 = gi.GetInstanceGeometry().GetEnumerator();


                    //foreach (GeometryObject egressGObj in
                    //   (egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).Objects.get_Item(0) as GeometryInstance).GetInstanceGeometry().Objects)
                    while (Objects1.MoveNext())
                    {
                        GeometryObject egressGObj = Objects1.Current;

                        if (egressGObj is Solid)
                        {
                            Solid egressVolume = egressGObj as Solid; //calculated from shape and location of a given door

                            XElement solidNode = new XElement("ElementSolid" + count.ToString());
                            // Iterate to find all instance types
                            FilteredElementCollector blockingcollector = new FilteredElementCollector(m_doc);
                            blockingcollector.WhereElementIsNotElementType();

                            // Apply geometric filter
                            ElementIntersectsSolidFilter testElementIntersectsSolidFilter =
                                new ElementIntersectsSolidFilter(egressVolume);
                            blockingcollector.WherePasses(testElementIntersectsSolidFilter);

                            IEnumerable <Element> blockingElement = blockingcollector;

                            // Exclude the door itself
                            List <ElementId> exclusions = new List <ElementId>();
                            exclusions.Add(egressElement.Id);
                            blockingcollector.Excluding(exclusions);

                            XElement blockingegressNode = new XElement("blocking_egress_elements",
                                                                       new XAttribute("Count", blockingElement.Count().ToString()));

                            foreach (Element blockingelement in blockingElement)
                            {
                                blockingegressNode.Add(new XElement("blocking_egress_element",
                                                                    new XAttribute("Name", blockingelement.Name)));
                            }

                            solidNode.Add(blockingegressNode);
                            egressNode.Add(solidNode);

                            count++;
                        }
                    }
                    egressesNode.Add(egressNode);
                }
            }
            catch (Exception ex)
            {
                egressesNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString())));
            }

            // return the whole Egresses Node
            return(egressesNode);
        }
Example #11
0
        /// <summary>
        /// Find the nearby walls on specific point and in specific height
        /// </summary>
        /// <param name="point">The given point</param>
        /// <param name="height">The given height</param>
        /// <param name="radius">The radius in which walls can be detected</param>
        /// <returns>The detection result</returns>
        private FilteredElementCollector nearbyWallsFilter(XYZ point, double height, double radius)
        {
            // build cylindrical shape around wall endpoint
             List<CurveLoop> curveloops = new List<CurveLoop>();
             CurveLoop circle = new CurveLoop();
             circle.Append(m_app.Create.NewArc(point, radius
                                           , 0, Math.PI,
                                           XYZ.BasisX, XYZ.BasisY));
             circle.Append(m_app.Create.NewArc(point, radius
                                           , Math.PI, 2 * Math.PI,
                                           XYZ.BasisX, XYZ.BasisY));
             curveloops.Add(circle);

             Solid wallEndCylinder =
            GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, height);

             // Iterate document to find walls
             FilteredElementCollector collector = new FilteredElementCollector(m_doc);
             collector.OfCategory(BuiltInCategory.OST_Walls);

             // Apply geometric filter
             ElementIntersectsSolidFilter testElementIntersectsSolidFilter =
            new ElementIntersectsSolidFilter(wallEndCylinder);
             collector.WherePasses(testElementIntersectsSolidFilter);

             return collector;
        }
Example #12
0
        /// <summary>
        /// Find elements blocking egress
        /// </summary>
        /// <param name="egresses">The egresses to be detected</param>
        /// <returns>The detection result</returns>
        public XElement findBlockingElements(ICollection<Element> egresses)
        {
            // create a node that place all egresses.
             XElement egressesNode = new XElement("Egresses", new XAttribute("Name", "Egresses"));

             try
             {
            // find the elements blocking egress
            foreach (Element egressElement in egresses)
            {
               XElement egressNode = new XElement("Egress",
                  new XAttribute("Name", egressElement.Name));

               int count = 1;
               foreach (GeometryObject egressGObj in
                  (egressElement.get_Geometry(new Autodesk.Revit.DB.Options()).Objects.get_Item(0) as GeometryInstance).GetInstanceGeometry().Objects)
               {
                  if (egressGObj is Solid)
                  {
                     Solid egressVolume = egressGObj as Solid; //calculated from shape and location of a given door

                     XElement solidNode = new XElement("ElementSolid" + count.ToString());
                     // Iterate to find all instance types
                     FilteredElementCollector blockingcollector = new FilteredElementCollector(m_doc);
                     blockingcollector.WhereElementIsNotElementType();

                     // Apply geometric filter
                     ElementIntersectsSolidFilter testElementIntersectsSolidFilter =
                        new ElementIntersectsSolidFilter(egressVolume);
                     blockingcollector.WherePasses(testElementIntersectsSolidFilter);

                     IEnumerable<Element> blockingElement = blockingcollector;

                     // Exclude the door itself
                     List<ElementId> exclusions = new List<ElementId>();
                     exclusions.Add(egressElement.Id);
                     blockingcollector.Excluding(exclusions);

                     XElement blockingegressNode = new XElement("blocking_egress_elements",
                        new XAttribute("Count", blockingElement.Count().ToString()));

                     foreach (Element blockingelement in blockingElement)
                     {
                        blockingegressNode.Add(new XElement("blocking_egress_element",
                           new XAttribute("Name", blockingelement.Name)));
                     }

                     solidNode.Add(blockingegressNode);
                     egressNode.Add(solidNode);

                     count++;
                  }
               }
               egressesNode.Add(egressNode);
            }
             }
             catch (Exception ex)
             {
            egressesNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString())));
             }

             // return the whole Egresses Node
             return egressesNode;
        }
Example #13
0
        /// <summary>ElementIntersectsSolidFilter: 找到与某Solid相交的Elements </summary>
        public void FindIntersectWallsByGeometry()
        {
            Transaction trans = new Transaction(Doc, "ExComm");

            trans.Start();

            // ---------------- 在API内存中创建一个拉伸Solid的定义(但是并不包含在Document中) ----------------
            //pick a point to draw solid
            Selection sel = UIDoc.Selection;
            XYZ       pt  = sel.PickPoint("Please pick a point to get the close walls");

            XYZ pttemp1 = sel.PickPoint(ObjectSnapTypes.None, "Pick leader end...");
            XYZ pttemp2 = sel.PickPoint(ObjectSnapTypes.None, "Pick leader elbow...");

            double dBoxLength = 3;
            // 创建进行拉伸的闭合曲线
            XYZ pt1 = new XYZ(pt.X - dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z);
            XYZ pt2 = new XYZ(pt.X + dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z);
            XYZ pt3 = new XYZ(pt.X + dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z);
            XYZ pt4 = new XYZ(pt.X - dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z);

            // 闭合曲线的四条边
            Line lineBottom = Line.CreateBound(pt1, pt2);
            Line lineRight  = Line.CreateBound(pt2, pt3);
            Line lineTop    = Line.CreateBound(pt3, pt4);
            Line lineLeft   = Line.CreateBound(pt4, pt1);

            // 将四条边连接起来
            CurveLoop profile = new CurveLoop();

            profile.Append(lineBottom);
            profile.Append(lineRight);
            profile.Append(lineTop);
            profile.Append(lineLeft);

            // 创建闭合的连续曲线段
            List <CurveLoop> loops = new List <CurveLoop>();

            loops.Add(profile);

            // 创建出一个Solid:此Solid只是为了与其他API交互,并未保存在Document中,所以也不可见。
            XYZ   vector = new XYZ(0, 0, 1);
            Solid solid  = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector, 10);

            // 在整个文档中搜索与此虚拟定义的Solid相交的Element
            FilteredElementCollector     collector   = new FilteredElementCollector(Doc);
            ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid);

            collector.WherePasses(solidFilter);

            // 将最终的相交结果选中
            List <ElementId> selEle = new List <ElementId>();

            foreach (Element elem in collector)
            {
                selEle.Add(elem.Id);
            }
            sel.SetElementIds(selEle);
            //
            trans.Commit();
        }
Example #14
0
        public static List <global::Revit.Elements.Element> GetIntersectingElementsOfCategoryLinkOption(global::Revit.Elements.Element element,
                                                                                                        global::Revit.Elements.Category category, [DefaultArgument("Rhythm.Revit.Elements.Element.GetNull()")] global::Revit.Elements.Element sourceInstance)
        {
            //the current document
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //get built in category from user viewable category
            BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());
            //build a new list for the intersecting elements to be added to
            List <global::Revit.Elements.Element> intersectingElements = new List <global::Revit.Elements.Element>();

            if (sourceInstance != null)
            {
                Autodesk.Revit.DB.RevitLinkInstance internalInstance =
                    (Autodesk.Revit.DB.RevitLinkInstance)sourceInstance.InternalElement;
                //get the element's geometry.
                GeometryElement geomElement = element.InternalElement.get_Geometry(new Options());
                //transform the solid to where the eff the link is.
                GeometryElement transformedElement = geomElement.GetTransformed(internalInstance.GetTransform());
                //make a solid filter.
                Solid solid = null;
                foreach (GeometryObject geomObj in transformedElement)
                {
                    solid = geomObj as Solid;
                    if (solid != null)
                    {
                        break;
                    }
                }
                //the intersection filter
                ElementIntersectsSolidFilter filter = new ElementIntersectsSolidFilter(solid);
                //build a collector
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                //collect the elements that fall in that category
                IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList =
                    collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements();

                //add each user recognizable element to the list
                foreach (Autodesk.Revit.DB.Element internalElement in intersectingElementsInternaList)
                {
                    intersectingElements.Add(internalElement.ToDSType(true));
                }
            }
            else
            {
                //the intersection filter
                ElementIntersectsElementFilter filter = new ElementIntersectsElementFilter(element.InternalElement);
                //build a collector
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                //collect the elements that fall in that category
                IList <Autodesk.Revit.DB.Element> intersectingElementsInternaList =
                    collector.OfCategory(myCatEnum).WhereElementIsNotElementType().WherePasses(filter).ToElements();

                //add each user recognizable element to the list
                foreach (Autodesk.Revit.DB.Element internalElement in intersectingElementsInternaList)
                {
                    intersectingElements.Add(internalElement.ToDSType(true));
                }
            }

            return(intersectingElements);
        }
 /// <summary>
 /// 梁柱连接
 /// </summary>
 /// <param name="beamList">梁的实例</param>
 /// <param name="colList">柱子的实例</param>
 /// <param name="doc">项目文档</param>
 private void JoinBeamAndColumns(ref List <FamilyInstance> beamList, List <FamilyInstance> colList, Document doc)
 {
     if (colList.Count != 0 && beamList.Count != 0)
     {
         List <XYZ>            colPosList = colList.ConvertAll(m => (m.Location as LocationPoint).Point);
         Level                 lev        = doc.GetElement(beamList[0].Host.Id) as Level;
         List <FamilyInstance> BeamNotJoinNowColListList = new List <FamilyInstance>();
         //需要改变定位线的梁、
         List <ElementId> beamElemChnageIds     = new List <ElementId>();
         List <Line>      beamLocationCurveList = new List <Line>();
         foreach (FamilyInstance col in colList)
         {
             XYZ       colPos         = (col.Location as LocationPoint).Point;
             XYZ       direction      = -XYZ.BasisZ;
             double    b              = col.Symbol.LookupParameter("b").AsDouble();
             double    h              = col.Symbol.LookupParameter("h").AsDouble();
             double    length         = b > h ? b : h;
             double    curveLoopWidth = length / 2 + 200 / 304.8;
             CurveLoop cuLoop         = new CurveLoop();
             double    x              = colPos.X;
             double    y              = colPos.Y;
             double    z              = lev.Elevation;
             //左上
             XYZ p1 = new XYZ(x - curveLoopWidth, y + curveLoopWidth, z);
             //左下
             XYZ p2 = p1 + new XYZ(0, -2 * curveLoopWidth, 0);
             //右下
             XYZ p3 = p2 + new XYZ(2 * curveLoopWidth, 0, 0);
             //右上
             XYZ   p4 = p3 + new XYZ(0, 2 * curveLoopWidth, 0);
             Curve c1 = Line.CreateBound(p1, p2);
             Curve c2 = Line.CreateBound(p2, p3);
             Curve c3 = Line.CreateBound(p3, p4);
             Curve c4 = Line.CreateBound(p4, p1);
             cuLoop.Append(c1);
             cuLoop.Append(c2);
             cuLoop.Append(c3);
             cuLoop.Append(c4);
             Solid intersectSolid = GeometryCreationUtilities.CreateExtrusionGeometry(new List <CurveLoop>()
             {
                 cuLoop
             }, direction, 200 / 304.8);
             ElementIntersectsSolidFilter ElemInsectSolidFilter = new ElementIntersectsSolidFilter(intersectSolid);
             IList <Element> beamNotJoinColList = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance))
                                                  .OfCategory(BuiltInCategory.OST_StructuralFraming).WherePasses(ElemInsectSolidFilter).ToElements().
                                                  Where(m => !JoinGeometryUtils.AreElementsJoined(doc, m, col)).ToList();
             //Transaction trans = new Transaction(doc, "创建内建模型");
             //trans.Start();
             //DirectShapeType drt = DirectShapeType.Create(doc, "实体", new ElementId(BuiltInCategory.OST_Parts));
             //DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Parts), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
             //ds.SetShape(new List<GeometryObject>() { intersectSolid });
             //ds.SetTypeId(drt.Id);
             //trans.Commit();
             //TaskDialog.Show("biao", "uu");
             foreach (Element e in beamNotJoinColList)
             {
                 //判断是否发生了变化
                 bool pd = true;
                 Line l  = (e.Location as LocationCurve).Curve is Line ? (e.Location as LocationCurve).Curve as Line : null;
                 if (l == null)
                 {
                     continue;
                 }
                 XYZ lp1  = l.GetEndPoint(0);
                 XYZ lp2  = l.GetEndPoint(1);
                 XYZ dirt = (lp1 - lp2) / lp1.DistanceTo(lp2);
                 //当柱端点与梁端点相距不超过某个值是默认让其相交
                 XYZ pi = new XYZ(x, y, z);
                 if (lp1.DistanceTo(pi) < curveLoopWidth)
                 {
                     if (dirt.IsAlmostEqualTo(new XYZ(0, 1, 0)) || dirt.IsAlmostEqualTo(new XYZ(0, -1, 0)))
                     {
                         lp1 = new XYZ(lp1.X, pi.Y, lev.Elevation);
                     }
                     else if (dirt.IsAlmostEqualTo(new XYZ(-1, 0, 0)) || dirt.IsAlmostEqualTo(new XYZ(1, 0, 0)))
                     {
                         lp1 = new XYZ(pi.X, lp1.Y, lev.Elevation);
                     }
                     else
                     {
                         continue;
                     }
                 }
                 else if (lp2.DistanceTo(pi) < curveLoopWidth)
                 {
                     if (dirt.IsAlmostEqualTo(new XYZ(0, 1, 0)) || dirt.IsAlmostEqualTo(new XYZ(0, -1, 0)))
                     {
                         lp2 = new XYZ(lp2.X, pi.Y, lev.Elevation);
                     }
                     else if (dirt.IsAlmostEqualTo(new XYZ(-1, 0, 0)) || dirt.IsAlmostEqualTo(new XYZ(1, 0, 0)))
                     {
                         lp2 = new XYZ(pi.X, lp2.Y, lev.Elevation);
                     }
                     else
                     {
                         continue;
                     }
                 }
                 else
                 {
                     pd = false;
                 }
                 if (pd == true)
                 {
                     if (beamElemChnageIds.Count() == 0 || beamElemChnageIds.Where(m => m == e.Id).Count() == 0)
                     {
                         beamElemChnageIds.Add(e.Id);
                         beamLocationCurveList.Add(Line.CreateBound(lp1, lp2));
                     }
                     else
                     {
                         int  index     = beamElemChnageIds.IndexOf(e.Id);
                         Line indexLine = beamLocationCurveList.ElementAt(index);
                         XYZ  pone      = indexLine.GetEndPoint(0);
                         XYZ  ptwo      = indexLine.GetEndPoint(1);
                         //变化的线
                         Line linelast1 = Line.CreateBound(pone, lp2);
                         Line linelast2 = Line.CreateBound(lp1, ptwo);
                         beamLocationCurveList[index] = linelast1.Length > linelast2.Length ? linelast1 : linelast2;
                     }
                 }
             }
         }
         //创建新的梁实例
         using (Transaction transChange = new Transaction(doc))
         {
             transChange.Start("join");
             foreach (ElementId beamId in beamElemChnageIds)
             {
                 int     index = beamElemChnageIds.IndexOf(beamId);
                 Element beam  = doc.GetElement(beamId);
                 (beam.Location as LocationCurve).Curve = beamLocationCurveList[index];
                 TaskDialog.Show("kaishi", "sdduas");
             }
             transChange.Commit();
         }
         using (Transaction trans = new Transaction(doc, "调整顺序"))
         {
             trans.Start();
             //梁柱剪切关系
             foreach (FamilyInstance col in colList)
             {
                 foreach (FamilyInstance beam in beamList)
                 {
                     if (JoinGeometryUtils.AreElementsJoined(doc, beam, col) == true)
                     {
                         if (JoinGeometryUtils.IsCuttingElementInJoin(doc, beam, col))
                         {
                             JoinGeometryUtils.SwitchJoinOrder(doc, col, beam);
                         }
                     }
                 }
             }
             trans.Commit();
         }
     }
 }
Example #16
0
        private void WP_ProcessBar_Load()
        {
            //IL_0014: Unknown result type (might be due to invalid IL or missing references)
            //IL_0019: Unknown result type (might be due to invalid IL or missing references)
            //IL_001e: Unknown result type (might be due to invalid IL or missing references)
            //IL_0020: Unknown result type (might be due to invalid IL or missing references)
            //IL_0021: Unknown result type (might be due to invalid IL or missing references)
            //IL_0026: Unknown result type (might be due to invalid IL or missing references)
            //IL_002c: Unknown result type (might be due to invalid IL or missing references)
            //IL_0032: Unknown result type (might be due to invalid IL or missing references)
            //IL_0033: Unknown result type (might be due to invalid IL or missing references)
            //IL_0038: Unknown result type (might be due to invalid IL or missing references)
            //IL_003f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0041: Unknown result type (might be due to invalid IL or missing references)
            //IL_0047: Unknown result type (might be due to invalid IL or missing references)
            //IL_0048: Unknown result type (might be due to invalid IL or missing references)
            //IL_0070: Unknown result type (might be due to invalid IL or missing references)
            //IL_0075: Unknown result type (might be due to invalid IL or missing references)
            //IL_0078: Unknown result type (might be due to invalid IL or missing references)
            //IL_00dc: Unknown result type (might be due to invalid IL or missing references)
            //IL_00de: Unknown result type (might be due to invalid IL or missing references)
            //IL_00e3: Unknown result type (might be due to invalid IL or missing references)
            //IL_00e8: Unknown result type (might be due to invalid IL or missing references)
            //IL_00eb: Unknown result type (might be due to invalid IL or missing references)
            //IL_00ee: Unknown result type (might be due to invalid IL or missing references)
            //IL_00fb: Unknown result type (might be due to invalid IL or missing references)
            //IL_0100: Unknown result type (might be due to invalid IL or missing references)
            //IL_0103: Unknown result type (might be due to invalid IL or missing references)
            //IL_0105: Expected O, but got Unknown
            //IL_010a: Unknown result type (might be due to invalid IL or missing references)
            //IL_010c: Unknown result type (might be due to invalid IL or missing references)
            //IL_011c: Unknown result type (might be due to invalid IL or missing references)
            //IL_011e: Unknown result type (might be due to invalid IL or missing references)
            //IL_0144: Unknown result type (might be due to invalid IL or missing references)
            //IL_0146: Unknown result type (might be due to invalid IL or missing references)
            //IL_014b: Unknown result type (might be due to invalid IL or missing references)
            //IL_014e: Unknown result type (might be due to invalid IL or missing references)
            //IL_0154: Unknown result type (might be due to invalid IL or missing references)
            //IL_0159: Unknown result type (might be due to invalid IL or missing references)
            //IL_015e: Unknown result type (might be due to invalid IL or missing references)
            //IL_0160: Unknown result type (might be due to invalid IL or missing references)
            //IL_0193: Unknown result type (might be due to invalid IL or missing references)
            //IL_019b: Unknown result type (might be due to invalid IL or missing references)
            //IL_01a3: Unknown result type (might be due to invalid IL or missing references)
            //IL_01ba: Unknown result type (might be due to invalid IL or missing references)
            //IL_01c2: Unknown result type (might be due to invalid IL or missing references)
            //IL_01ca: Unknown result type (might be due to invalid IL or missing references)
            //IL_0231: Unknown result type (might be due to invalid IL or missing references)
            //IL_023f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0244: Unknown result type (might be due to invalid IL or missing references)
            this.progressBar1.Maximum = this.PB;
            Transaction val = this.I_trans = new Transaction(this.DOC);

            val.Start("JoinAll");
            FailureHandlingOptions failureHandlingOptions = val.GetFailureHandlingOptions();
            MyFailuresPreProcessor myFailuresPreProcessor = new MyFailuresPreProcessor();

            failureHandlingOptions.SetFailuresPreprocessor(myFailuresPreProcessor);
            val.SetFailureHandlingOptions(failureHandlingOptions);
            List <ElementId> list = new List <ElementId>();
            int num  = 0;
            int num2 = 0;

            foreach (Element item in this.FL)
            {
                if (!val.HasStarted())
                {
                    break;
                }
                num2++;
                this.Text = "HotGear Project Join All Process : " + num2.ToString() + "/" + this.PB;
                this.progressBar1.Value = num2;
                try
                {
                    GeometryElement val2 = item.get_Geometry(new Options());
                    Solid           val3 = null;
                    using (IEnumerator <GeometryObject> enumerator2 = val2.GetEnumerator())
                    {
                        if (enumerator2.MoveNext())
                        {
                            GeometryObject current2 = enumerator2.Current;
                            val3 = (current2 as Solid);
                            if (val3 != null)
                            {
                                list.Add(item.get_Id());
                            }
                        }
                    }
                    ElementIntersectsSolidFilter val4   = new ElementIntersectsSolidFilter(val3);
                    IList <Element>        values       = new FilteredElementCollector(this.DOC, (ICollection <ElementId>)list).WhereElementIsNotElementType().WherePasses(val4).ToElements();
                    Combinations <Element> combinations = new Combinations <Element>(values, 2, GenerateOption.WithoutRepetition);
                    foreach (List <Element> item2 in combinations)
                    {
                        if (!JoinGeometryUtils.AreElementsJoined(this.DOC, item2[0], item2[1]))
                        {
                            try
                            {
                                JoinGeometryUtils.JoinGeometry(this.DOC, item2[0], item2[1]);
                                num++;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                catch
                {
                }
                base.Show();
                Application.DoEvents();
            }
            if (val.HasStarted())
            {
                this.I_trans.Commit();
                base.Close();
            }
        }