Rhino.PointClosestObject (arrPoint, arrObjects)(0) fails if

arrObjects array has “” as one of its elements ONLY the first time it’s called out.

That means that if arrObjects has all the proper object IDs as its elements the first time Rhino.PointClosestObject (arrPoint, arrObjects)(0) is called out, you can then assign “” to any of arrObjects elements and Rhino.PointClosestObject (arrPoint, arrObjects)(0) will work proper, ignoring those empty elements i guess?

Below will work ONLY if Holes array doesn’t have one of its elements empty ("") on the first time its called out. Which made me create an extra lines of “unnecessary” code just to remake the array removing all the empty elements.

	For i=0 To UBound(Holes)
		PtN = Null
		Hole = Rhino.PointClosestObject(PtS, Holes)(0)
		If Not IsNull(Hole) Then PtN = Rhino.CircleCenterPoint(Hole)
		If Not IsNull(PtN) And y = 0 Then SrtdHoles(0) = PtN
		If Not IsNull(PtN) And y > 0 Then ReDim Preserve SrtdHoles(y) : SrtdHoles(y) = PtN
		If Not IsNull(PtN) Then
			For j = 0 To UBound(Holes)
				If Holes(j) = Hole Then Holes(j) = "" <-------------
			Next
			y = y + 1
		End If
	Next

^ This will fail @ Hole = Rhino.PointClosestObject(PtS, Holes)(0) if Holes(0) ="" for example with

but won’t for every next time.

Any idea why?

Don’t do this. What you are doing here is nesting functions, and you cannot be assured that the first function is going to return something, so the second will error out.

To explain further:

Rhino.PointClosestObject(PtS, Holes) may return something valid (an array of a GUID plus the point), and maybe not, in which case it will return Null.

If it happens to return Null, Null(0) is meaningless (as Null is not an array and has no index 0), so it throws an error.

Better is to un-nest the functions:

result = Rhino.PointClosestObject(PtS, Holes)
If IsArray(result) Then
    Hole=result(0)
Else
    'the method failed, so do something else...
End If

If you suspect that some of your array elements may be invalid, you ALWAYS need to check…

HTH, --Mitch
–Mitch

This indeed works as intended:

For i=0 To UBound(Holes)
	PtN = Null
	Hole = Rhino.PointClosestObject(PtS, Holes)
	If IsArray(Hole) Then PtN = Rhino.CircleCenterPoint(Hole(0))
	If Not IsNull(PtN) And y = 0 Then SrtdHoles(0) = PtN
	If Not IsNull(PtN) And y > 0 Then ReDim Preserve SrtdHoles(y) : SrtdHoles(y) = PtN
	If Not IsNull(PtN) Then
		For j = 0 To UBound(Holes)
			If Holes(j) = Hole(0) Then Holes(j) = ""
		Next
		y = y + 1
	End If
Next

But Rhino.PointClosestObject(PtS, Holes) should never fail as I have all the checks before it to make sure PtS is always a point and Holes is always an array of object IDs. As I said before, I can’t comprehend why it fails on the first time and not on any other. :confused: It almost feels like one function is processed faster than the other this one time… Also, it only fails on the first time if Holes has one or more of its elements Empty ("").