How do I get the optional outputs in an overloaded function again?

I forgot (or not sure I really ever knew)… :stuck_out_tongue_winking_eye:

For example:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_ClosestPoint_1.htm
image

(the basic output is just the 3D point)

If you wanted to use the C# style call, you need to pass in a clr.Reference[T] object in place of the out / ref parameter to hold the value. You can access that value through the Value property.

import Rhino.Geometry as rg
import System
import clr
closestPoint = clr.StrongBox[rg.Point3d]()
ci = clr.StrongBox[rg.ComponentIndex]()
s = clr.StrongBox[System.Double]()
t = clr.StrongBox[System.Double]()
normal = clr.StrongBox[rg.Vector3d]()
brep.ClosestPoint(point, closestPoint, ci, s, t, 5.0, normal)

a = closestPoint.Value
b = ci.Value
c = s.Value
d = t.Value
e = normal.Value

StrongBox.gh (3.3 KB)

Another method:

1 Like

@Helvetosaur, in C# the out method is used when a method will return more than one value . ClosestPoint returns a boolean, as well as the rest of the data that is decorated with the out keyword. Point3d testPoint and double maximumDistance are the arguments for the method.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier

As for the link you provided, there is only one return value, the rest are method parameters.

Hi Mitch

This seems to work here:

import Rhino
import rhinoscriptsyntax as rs

gid = rs.GetObject( 'Brep ?' )
re = Rhino.DocObjects.ObjRef( gid ).Brep()
pt = rs.GetPoint( 'Point ?' )
ok, clop, ci, s, t, nrm = re.ClosestPoint( pt, 1000 )
print( 'clop ' + str( clop ) )
print( 'ci ' + str( ci ) )
print( 's ' + str( s ) )
print( 't ' + str( t ) )
print( 'nrm ' + str( nrm ) )

HTH, regards

Hi Emilio,

Thanks!

Hmm, I had tried that first, but I only used

a,b,c,d,e,f=brep.ClosestPoint(pt)

which didn’t work. What I didn’t realize was that the second (maximum distance) argument was not optional…

1 Like

Sorry, pasted the wrong link - corrected above.