Example #1
1
        /// <summary>
        /// Create Curves using Isolines of a Surface
        /// </summary>
        /// <param name="face">Surface</param>
        /// <param name="isoDirection">Iso Line Direction</param>
        /// <param name="parameters">Parameters to Evaluate</param>
        /// <returns>List of IsoCurves</returns>
        //public static List<Curve> FollowingIsoLineSurface(Surface face, int isoDirection, List<double> parameters)
        //{
        //    List<Curve> result = new List<Curve>();
        //
        //    foreach (double parameter in parameters)
        //        result.Add(face.GetIsoline(isoDirection, parameter));
        //
        //    return result;
        //}

        /// <summary>
        /// Cuts a set of Rebars by Plane
        /// </summary>
        /// <param name="plane">Plane to cut by</param>
        /// <param name="rebarContainerElement">Rebar Container</param>
        /// <param name="firstPart">Return the first or the last part of the splitted elements</param>
        public static void Cut(Surface plane, Revit.Elements.Element rebarContainerElement, bool firstPart)
        {
            // Get Rebar Container Element
            Autodesk.Revit.DB.Structure.RebarContainer rebarContainer = (Autodesk.Revit.DB.Structure.RebarContainer)rebarContainerElement.InternalElement;

            // Get the active Document
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // Open a new Transaction
            TransactionManager.Instance.EnsureInTransaction(document);

            // Get all single Rebar elements from the container
            List<Autodesk.Revit.DB.Structure.RebarContainerItem> rebars = rebarContainer.ToList();

            // Walk through all rebar elements
            foreach (Autodesk.Revit.DB.Structure.RebarContainerItem rebar in rebars)
            {
                // Buffer Rebar properties for recreation
                RVT.Structure.RebarBarType barType = (RVT.Structure.RebarBarType)document.GetElement(rebar.BarTypeId);
                RVT.Structure.RebarHookType hookTypeStart = (RVT.Structure.RebarHookType)document.GetElement(rebar.GetHookTypeId(0));
                RVT.Structure.RebarHookType hookTypeEnd = (RVT.Structure.RebarHookType)document.GetElement(rebar.GetHookTypeId(1));
                RVT.Structure.RebarHookOrientation hookOrientationStart = rebar.GetHookOrientation(0);
                RVT.Structure.RebarHookOrientation hookOrientationEnd = rebar.GetHookOrientation(1);

                // create a list to store the remaining part of the curve after cutting it
                List<RVT.Curve> result = new List<RVT.Curve>();

                // get the center line curves of the rebar elements
                foreach (RVT.Curve curve in rebar.GetCenterlineCurves(false, true, true))
                {
                    // if the curve is a line or an arc consider it being valid
                    if (curve.GetType() == typeof(RVT.Line) || curve.GetType() == typeof(RVT.Arc))
                    {
                        // Get a DesignScript Curve from the Revit curve
                        Curve geocurve = curve.ToProtoType();

                        // Intersect the selected plane with the curve
                        foreach (Geometry geometry in plane.Intersect(geocurve))
                        {
                            // if the intersection is a point
                            if (geometry.GetType() == typeof(Point))
                            {
                                // Get the closest point to the intersection on the curve
                                Point p = geocurve.ClosestPointTo((Point)geometry);

                                // Split the curve at this point
                                Curve[] curves = geocurve.ParameterSplit(geocurve.ParameterAtPoint(p));

                                // If the curve has been split into two parts
                                if (curves.Length == 2)
                                {
                                    // return the first or the second part of the splitted curve
                                    if (firstPart)
                                        result.Add(curves[0].ToRevitType());
                                    else
                                        result.Add(curves[1].ToRevitType());
                                }
                            }
                        }
                    }
                }

                // If the result has some elements, create a new rebar container from those curves
                // using the same properties as the initial one.
                if (result.Count > 0)
                {
                    rebar.SetFromCurves(RVT.Structure.RebarStyle.Standard, barType, hookTypeStart, hookTypeEnd, rebar.Normal, result, hookOrientationStart, hookOrientationEnd, true, false);
                }
            }

            // Commit and Dispose the transaction
            TransactionManager.Instance.TransactionTaskDone();
        }
Example #2
0
        public static object AwareTributaryArea_ByPoints(Dyn.Surface boundarySrf, List <Dyn.Point> pointsForLoad, bool flipDirection)
        {
            sDynamoConverter dycon = new sDynamoConverter("Feet", "Meters");

            List <Dyn.UV> uvs = new List <Dyn.UV>();


            //double fac = 10;
            //if (flipDirection) fac *= -1;
            //foreach (Dyn.Curve seg in Dyn.PolyCurve.ByJoinedCurves(boundarySrf.PerimeterCurves()).Offset(fac).Explode())
            //{
            //    uvs.Add(boundarySrf.UVParameterAtPoint(seg.PointAtParameter(0.5)));
            //}
            foreach (Dyn.Point lp in pointsForLoad)
            {
                uvs.Add(boundarySrf.UVParameterAtPoint(lp));
            }
            List <Dyn.Surface> vorocut = new List <Dyn.Surface>();

            foreach (var vc in Voronoi.ByParametersOnSurface(uvs, boundarySrf))
            {
                Dyn.Curve vcc = vc as Dyn.Curve;

                Dyn.Geometry[] ints = boundarySrf.Intersect(vcc);
                if (ints != null && ints.Length > 0)
                {
                    for (int i = 0; i < ints.Length; ++i)
                    {
                        if (ints[i] is Dyn.Curve)
                        {
                            Dyn.Curve   ic   = ints[i] as Dyn.Curve;
                            Dyn.Surface isrf = ic.Extrude(Dyn.Vector.ZAxis().Scale(5));
                            vorocut.Add(isrf);
                        }
                        else
                        {
                            object t = ints[i];
                        }
                    }
                }
            }
            List <Dyn.Surface> voroPattern = new List <Dyn.Surface>();
            List <double>      voroArea    = new List <double>();
            List <Dyn.Point>   lpts        = new List <Dyn.Point>();

            Dyn.PolySurface vorocutPoly = Dyn.PolySurface.ByJoinedSurfaces(vorocut);
            Dyn.Geometry[]  splited     = boundarySrf.Split(vorocutPoly);
            for (int i = 0; i < splited.Length; ++i)
            {
                Dyn.Surface vsrf = splited[i] as Dyn.Surface;
                if (vsrf != null)
                {
                    //voroPattern.Add(Dyn.PolyCurve.ByJoinedCurves(vsrf.PerimeterCurves()));
                    voroPattern.Add(vsrf);
                    voroArea.Add(vsrf.Area);

                    foreach (Dyn.Point lp in pointsForLoad)
                    {
                        if (lp.DistanceTo(vsrf) < 0.005)
                        {
                            lpts.Add(lp);
                            break;
                        }
                    }
                }
            }


            //vorocutPoly.Dispose();

            return(new Dictionary <string, object>
            {
                { "LoadPoints", lpts },
                { "TributaryAreaSrfs", voroPattern },
                { "TributaryArea", voroArea }
            });
        }