Example #1
0
        public static Dictionary <string, object> getRebarCenterLineCurve(
            List <Revit.Elements.Element> rebar,
            bool adjustForSelfIntersection = false,
            bool suppressHooks             = true,
            bool suppressBendRadius        = true,
            bool multiplanarOption         = true
            )
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <Autodesk.DesignScript.Geometry.PolyCurve> curves = new List <Autodesk.DesignScript.Geometry.PolyCurve>();
            MultiplanarOption mp = MultiplanarOption.IncludeOnlyPlanarCurves;

            foreach (Revit.Elements.Element r in rebar)
            {
                switch (multiplanarOption)
                {
                case true: mp = MultiplanarOption.IncludeOnlyPlanarCurves; break;

                case false: mp = MultiplanarOption.IncludeAllMultiplanarCurves; break;
                }
                Autodesk.Revit.DB.Element el = doc.GetElement(r.UniqueId.ToString());
                Rebar         reb            = el as Rebar;
                IList <Curve> sketch         = reb.GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius, mp, 0);
                List <Autodesk.DesignScript.Geometry.Curve> crv = new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (Curve s in sketch)
                {
                    Autodesk.DesignScript.Geometry.Curve c = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(s, true);
                    crv.Add(c);
                }
                Autodesk.DesignScript.Geometry.PolyCurve pc = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(crv);
                curves.Add(pc);
            }

            return(new Dictionary <string, object>
            {
                { "polyCurves", curves },
                //{ "Message", message },
            });
        }
 /// <summary>
 /// Gets center line curves of a rebar.
 /// </summary>
 /// <param name="element">The rebar element.</param>
 /// <param name="adjustForSelfIntersection">Identifies if curves should be adjusted to avoid intersection.</param>
 /// <param name="suppressHooks">Identifies if the chain will include hooks curves.</param>
 /// <param name="suppressBendRadius">Identifies if the connected chain will include unfilled curves.</param>
 /// <returns></returns>
 static IList <Curve> GetRebarCenterlineCurves(object element, bool adjustForSelfIntersection, bool suppressHooks, bool suppressBendRadius,
                                               MultiplanarOption multiplanarOption = MultiplanarOption.IncludeOnlyPlanarCurves, int barPositionIndex = 0)
 {
     if (element is Rebar)
     {
         return((element as Rebar).GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius, multiplanarOption, barPositionIndex));
     }
     else if (element is RebarInSystem)
     {
         return((element as RebarInSystem).GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius));
     }
     else if (element is RebarContainerItem)
     {
         return((element as RebarContainerItem).GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius));
     }
     else
     {
         throw new ArgumentException("Not a rebar.");
     }
 }