/// <summary>
        /// Constructs a nurbs curve representation of this polyline.
        /// </summary>
        /// <returns>A Nurbs curve shaped like this polyline or null on failure.</returns>
        public NurbsCurve ToNurbsCurve()
        {
            if (m_size < 2)
            {
                return(null);
            }
            PolylineCurve pl_crv = new PolylineCurve(this);

            return(pl_crv.ToNurbsCurve());
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            List <RG.Point3d> pts = new List <RG.Point3d> {
                new RG.Point3d(0, 0, 0), new RG.Point3d(5, 10, 0), new RG.Point3d(15, 0, 0), new RG.Point3d(20, 0, 0)
            };


            RG.PolylineCurve pc = new RG.PolylineCurve(pts);


            RG.NurbsCurve nurb = pc.ToNurbsCurve();

            nurb.IncreaseDegree(3);

            var knots         = ToDoubleArray(nurb.Knots, nurb.Degree);
            var controlPoints = ToXYZArray(nurb.Points, 1);
            var weights       = nurb.Points.ConvertAll(x => x.Weight);

            XYZ normal = new XYZ(0, 0, 1);
            XYZ origin = new XYZ(0, 0, 0);

            Plane rvtPlane = Plane.CreateByNormalAndOrigin(normal, origin);

            //var plane = sketchPlane.GetPlane().ToPlane();
            Curve rvtN = NurbSpline.CreateCurve(nurb.Degree, knots, controlPoints);

            using (Transaction t = new Transaction(doc, "a"))
            {
                t.Start();
                SketchPlane sketchPlane = SketchPlane.Create(doc, rvtPlane);
                ModelCurve  mc          = doc.Create.NewModelCurve(rvtN, sketchPlane);
                TaskDialog.Show("r", mc.Id.ToString());
                t.Commit();
            }



            return(Result.Succeeded);
        }
Exemple #3
0
        //HATCH FILL REGION - infills a planar region with a hatching pattern
        public void Filler(List<double> infDens, List<double> infRot)
        {
            double tolerance = 0.001;
            //double overlaptol = 0.0;
            double crossSecHyp = Math.Sqrt(Math.Pow(crossSec, 2) * 2);

            curveInfill = new List<Curve>[planarBreps.Count];

            //Create List of Infill Curves for each Planar Region
            for (int u = 0; u < planarBreps.Count; u++)
            {

                    //Rotate Plane for Filling
                    double rotationRad = infRot[u] * 0.0174532925;
                    Plane plane = Plane.WorldXY;

                    plane.Rotate(rotationRad, Plane.WorldXY.ZAxis);

                    //Create Bounding Box
                    Box bbox = new Box();
                    planarBreps[u].GetBoundingBox(plane, out bbox);

                    //Get Corners
                    Point3d[] cornerPts = bbox.GetCorners();

                    //Draw Parallel Lines
                    LineCurve baseLine = new LineCurve(cornerPts[0], cornerPts[1]);
                    LineCurve baseLine2 = new LineCurve(cornerPts[3], cornerPts[2]);
                    //int nPts = (int)Math.Round((baseLine.Line.Length/crossSec),0);
                    Point3d[] basePts = new Point3d[0];
                    Point3d[] basePts2 = new Point3d[0];

                    double length = baseLine.Line.Length;
                    double floatdivisions = length / crossSec;
                    double density = infDens[u];

                    int divisions = (int)Math.Round((floatdivisions * density));

                    //Divide Lines by Fill Density ratio
                    baseLine.DivideByCount(divisions, true, out basePts);
                    baseLine2.DivideByCount(divisions, true, out basePts2);

                    if (divisions == 0)
                    {
                        curveInfill[u] = new List<Curve>();
                        return;
                    }

                    Curve[][] intCurve = new Curve[basePts.Length][];

                    List<Curve> intCurves = new List<Curve>();
                    for (int i = 0; i < basePts.Length; i++)
                    {

                        LineCurve intLine = new LineCurve(basePts[i], basePts2[i]);

                        Point3d[] intPts = new Point3d[0];
                        BrepFace r_Infill = planarBreps[u].Faces[0];

                        Curve[] int_Curve = new Curve[0];

                        //Intersect Curves with Regions
                        Intersection.CurveBrepFace(intLine, r_Infill, tolerance, out int_Curve, out intPts);
                        intCurve[i] = int_Curve;

                        //Convert resulting Curves into LineCurves
                        for (int j = 0; j < int_Curve.Length; j++)
                        {
                            LineCurve line = new LineCurve(int_Curve[j].PointAtStart, int_Curve[j].PointAtEnd);
                            intCurve[i][j] = line;
                            //intCurves[j].Add(int_Curve[j]);
                            intCurves.Add(line);
                        }

                    }

                    //Rotate Array
                    List<Curve>[] int_Curves = RotatetoListArray(intCurve);

                    List<Curve> joinLines = new List<Curve>();

                    List<Curve> p_lines = new List<Curve>();

                    for (int l = 0; l < int_Curves.Length; l++)
                    {
                        for (int k = 1; k < int_Curves[l].Count; k += 2)
                        {

                            int_Curves[l][k].Reverse();

                        }
                    }

                //Create a list of points for all connected lines in the infill.  Do this for each seperate string of segments
                    for (int l = 0; l < int_Curves.Length; l++)
                    {
                        List<Point3d> plinePts = new List<Point3d>();
                        if (int_Curves[l].Count > 0)
                        {
                            plinePts.Add(int_Curves[l][0].PointAtStart);
                            for (int k = 1; k < int_Curves[l].Count; k++)
                            {
                                plinePts.Add(int_Curves[l][k - 1].PointAtEnd);

                                plinePts.Add(int_Curves[l][k].PointAtStart);
                                plinePts.Add(int_Curves[l][k].PointAtEnd);
                            }

                            PolylineCurve plCurve = new PolylineCurve(plinePts);
                            Curve curve = plCurve.ToNurbsCurve();
                            p_lines.Add(curve);
                        }
                    }

                    List<Curve> curve_s = p_lines;
                    curveInfill[u] = p_lines;

            }
        }
    /// <summary>
    /// Constructs a nurbs curve representation of this polyline.
    /// </summary>
    /// <returns>A Nurbs curve shaped like this polyline or null on failure.</returns>
    public NurbsCurve ToNurbsCurve()
    {
      if (m_size < 2) { return null; }
      PolylineCurve pl_crv = new PolylineCurve(this);

      return pl_crv.ToNurbsCurve();
    }
