Esempio n. 1
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static bool IsInside(this XYZ point, Solid solid, double tolerance)
        {
            if (solid == null || solid.Volume < tolerance)
            {
                return(false);
            }

            SolidCurveIntersectionOptions sco = new SolidCurveIntersectionOptions();

            sco.ResultType = SolidCurveIntersectionMode.CurveSegmentsInside;

            XYZ[] vectors = { XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ };
            foreach (XYZ vector in vectors)
            {
                Line l = Line.CreateBound(point - vector, point + vector);
                SolidCurveIntersection sci = solid.IntersectWithCurve(l, sco);
                if (sci == null)
                {
                    continue;
                }

                for (int i = 0; i < sci.SegmentCount; i++)
                {
                    Curve c = sci.GetCurveSegment(i);
                    IntersectionResult ir = c.Project(point);
                    if (ir != null && ir.Distance <= tolerance)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        private Line GetIntersectingCurve(Curve locationCurve)
        {
            Solid wallSolid = _wall.GetSolid();

            SolidCurveIntersection line = wallSolid.IntersectWithCurve(locationCurve, new SolidCurveIntersectionOptions());
            Line curveSegment           = line.GetCurveSegment(0) as Line;

            return(curveSegment);
        }
        private Line GetIntersectingCurve(Element intersector)
        {
            Solid wallSolid = Wall.GetSolid();

            if (intersector.Location is LocationCurve locationCurve)
            {
                SolidCurveIntersection line = wallSolid.IntersectWithCurve(locationCurve.Curve, new SolidCurveIntersectionOptions());
                Line curveSegment           = line.GetCurveSegment(0) as Line;
                return(curveSegment);
            }

            return(null);
        }
Esempio n. 4
0
        static void ColumnSplitter(Document doc, Element selectedElem)
        {
            List <Curve> crvs = new List <Curve>();
            IDictionary <Curve, Level> crvsLvls = new Dictionary <Curve, Level>();

            Curve currCrv = RvtGeometryUtils.GetColumnAxis(selectedElem);

            ElementId prevElemId =
                m_interferingElems.ElementAt(0).LevelId;

            for (int i = 0; i < m_interferingElems.Count; i++)
            {
                Element currElem = m_interferingElems.ElementAt(i);

                Solid elemSolid = RvtGeometryUtils.GetSolid(currElem);

                SolidCurveIntersection results =
                    elemSolid.IntersectWithCurve
                        (currCrv,
                        new SolidCurveIntersectionOptions
                {
                    ResultType = SolidCurveIntersectionMode.CurveSegmentsOutside
                });

                if (results.SegmentCount == 2)
                {
                    // if it is not the last segment
                    if (i != m_interferingElems.Count - 1)
                    {
                        crvs.Add(results.GetCurveSegment(0));
                        currCrv = results.GetCurveSegment(1);
                        crvsLvls.Add(results.GetCurveSegment(0), (Level)doc.GetElement(prevElemId));
                    }
                    else
                    {
                        crvs.Add(results.GetCurveSegment(0));
                        crvs.Add(results.GetCurveSegment(1));
                        crvsLvls.Add(results.GetCurveSegment(0), (Level)doc.GetElement(prevElemId));
                        crvsLvls.Add(results.GetCurveSegment(1), (Level)doc.GetElement(currElem.LevelId));
                    }
                }
                else
                {
                    currCrv = results.GetCurveSegment(0);
                }
                prevElemId = currElem.LevelId;
            }

            FamilySymbol columnType = ((FamilyInstance)selectedElem).Symbol;

            using (Transaction t = new Transaction(doc, "Split Column"))
            {
                t.Start();
                foreach (Curve crv in crvsLvls.Keys)
                {
                    doc.Create.NewFamilyInstance
                        (crv, columnType, crvsLvls[crv], StructuralType.Column);
                }

                doc.Delete(selectedElem.Id);
                t.Commit();
            }
        }
Esempio n. 5
0
        public static void Split(Document doc, ElementId elemId)
        {
            document          = doc;
            selectedElemId    = elemId;
            selectedElem      = document.GetElement(elemId);
            selectedElemSolid = GetUppermostSolid(selectedElem);

            try
            {
                // Acquire interfering elements
                IList <Element> interferingElems
                    = GetInterferingElems(selectedElem);

                if (interferingElems.Count == 0)
                {
                    return;
                }

                if (selectedElem is Wall)
                {
                    IList <ElementId> inserts =
                        (selectedElem as Wall).FindInserts(true, true, true, true);

                    if (inserts.Count != 0)
                    {
                        return;
                    }

                    if (ModifiedProfile((Wall)selectedElem))
                    {
                        return;
                    }



                    // Get hold of all solids involed in the clash
                    IList <Solid> interferingSolids =
                        GetInterferingElemsAsSolids(interferingElems);

                    // Perform the boolean opeartions to get the resulting solid
                    Solid resultingSolid =
                        GetResultingSolid(selectedElemSolid, interferingSolids);

                    // Find the face whose normal matches the wall's normal
                    Face face            = null;
                    XYZ  wallOrientation = ((Wall)selectedElem).Orientation;
                    foreach (Face currFace in resultingSolid.Faces)
                    {
                        XYZ faceNormal = currFace
                                         .ComputeNormal(new UV(0, 0)).Normalize();

                        if (Math.Round(
                                wallOrientation.DotProduct(faceNormal), 2) > 0.1)
                        {
                            face = currFace;
                            break;
                        }
                    }

                    if (face == null)
                    {
                        throw new ArgumentNullException("Face is null");
                    }

                    // Get a set of curveloops from the face
                    IList <CurveLoop> crvLoops = face.GetEdgesAsCurveLoops();

                    IList <CurveLoop> orderedCrvloops =
                        (crvLoops.OrderBy(crvloop =>
                    {
                        Curve crv = crvloop
                                    .Where(c => GetDirectionVector(c).Z == 1)
                                    .First();

                        return(crv.GetEndPoint(0).Z);
                    })).ToList();

                    // Get Wall's properties
                    Wall     wall     = (Wall)selectedElem;
                    WallType wallType = wall.WallType;

                    using (Transaction t = new Transaction(doc, "Create walls"))
                    {
                        t.Start();
                        for (int i = 0; i < orderedCrvloops.Count; i++)
                        {
                            // Select a curve
                            Curve selectedCrv =
                                orderedCrvloops[i].Where(crv =>
                                                         GetDirectionVector(crv).Z == 1).First();

                            double currWallHeight = selectedCrv.ApproximateLength;

                            if (i == 0)
                            {
                                double offset = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();

                                Wall.Create(doc, ((LocationCurve)wall.Location).Curve, wallType.Id, wall.LevelId,
                                            currWallHeight, offset, false, true);
                            }
                            else
                            {
                                Element intruder = interferingElems
                                                   .ElementAt(i - 1);

                                ElementId currLevelId = intruder.LevelId;

                                double offset = intruder
                                                .get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM)
                                                .AsDouble();

                                Wall.Create(doc, ((LocationCurve)wall.Location).Curve, wallType.Id, currLevelId,
                                            currWallHeight, offset, false, true);
                            }
                        }
                        doc.Delete(wall.Id);
                        t.Commit();
                    }
                }
                else
                {
                    List <Curve> crvs = new List <Curve>();
                    IDictionary <Curve, Level> crvsLvls = new Dictionary <Curve, Level>();

                    Curve currCrv = GetColumnAxis(selectedElem);

                    ElementId prevElemId =
                        interferingElems.ElementAt(0).LevelId;

                    for (int i = 0; i < interferingElems.Count; i++)
                    {
                        Element currElem = interferingElems.ElementAt(i);

                        Solid elemSolid = GetUppermostSolid(currElem);

                        SolidCurveIntersection results =
                            elemSolid.IntersectWithCurve
                                (currCrv,
                                new SolidCurveIntersectionOptions
                        {
                            ResultType = SolidCurveIntersectionMode.CurveSegmentsOutside
                        });

                        if (results.SegmentCount == 2)
                        {
                            // if it is not the last segment
                            if (i != interferingElems.Count - 1)
                            {
                                crvs.Add(results.GetCurveSegment(0));
                                currCrv = results.GetCurveSegment(1);
                                crvsLvls.Add(results.GetCurveSegment(0), (Level)doc.GetElement(prevElemId));
                            }
                            else
                            {
                                crvs.Add(results.GetCurveSegment(0));
                                crvs.Add(results.GetCurveSegment(1));
                                crvsLvls.Add(results.GetCurveSegment(0), (Level)doc.GetElement(prevElemId));
                                crvsLvls.Add(results.GetCurveSegment(1), (Level)doc.GetElement(currElem.LevelId));
                            }
                        }
                        else
                        {
                            currCrv = results.GetCurveSegment(0);
                        }
                        prevElemId = currElem.LevelId;
                    }

                    FamilySymbol columnType = ((FamilyInstance)selectedElem).Symbol;

                    using (Transaction t = new Transaction(doc, "Split Column"))
                    {
                        t.Start();
                        foreach (Curve crv in crvsLvls.Keys)
                        {
                            doc.Create.NewFamilyInstance
                                (crv, columnType, crvsLvls[crv], StructuralType.Column);
                        }

                        doc.Delete(selectedElem.Id);
                        t.Commit();
                    }
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Exception", string.Format("StackTrace:\n{0}\nMessage:\n{1}",
                                                           ex.StackTrace, ex.Message));
            }
        }