Check null values of CurveIntersections

I’m sorry, if this is a basic question and already answered somewhere…
I’m trying to check null values of CurveIntersections before I do somethings in the script.
The following code doesn’t work, because it has already null CurveIntersections value.
What would be a correct statement to replace this part in the code below?:
“Rhino.Geometry.Intersect.Intersection.CurveSelf(offsetCrvs[0], 0.001).GetType() != null”
Please advise me, if this approach is not right and there’s a better method to skip invalid CurveIntersections.CurveIntersections.gh (10.5 KB)

Curve[] offsetCrvs;
Rhino.Geometry.Intersect.CurveIntersections interSelfEvent;

if (offset > 0)
{
  offsetCrvs = curve.Offset(Plane.WorldXY, offset, 0.01, CurveOffsetCornerStyle.Sharp);

  if (Rhino.Geometry.Intersect.Intersection.CurveSelf(offsetCrvs[0], 0.001).GetType() != null)
  {
    A = "do something";
  }
}

Hi, I checked your code. See if the attached is what you are after…
CurveIntersections_RI.gh (4.0 KB)

  private void RunScript(Curve curve, double offset, ref object A)
  {
    Curve[] offsetCrvs = null;
    if (offset > 0)
    {
      offsetCrvs = curve.Offset(Plane.WorldXY, offset, 0.01, CurveOffsetCornerStyle.Sharp);
      if( null == offsetCrvs )
        Print("No valid offset was returned");
      else
      {
        if( offsetCrvs.Length > 0 && offsetCrvs[0].IsValid )
        {
          var interSelfEvent = Rhino.Geometry.Intersect.Intersection.CurveSelf(offsetCrvs[0], 0.001);
          if(interSelfEvent.Count > 0)
          {
            Print("curve is self-intersecting");
          }
          A = offsetCrvs;
        }
      }
    }
  }
1 Like

Thank you @rajaa. It works very well for my use!