Exemple #5
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            //Reference adaptive = uidoc.Selection.PickObject(ObjectType.Element, "Select adaptive family");

            //Element adaptiveEle = doc.GetElement(adaptive);

            //PlanarFace pf = GetFace(adaptiveEle);

            //TaskDialog.Show("tr", "I am done");

            //TaskDialog.Show("tr", "so done");

            //TaskDialog.Show("tr", "done done");


            List <RG.Point3d> pts = new List <RG.Point3d> {
                new RG.Point3d(0, 0, 0), new RG.Point3d(5, 10, 0), new RG.Point3d(15, 5, 0), new RG.Point3d(20, 0, 0)
            };


            RG.PolylineCurve pc = new RG.PolylineCurve(pts);

            RG.Interval d = pc.Domain;

            //TaskDialog.Show("r", d.ToString());

            RG.NurbsCurve value = pc.ToNurbsCurve();

            value.IncreaseDegree(3);

            int newDegree     = 3;
            var degree        = value.Degree;
            var knots         = ToDoubleArray(value.Knots, newDegree);
            var controlPoints = ToXYZArray(value.Points, 1);
            var weights       = value.Points.ConvertAll(x => x.Weight);

            XYZ normal = new XYZ(0, 0, 1);
            XYZ origin = new XYZ(0, 0, 0);

            Plane rvtPlane = Plane.CreateByNormalAndOrigin(normal, origin);


            string knot = "";

            foreach (var item in knots)
            {
                knot += item.ToString() + "\n";
            }

            //TaskDialog.Show("r", knot);

            //TaskDialog.Show("R", $"ControlPoints > Degree: {controlPoints.Length} > {degree}\nKnots = degree + control points + 1 = {controlPoints.Length + degree + 1} ");

            Curve rvtN = NurbSpline.CreateCurve(newDegree, knots, controlPoints);

            //Trace.WriteLine()
            using (Transaction t = new Transaction(doc, "a"))
            {
                t.Start();
                SketchPlane sketchPlane = SketchPlane.Create(doc, rvtPlane);
                doc.Create.NewModelCurve(rvtN, sketchPlane);

                t.Commit();
            }

            return(Result.Succeeded);
        }