ComputeClosestPoints in nested forloop crashing

ComputeClosestPoints in nested forloop crashing

Maltezc
Advocate Advocate
449 Views
1 Reply
Message 1 of 2

ComputeClosestPoints in nested forloop crashing

Maltezc
Advocate
Advocate

Hi all, I'm trying to iterate through a nested forloop of DetailLines and call ComputeClosestPoints to see if any lines in those 2 lists match my requirements. 

 

It runs the first time, I then clear the list but I still get the error below. Is there a way to run through again without getting the InvalidOperationException Error? This is one of my first times using ComputeClosestPoints(). I'm still learning it. 

 

I've checked the API docs, and this other post but they don't mention anything about being able to iterate through it a second time. 

 

Any and all help is appreciated. 

 

 

When I call ComputeClosestPoints the second time around, I get an error: 

Exception thrown: 'Autodesk.Revit.Exceptions.InvalidOperationException' in RevitAPI.dll
An exception of type 'Autodesk.Revit.Exceptions.InvalidOperationException' occurred in RevitAPI.dll but was not handled in user code
Additional information: The method failed. For example the problem has infinitely many solutions such as two parallel lines or two concentric circles.

 

Here is my code: 

List<DetailLine> testLines1;
List<DetailLine> testLines2;

for (int i = 0; i < testLines1.Count; i++)
{
    for (int k = 0; k < testLines2.Count; k++) 
    {
    IList<ClosestPointsPairBetweenTwoCurves> resultPoints = new 
    List<ClosestPointsPairBetweenTwoCurves>();

 testLines1[i].GeometryCurve.ComputeClosestPoints(testLines2[k].GeometryCurve, true, true, true, out resultPoints);

    resultPoints.Clear();
    }
}

 

 

0 Likes
450 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

The problem is stated clearly in the error message: two parallel lines or two concentric circles.

 

Eliminate those and the problem will go away.

 

Maybe there is a more efficient way to achieve your goal.

 

What might that be?

 

What are your "requirements"?

  

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes