Help with Curve method ComputeClosestPoints

Hello everyone, is there a way to set the parameter out IList for the Curve class metho ComputeClosestPoints in python?

I tried to find the resulting ClosestPointsPairBetweenTwoCurves for two lines, but i dont know how to set this parameter, here is what i try.

First:

#Code begins here
pt1 = XYZ(0, 0, 0)
pt2 = XYZ(10, 0, 0)
pt3 = XYZ(0, 7, 0)
p4 = XYZ(10, 15, 0)
ln1 = Line.CreateBound(pt1, pt2)
ln2 = Line.CreateBound(pt3, p4)
resLst = []
clstPts = ln1.ComputeClosestPoints(ln2, True, True, False, resLst)

Throws this exception (I know resLst cant be a list, just for show the expected input type…
TypeError: expected StrongBox[IList[ClosestPointsPairBetweenTwoCurves]], got list

Second, changir resLst to:

resLst = clr.Reference[List[ClosestPointsPairBetweenTwoCurves]]()

Throws this exception:
TypeError: expected StrongBox[IList[ClosestPointsPairBetweenTwoCurves]], got StrongBox[List[ClosestPointsPairBetweenTwoCurves]]

Last:
Changing resLst to:

resLst = clr.Reference[IList[ClosestPointsPairBetweenTwoCurves]]([ClosestPointsPairBetweenTwoCurves()])

In this case the method seems to work, pyrevit dosnt throw any exception but the result is null.

Any help will be appreciated.

Regards.

When I don’t know how to understand such issues I tend to look for examples on GitHub

Then go through C# and python code samples

You should also look at the constructor on apidocs website to understand better expected inputs and outputs

@Jean-Marc I think asking on the friendly and helpful pyRevit forum is a good idea, too. :wink:
@rtorrez : for the case of the result out argument it is indeed more tricky than the common strongbox or typed list examples one would find in usual rvtapi snippets.
to get to the working ironpython version I wrote it in c# and tried to do the same in ironpython.
so here is the c# snippet:

IList<ClosestPointsPairBetweenTwoCurves> results = new List<ClosestPointsPairBetweenTwoCurves>();

so a new List (not IList!) is constructed new List<ClosestPointsPairBetweenTwoCurves>() and then by its variable type is type cast to IList<ClosestPointsPairBetweenTwoCurves>
this is the what the equivalent would look like in ironpython:

from clr import StrongBox
from System.Collections.Generic import List, IList

results = StrongBox[IList[ClosestPointsPairBetweenTwoCurves]](List[ClosestPointsPairBetweenTwoCurves]())

on the right in the brackets a List[ClosestPointsPairBetweenTwoCurves]() gets created, and then immediatly gets type cast into the required StrongBox[IList[ClosestPointsPairBetweenTwoCurves]]

for accessing the results:

for result in results.Value:
    print(result.Distance)
    print(result.XYZPointOnFirstCurve)
    print(result.XYZPointOnSecondCurve)

Indeed. I just felt the Strongbox question is all over the place. And maybe was a bit tired ;p

I can imagine, and since these typed List[] and clr.StrongBox and clr.Reference are so foreign to python programmers, but in some places required in revitapi they are bound to pop up in pyRevit forum a few times, I would guess. :slightly_smiling_face:

1 Like