Option Explicit
‘Script written by <Suqi>
‘Script copyrighted by <insert company name>
‘Script version Wednesday, 13 October 2010 02:08:35
Call Main()
Sub Main()
Dim arrsurface
arrsurface = rhino.getobjects(“get the base arrsurface”,8)
”Call rhino.command (“_rebuild 30 30 “)
Dim linecount
linecount = rhino.getinteger(“how many lines”,2,1,20)
‘
‘ Dim lines
‘ lines = rhino.GetObjects(“get a line”,4)
Dim iteration
iteration = rhino.GetInteger(“how many iteration of transformation”,5,0,20)
Dim p
Dim orignialarrpoints
ReDim orignialarrpoints(ubound(arrsurface))
For p = 0 To ubound(arrsurface)
Call rhino.enableobjectgrips(arrsurface(p))
orignialarrpoints (p)= rhino.ObjectGripLocations(arrsurface(p))
Next
Dim r
For r = 0 To iteration
Call rhino.EnableRedraw(True)
For p = 0 To ubound(arrsurface)
Call rhino.EnableRedraw(True)
Call rhino.enableobjectgrips(arrsurface(p))
‘————————————————–generate line on surface rather than use pre-selected lines
Dim lines
ReDim lines(linecount-1)
Dim udomain,vdomain
Dim pt1,pt2,pt11,pt22
udomain = rhino.SurfaceDomain(arrsurface(p),0)
vdomain = rhino.SurfaceDomain(arrsurface(p),1)
Dim upara1,upara2,vpara1,vpara2
Call Randomize
Dim count1:count1 = 0
Dim normal
Dim aa
For i = 0 To linecount-1
aa = rnd
upara1 = rnd*(udomain(1)-udomain(0))
upara2 = rnd*(udomain(1)-udomain(0))
vpara1 = rnd*(vdomain(1)-vdomain(0))
vpara2 = rnd*(vdomain(1)-vdomain(0))
pt1 = rhino.EvaluateSurface(arrsurface(p),array(upara1,vdomain(0)))
pt2 = rhino.evaluatesurface(arrsurface(p),array(upara2,vdomain(1)))
pt11 = rhino.EvaluateSurface(arrsurface(p),array(vpara1,udomain(0)))
pt22 = rhino.evaluatesurface(arrsurface(p),array(vpara2,udomain(1)))
normal = rhino.surfacenormal(arrsurface(p),array(upara1,vdomain(0)))
normal = rhino.vectorunitize(normal)
If aa < 0.5 Then
lines(i) = rhino.AddLine(pt1,pt2)
Else
lines(i) = rhino.addline(pt11,pt22)
End If
Next
‘————————————————-move lines by surface’s normal
For i = 0 To ubound(lines)
lines(i) = rhino.MoveObject(lines(i),rhino.VectorScale(normal,(r*5+rnd*5)))
Next
Dim arrpoints
arrpoints = rhino.ObjectGripLocations(arrsurface(p))
Dim i
Dim arrnewpoints
ReDim arrnewpoints(ubound(arrpoints))
Dim closept, dist,vec
ReDim closept(ubound(arrpoints))
Dim j
Dim neovector
neovector = array(0,0,0)
Dim count
count = 0
Dim minidist
Dim index
Dim cpt
ReDim cpt(ubound(lines))
Dim srfcpt
Dim midpt,distonline
Dim refdist
For i = 0 To ubound(arrpoints)
For j = 0 To ubound(lines)
cpt(j) = rhino.EvaluateCurve(lines(j),rhino.CurveClosestPoint(lines(j),arrpoints(i)))
Next
index = rhino.PointArrayClosestPoint(cpt,arrpoints(i))
srfcpt = rhino.EvaluateSurface(arrsurface(p),rhino.SurfaceClosestPoint(arrsurface(p),cpt(index)))
dist = rhino.Distance(arrpoints(i),srfcpt)
midpt = rhino.CurveMidPoint(lines(index))
distonline = rhino.distance(midpt,cpt(index))
If distonline > 120 Then
distonline = 120
End If
vec = rhino.VectorCreate(cpt(index),arrpoints(i))
vec = rhino.vectorscale(vec,(1-distonline/120))
refdist = rhino.Distance(arrpoints(i),orignialarrpoints (p)(i))
If dist < 5 And refdist < 5 Then
arrnewpoints(i) = rhino.PointAdd(arrpoints(i),vec)
neovector = rhino.VectorAdd(neovector,vec)
Else
arrnewpoints(i) = arrpoints(i)
count = count+1
End If
Next
rhino.Print “count” & CStr(count)
rhino.Print “ubound(arrnewpoints)” & CStr(ubound(arrnewpoints))
For i = 0 To ubound(arrpoints)
If arrnewpoints(i)(0) = arrpoints(i)(0) And arrnewpoints(i)(1) = arrpoints(i)(1) And arrnewpoints(i)(2) = arrpoints(i)(2)Then
arrnewpoints(i) = rhino.PointAdd(arrnewpoints(i),rhino.vectorscale(neovector,1/count))
End If
Next
Call rhino.ObjectGripLocations(arrsurface(p),arrnewpoints)
Call rhino.enableobjectgrips(arrsurface(p),False)
Next
Next
End Sub