I can´t reference the CurveIntersection object to extract results working with nested loops.

Getting the error “Object reference not set to an instance of an object”. Easily achieved with a single CurveIntersection but many tries and no luck. Help is highly appreciated! Thanks…

curvesXplane.gh (131.3 KB)

Hi,

Is this what you need ?

```
private void RunScript(List<Plane> planes, DataTree<Curve> curves, ref object A, ref object B)
{
DataTree<Rhino.Geometry.Intersect.CurveIntersections> dtInters = new DataTree<Rhino.Geometry.Intersect.CurveIntersections> ();
DataTree<Point3d> pts = new DataTree<Point3d>();
for (int i = 0; i < curves.BranchCount; i++)
{
for (int j = 0; j < curves.Branch(i).Count; j++)
{
Curve c = curves.Branch(i)[j];
Plane p = planes[i];
Rhino.Geometry.Intersect.CurveIntersections intersections = Rhino.Geometry.Intersect.Intersection.CurvePlane(c, p, 0.001);
dtInters.Add(intersections, new GH_Path(i, 0));
if (intersections != null)
{
IEnumerator ie = intersections.GetEnumerator();
while (ie.MoveNext())
{
Rhino.Geometry.Intersect.IntersectionEvent iev = ie.Current as Rhino.Geometry.Intersect.IntersectionEvent;
pts.Add(iev.PointA, new GH_Path(i, j));
}
}
}
A = pts;
B = dtInters;
}
```

Do you really need the C# for this ? Component does just fine.

curvesXplane.gh (141.0 KB)

1 Like

Thank you very much mr @magicteddy. It works.

I¨m working with c# component because GH components are very spread all over my screen in a messy way and I have many variables to manage, so I´d like to keep the script inside the custom c# component and using GH components for main variables and things like custom previews, graph mappers, curvature analysis, kangaroo and others. I¨m modeling a little roof.

Without your help staying within c# could be impossible as you showed me things out from my understanding, specially the last lines of the code. tx again.

I would like to know if there is a simpler way to achieve this… or… understanding better what you wrote. Seems I have some readings pending.

How do you show the title text of the component´s name?

That is Sunglasses plugin - a must have.

Due to the use of IEnumerator the CurveIntersections class is not that easy to implement, I’m afraid the above is the simplest you can do…

Or not ? After reading this :

I forgot one can use foreach to loop through an` IEnumerator<T>`

.

```
private void RunScript(List<Plane> planes, DataTree<Curve> curves, ref object A, ref object B)
{
DataTree<Rhino.Geometry.Intersect.CurveIntersections> dtInters = new DataTree<Rhino.Geometry.Intersect.CurveIntersections> ();
DataTree<Point3d> pts = new DataTree<Point3d>();
for (int i = 0; i < curves.BranchCount; i++)
{
for (int j = 0; j < curves.Branch(i).Count; j++)
{
Curve c = curves.Branch(i)[j];
Plane p = planes[i];
Rhino.Geometry.Intersect.CurveIntersections intersections = Rhino.Geometry.Intersect.Intersection.CurvePlane(c, p, 0.001);
dtInters.Add(intersections, new GH_Path(i, 0));
if (intersections != null)
{
foreach (Rhino.Geometry.Intersect.IntersectionEvent iev in intersections)
{
pts.Add(iev.PointA, new GH_Path(i, j));
}
}
}
A = pts;
B = dtInters;
}
}
```

1 Like