Exemplo n.º 1
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();
            }
        }