Hi Dimitry,

some comments on your code:

1.  Dim arrPts As New List(Of On3dPointArray)

What you're doing here is creating a list of point arrays. There's
nothing wrong with this, but such an exotic combination will probably
only be understood by your own code. If you wish to output a list of
points, then you should directly create a list of points:  Dim arrPts
As New List(On3dPoint)


2. Dim i As Int16

Int16? That one doesn't go very high. Int32 is probably the one you
want to use.


3. For Each cyl In cylinders

Handy trick. In VB.NET you can write loops more efficiently (not
faster, just less code). Like this:    For Each cyl As OnBrep in
cylinders
No need to declare a separate variable called cyl ahead of time.


4. If IsArray(rc) Then

rc is a boolean, so it's never an Array. IsArray() is something that
doesn't seem all that useful in a VB.NET environment. It's a legacy
thing from VB6 and VBScript. The rc return code is either True (we
found some intersections) or False (there were no intersections).


5. If you look at the help file for RhinoCurveBrepIntersect() you'll
find the following signature:

RhinoCurveBrepIntersect(ByRef crv As IOnCurve, ByRef brep As IOnBrep,
tol As double, curves As OnCurve(), points As On3dPointArray) As
Boolean

You have to supply ALL these fields, otherwise your script will not
compile. This is actually a fairly typical signature in Rhino SDK. The
function you call DOESN'T return the answer, it only returns a value
indicating whether or not it found an answer. The answer itself is
actually part of the input arguments of the function. In this case
'curves' and 'points'.


7. ReDim Preserve arrPts(i)

No, this is VBScript code. Your arrPts instance is a Generic List
Class. List(Of XXXX) is very clever and will grow itself as you add
more objects.


8. arrPts(i) = rc

As mentioned under (4). rc is a boolean value (rc is short for "Return
Code", a commonly used variable name for booleans that indicate
success or failure). Your arrPts instance is based on On3dPointArray,
not booleans, thus you cannot add rc to this instance.


----------------------------------

The following code will work:

  Sub RunScript(ByVal curves As List(Of OnCurve), ByVal cylinders As
List(Of OnBrep))
    Dim pts As New List(Of On3dPoint)

    For Each crv As OnCurve In curves
      For Each cyl As OnBRep In cylinders
        Dim points As On3dPointArray
        Dim overlaps As OnCurve()

        If (Not RhUtil.RhinoCurveBrepIntersect(crv, cyl, 0.001,
overlaps, points)) Then Continue For
        If (points.Count() = 0) Then Continue For

        For Each pt As on3dpoint In points
          pts.Add(pt)
        Next
      Next
    Next

    A = pts
  End Sub




--
David Rutten
[email protected]
Robert McNeel & Associates

Reply via email to