C#_Curves Offset

I have list of closed planar curves and want to offset them on XY plane. But they are not getting offset and script runs fine, No error!

Any help would be great!

Here’s the code!

Tuple<List,List> fl1 = Floors(crv, floors, flrSpacing, rotation, thickness);

List<Extrusion> iSkn = new List<Extrusion>();
List<Curve > c2 = new List<Curve>();

for(int i = 0; i < fl1.Item1.Count;i++){
  fl1.Item1[i].Offset(Plane.WorldXY, 5000, RhinoDocument.ModelAbsoluteTolerance,
    CurveOffsetCornerStyle.None);
  c2.Add(fl1.Item1[i]);
}
FloorCurves = fl1.Item1;
B = c2;

what am I doing wrong here?:sweat_smile:

The Offset method does not modify your curve, but return an array of offset curves, which you are ignoring in your example. If the offset worked well, the array contains one entry. It’s all documented in the RhinoCommon API.

The short fix would be:

  var crv = fl1.Item1[i].Offset(Plane.WorldXY, 5000, RhinoDocument.ModelAbsoluteTolerance,
    CurveOffsetCornerStyle.None)[0];
  c2.Add(crv);

But some Error handling for the case you receive an array with 0 or multiple entries would actually be better :wink:

1 Like

yeah it worked thanks!

Might want to do c2.AddRange(crv); in case crv is an array containing multiple curves or else you will only get the first segment in such case.

Yep, that’s probably even easier, even though I guess the best thing to do is to retrieve the array from the offset, and handle the different cases:

Curve[] crvs = fl1.Item1[i].Offset(
  Plane.WorldXY, 
  5000.0,
  RhinoDocument.ModelAbsoluteTolerance,
  CurveOffsetCornerStyle.None);
switch (crvs.Length)
{
  case 0:
    // offset failed, error / warning / exception ?
    break;
  case 1:
    // clean offset
    c2.Add(crvs[0]);
    break;
  default:
    // more than one segment, offset crv has self-intersections
    // do something smart to fix this
    break;
}

Well … the offset task is one of the most challenging things that you can deal with.

See just an entry level intro (solves about 1% of the whole puzzle) on that matter in the attached C# . A bonus C# sheds some light on some freaky curve points as well.

Curve_Offset_V1.gh (126.6 KB)
Curve_Offset_V1.3dm (305.5 KB)

Its great, thanks!..but I think i am not even at entry level, looking at your script

Just keep walking the walk.

Screen%20Shot%20048

2 Likes