Range Rebuild Surface

This script allows the user to rebuild surfaces that fall within a certain point count range. The user is asked to select a series of surfaces and is then prompted to select a minimum and maximum point count as well as a point count for rebuilding if the surface falls within these parameters. Additionally, the ability to override the degree of curvature is included if the value is zero the existing curvature is retained.

Rhino Script

Option Explicit 
'Script written by <David Mans> 
'Script copyrighted by <Neoarchaic Studio> 
'Script version Tuesday, June 09, 2009 3:07:42 PM 
Call Main() 
Sub Main() 
	Dim curves, arrValue 
	curves = Rhino.GetObjects("Select Surfaces to Rebuild", 8,, True) 
	If isNull(curves) Then Exit Sub 
	arrValue = Rhino.PropertyListBox(array("(U) Range Minimum", "(U) Range Maximum", "(U) Point Count", "(U) Degree (0=current)", "(V) Range Minimum", "(V) Range Maximum ", "(V) Point Count", "(V) Degree(0=current)"), array(2, 10, 5, 0, 2, 10, 5, 0)) 
	If isNull(arrValue) Then Exit Sub 
	Call Rhino.EnableRedraw(False) 
	Call reBuildRange(curves, array(CInt(arrValue(0)), CInt(arrValue(4))), array(CInt(arrValue(1)), CInt(arrValue(5))), array(CInt(arrValue(2)), CInt(arrValue(6))), array(CInt(arrValue(3)), CInt(arrValue(7)))) 
	Call Rhino.EnableRedraw(True) 
End Sub 
Function reBuildRange(arrSurfaces, minVal, maxVal, arrValue, arrDegree) 
	reBuildRange = Null 
	Dim i, tVal(1), tDeg(1),tBln(1) 
	Dim arrOutput() 
	ReDim arrOutput(uBound(arrSurfaces)) 
	For i = 0 To uBound(arrSurfaces) Step 1 
		'calculate for U then V 
		For j = 0 To 1 Step 1 
			'find the existing point count, set rebuild to false 
			tVal(j) = Rhino.SurfacePointCount(arrSurfaces(i))(j) 
			tBln(j) = False 
			'if the point count is in range then set rebuild to true and specify new point count 
			If tVal(j) >= minVal(j) And tVal(j) <= maxVal(j) Then 
				tBln(j) = True tVal(j) = arrValue(j) 
				tVal(j) = tVal(j) 
			End If 
			'if degree is set to zero use existing surface degree, otherwise specify new surface degree 
			If arrDegree(j) <= 0 Then 
				tDeg(j) = Rhino.SurfaceDegree(arrSurfaces(i))(j) 
				tDeg(j) = arrDegree(j) 
			End If 
		'if both U and V point counts fall within specified range, rebuild surface 
		If tBln(0) = True And tBln(1) = True Then 
			arrOutput(i) = Rhino.RebuildSurface(arrSurfaces(i), tDeg, tVal) 
			arrOutput(i) = arrSurfaces(i) 
		End If 
	reBuildRange = arrOutput 
End Function