Use .NET overloads in python

Hi,

It’s new terrain for me so correct my lingo if need be:

It’s my understanding that RhinoCommon methods can have ‘overloads’ to change the outcome or functioning of the method.

For example
Curve.DivideByLength Method (Double, Boolean,Point3d[])
Has the overload to return points instead of parameters.

My understanding is that the third argument passed should be “an empty array of points”

I could not find a way to create such an an empty array of points to pass as third argument in Python to get points returned.

Is that even possible, and if so how would I go about doing that?

Thanks
-Willem

Hi @Willem, you could use a clr.StrongBox to create the empy array like shown below:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import System, clr

def DoSomething():
    
    crv_id = rs.GetObject("Select curve to divide", 4, True, False)
    if not crv_id: return
    
    curve = rs.coercecurve(crv_id, -1, True)
    points = clr.StrongBox[System.Array[Rhino.Geometry.Point3d]]()
    length = 1.0
    params = curve.DivideByLength(length, True, points)
    
    if params: rs.AddPoints(points.Value)
        
DoSomething()

_
c.

1 Like

Hi Clement,

Thanks for showing me the way to do this.
It got me going and gave the direction to search in.

For others:. I’ve akso found this post by @Josh_Lopez-Binder witch gave me some additional insights.

Thanks
-Willem

Hi Clement,
I don’t see why you passed the second argument as True.
It sets the segment index of the curve. I suspect this is not intentional, right?

-Willem

1 Like

Yup, just typed to fast. It should be -1, i’ll correct it above.
_
c.