1129 crv distance check_2

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Wednesday, November 25, 2009 9:42:48 PM

Call Main()
Sub Main()

Dim arrObj, arrCrv, center1, center2,j

Dim param, pt1,pt2

arrObj = rhino.GetObjects(“get test pts”,1)
arrCrv = rhino.GetObjects(“get curves”,4)

Dim threshold
threshold = rhino.GetReal(“get threshold”,3)

rhino.AddLayer “circulation void”, RGB(100,150,0)
rhino.EnableRedraw False

Dim dist
For j = 0 To Ubound(arrCrv)

center1 = bBoxCenter(arrCrv(j))
dist = newPos(center1,arrObj,threshold)

If dist < threshold Then
rhino.ObjectLayer arrCrv(j),”circulation void”
End If
Next

rhino.EnableRedraw True

End Sub

Function newPos(objArr, attArr, thresholdDistance)

Dim centerPt, j, xyzPt, attXYZArr(),closestPtIndex,dist,adjAmount,adjNumber, mul

‘centerPt = rhino.PointCoordinates(objArr)

For j = 0 To UBound(attArr)
xyzPt = Rhino.PointCoordinates(attArr(j))
ReDim Preserve attXYZArr(j)
attXYZArr(j) = xyzPt
Next

closestPtIndex = Rhino.PointArrayClosestPoint(attXYZArr, objArr)
dist = Rhino.Distance(objArr, attXYZArr(closestPtIndex) )

newPos = dist

End Function

Function bBoxCenter(obj)

Dim bbox
bbox = Rhino.BoundingBox(obj)
bBoxCenter = Array( (bbox(0)(0) + bbox(6)(0))/2, (bbox(0)(1) + bbox(6)(1))/2, (bbox(0)(2) + bbox(6)(2))/2 )

End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s