예제 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve> curveList = new List <Curve>();

            DA.GetDataList(0, curveList);
            //GH_Structure<GH_Activ> in_IDtree = new GH_Structure<Curve>();

            double width = new double();

            if (!DA.GetData(1, ref width))
            {
                width = .1;
            }
            double halfwidth = width / 2.0;

            CurveOffsetCornerStyle cornerstyle = new CurveOffsetCornerStyle();
            List <PolylineCurve>   plines      = new List <PolylineCurve>();
            Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
            Point3d  origin = new Point3d(0.0, 0.0, 0.0);
            Plane    plane  = new Plane(origin, normal);

            foreach (Curve c in curveList)
            {
                Polyline pl = new Polyline();
                if (c.TryGetPolyline(out pl))
                {
                    int    segCount = pl.SegmentCount;
                    Line[] segments = pl.GetSegments();
                    foreach (Line l in segments)
                    {
                        l.Extend(halfwidth, halfwidth);
                        Curve     crv     = l.ToNurbsCurve();
                        Curve[]   offset1 = crv.Offset(plane, halfwidth, 0.0, cornerstyle);
                        Curve[]   offset2 = crv.Offset(plane, -halfwidth, 0.0, cornerstyle);
                        Point3d[] rect    = new Point3d[5] {
                            offset1[0].PointAtStart, offset1[0].PointAtEnd, offset2[0].PointAtEnd, offset2[0].PointAtStart, offset1[0].PointAtStart
                        };
                        PolylineCurve plc = new PolylineCurve(rect);
                        plines.Add(plc);
                    }
                }
            }

            // 2. Boolean Union
            Curve[] final = PolylineCurve.CreateBooleanUnion(plines);

            // 3. Set data back
            DA.SetDataList(0, final);
        }