Pages of Code / RVB / Back

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

1128dancing_final M+C

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Friday, November 13, 2009 10:55:04 PM

Call Main()
Sub Main()
Dim strCurveID, t, arrPt, arrPts(),t1
strCurveID = Rhino.GetObject(“Select a curve to sample”, 4, True, True)
If IsNull(strCurveID) Then Exit Sub
‘Call Rhino.EnableRedraw(False)

Dim count,transPt, transPtOld, transPtNew, interLine, arrParameter
Dim midPt, newCrv

Dim curveLengthSample
curveLengthSample = rhino.CurveLength(strCurveID)
rhino.print curveLengthSample

count = 0

For t = 0.01 To 1 Step 0.02
ReDim Preserve arrPts(count)

If count > 0 Then
transPtOld = transPt ‘TRANS2
End If

arrParameter = AddPointAtR1Parameter(strCurveID, t)

arrPts(count) = arrParameter(0)
transPt = arrParameter(2)’TRANS1
transPtNew = arrParameter(1)
‘rhino.Addpoint transPt

If count > 0 Then
interLine = rhino.AddLine(transPtOld, transPtNew)

midPt = rMidPrepPt(interLine)
newCrv = rhino.AddCurve(array(transPtOld,midPt,transPtNew))
rhino.DeleteObject interLine

End If

count = count + 1
Next
‘Call Rhino.EnableRedraw(True)
End Sub

Function AddPointAtR1Parameter(strCurveID, dblUnitParameter)
AddPointAtR1Parameter = Null

Dim crvDomain, dblR1Param, arrR3Point, strPointID
crvDomain = Rhino.CurveDomain(strCurveID)

dblR1Param = crvDomain(0) + dblUnitParameter * (crvDomain(1) – crvDomain(0))

arrR3Point = Rhino.EvaluateCurve(strCurveID, dblR1Param)

strPointID = Rhino.AddPoint(arrR3Point)

‘AddPointAtR1Parameter = strPointID

Dim tangentVec, prepVec,reversePrepVec
tangentVec = Rhino.CurveCurvature(strCurveID, dblUnitParameters)(1)
prepVec = rhino.VectorRotate(tangentVec,-90,array(0,0,1))
prepVec = rhino.VectorUnitize(prepVec)
prepVec = rhino.VectorScale(prepVec,3.2+rnd*0.4)
reversePrepVec = rhino.VectorReverse(prepVec)

Dim pt1, pt2

pt1 = rhino.PointAdd(arrR3Point, prepVec)
pt2 = rhino.PointAdd(arrR3Point, reversePrepVec)

‘pt1 = rhino.AddPoint(pt1)
‘pt2 = rhino.AddPoint(pt2)
Dim crv, midPt,newCrv

crv = rhino.AddLine(pt1,pt2)
midPt = midPrepPt(crv)
newCrv = rhino.AddCurve(array(pt1,midPt,pt2))
rhino.DeleteObject crv

AddPointAtR1Parameter = array(strPointID,pt1,pt2)

End Function

Function midPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,1000)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

midPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function rMidPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,-90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,1000)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

rMidPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function avoid (obstacle,threshold)

End Function

 

11.9 triangle and attractor Sukie & Shen

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version 2009
116 0:39:25

Call Main()
Sub Main()
Dim strn
strn = rhino.GetInteger(“curve dividing number”,30)
Dim ptn
ptn = rhino.getinteger(“give the dividing number of each circle”,4)
Dim noise
noise = rhino.getinteger(“give the z direction deviation for the points”,30)
Dim u
Dim arrcenline
arrcenline = rhino.GetObjects(“pick the curves to transform”, 4)
Dim arratt
arratt = rhino.getobjects(“get all the attractors”,1)
Dim y
For y = 0 To ubound(arratt)
arratt(y) = rhino.PointCoordinates(arratt(y))
Next

Dim l
Dim arrdvpts
Dim dvpts()
ReDim Preserve dvpts(ptn)
Dim degree
ReDim degree(ptn)
Dim closestpt
ReDim closestpt(ptn)
Dim vector
ReDim vector(ptn)
Dim data
Dim outpts
ReDim outpts(ptn)
Dim allcurves
Dim arrlayer
ReDim arrlayer(ubound(arrcenline))
Dim count1:count1 = 0
For u = 0 To ubound(arrcenline)
arrdvpts = rhino.DivideCurve(arrcenline(u),strn,True, True)
Dim count :count = 1
Dim k,arrcircles
ReDim arrcircles(ubound(arrdvpts))
Dim arrnum
ReDim arrnum(ubound(arrdvpts))
For k = 0 To ubound(arrdvpts)
count = count +0.2
Dim closestpt1,index
index = rhino.PointArrayClosestPoint(arratt,arrdvpts(k))
closestpt1 = arratt(index)
Dim distance
distance = rhino.distance (arrdvpts(k),closestpt1)
Dim strPoncurve: strPoncurve = rhino.CurveClosestPoint(arrcenline(u), arrdvpts(k))
Dim strframe: strframe = rhino.Curveperpframe(arrcenline(u), strPoncurve)
arrcircles(k) = rhino.addcircle(strframe,distance/15)               ‘(10*sin(count*rhino.Pi)  30*sin(count*rhino.Pi)+40+
Next
‘——————————————————————————-generate the points
Dim vecscale
vecscale = 3+3*rnd
For k = 0 To ubound(arrcircles)
data = rhino.CurveDomain(arrcircles(k))
arrnum(k) = array(outpts)
For l = 0 To ptn
If l = 0 Then
degree(l) = 0.5*rnd*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
If l > 0 And l < ptn Then
degree(l) = (l-0.5+rnd)*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
If l = ptn Then
degree(l) = (l-0.5+0.5*rnd)*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
Next
Next
‘————————————————————————- generate the trianglate polyline based on the points above
Dim pline1,pline2,pline3,pline4
ReDim pline1(k*(l-1))
ReDim pline2(k*(l-1))
ReDim pline3(k)
ReDim pline4(k)
For k = 0 To ubound(arrnum)-1
For l = 0 To ptn-1
pline1(k*ptn+l) = rhino.AddPolyline(array(arrnum(k)(0)(l),arrnum(k+1)(0)(l),arrnum(k)(0)(l+1),arrnum(k)(0)(l)))
pline2(k*ptn+l) =  rhino.AddPolyline(array(arrnum(k)(0)(l+1),arrnum(k+1)(0)(l),arrnum(k+1)(0)(l+1),arrnum(k)(0)(l+1)))
Next
pline3(k)=  rhino.AddPolyline(array(arrnum(k)(0)(ptn),arrnum(k+1)(0)(ptn),arrnum(k)(0)(0),arrnum(k)(0)(ptn)))
pline4(k) =  rhino.AddPolyline(array(arrnum(k)(0)(0),arrnum(k+1)(0)(ptn),arrnum(k+1)(0)(0),arrnum(k)(0)(0)))
Next
Call rhino.AddLoftSrf(arrcircles)
Call rhino.DeleteObjects(arrcircles)
Dim deletepts
deletepts = rhino.ObjectsByType(1)
Call rhino.deleteobjects(deletepts)
allcurves = rhino.ObjectsByType(4)
rhino.Command “_group”

Next
End Sub
Function randomWithinRange(min, max)
Randomize
randomWithinRange = min + (max-min) * rnd()
End Function

1129 checkcurvelength


‘Script written by Macus Chen
’1129 checkcurvelength

Call Main()
Sub Main()

Dim arrCrv, length, i

arrCrv = rhino.GetObjects(“get curves”, 4)

For i = 0 To Ubound(arrCrv)

length = rhino.CurveLength(arrCrv(i))

If length < 5 Then

Rhino.DeleteObject arrCrv(i)

End If

Next

End Sub

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

1129 curvegripalittlemove

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Saturday, November 28, 2009 9:54:48 PM

Call Main()
Sub Main()

Dim arrCrv, arrPts, ptNew
arrCrv = Rhino.GetObjects(“Select curves”, 4)

Dim i,j
For i = 0 To Ubound(arrCrv)

Rhino.EnableObjectGrips arrCrv(i)
arrPts = Rhino.ObjectGripLocations(arrCrv(i))

For j = 0 To Ubound(arrPts)
arrPts(j)(0) =     arrPts(j)(0) + (Rnd*0.5-0.25)
arrPts(j)(1) =     arrPts(j)(1) + (Rnd*0.5-0.25)

Next

ptNew = Rhino.ObjectGripLocations(arrCrv(i), arrPts)
Rhino.EnableObjectGrips arrCrv(i), False

Next

End Sub

1204FINALSUBSTANCESRF

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Wednesday, November 25, 2009 4:40:35 PM

Call Main()
Sub Main()

Dim arrObj
arrObj = rhino.GetObjects(“get all the lines”,4)

Dim i, crvLength, crvPts
Dim tangentVec1, tangentVec2, tangentVec3
Dim ptA, ptB, ptC
Dim substance

rhino.EnableRedraw False

For i = 0 To Ubound(arrObj)

crvLength = rhino.CurveLength(arrObj(i))
crvPts = rhino.DivideCurve(arrObj(i),2) ‘crvPts(0),crvPts(1),crvPts(2)
tangentVec1 = rhino.CurveTangent(arrObj(i),0)
tangentVec2 = rhino.CurveTangent(arrObj(i),0.5)
tangentVec3 = rhino.CurveTangent(arrObj(i),1)

ptA = rhino.CurveStartPoint(arrObj(i))
ptB = rhino.CurveMidPoint(arrObj(i))
ptC = rhino.CurveEndPoint(arrObj(i))

substance = hole (ptA, ptB, ptC, crvLength, tangentVec1,tangentVec2,tangentVec3)

Next
rhino.EnableRedraw True

End Sub

Function hole (ptA, ptB, ptC, crvLength, tangentVec1,tangentVec2,tangentVec3)

‘arrPt = rhino.PointCoordinates(arrPt)
Dim vec1, vec2,vec3
Dim vecMid1, vecMid2, vecStart1, vecStart2, vecStart3, vecStart4, vecEnd1, vecEnd2, vecEnd3, vecEnd4
Dim pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10
Dim crv, srf

vec1 = rhino.VectorUnitize(tangentVec1)
vec1 = rhino.VectorScale(vec1,crvLength/10)
vec1 = rhino.VectorRotate(vec1,180,array(0,0,1))
vecStart1 = rhino.VectorRotate(vec1,-60-rnd*10,array(0,0,1))
vecStart2 = rhino.VectorRotate(vec1,-50+rnd*10,array(0,0,1))
vecStart3 = rhino.VectorRotate(vec1,50-rnd*10,array(0,0,1))
vecStart4 = rhino.VectorRotate(vec1,60+rnd*10,array(0,0,1))

vec2 = rhino.VectorUnitize(tangentVec2)
vec2 = rhino.VectorScale(vec2,crvLength/8)
vecMid1 = rhino.VectorRotate(vec2,-90,array(0,0,1))
vecMid1 = rhino.VectorScale(vecMid1,0.5)
vecMid2 = rhino.VectorRotate(vec2,90,array(0,0,1))
vecMid2 = rhino.VectorScale(vecMid2,0.75)

vec3 = rhino.VectorUnitize(tangentVec3)
vec3 = rhino.VectorScale(vec3,crvLength/10)
vecEnd1 = rhino.VectorRotate(vec3,-60-rnd*10,array(0,0,1))
vecEnd2 = rhino.VectorRotate(vec3,-50+rnd*10,array(0,0,1))
vecEnd3 = rhino.VectorRotate(vec3,50-rnd*10,array(0,0,1))
vecEnd4 = rhino.VectorRotate(vec3,60+rnd*10,array(0,0,1))

pt1 = rhino.PointAdd(ptA,vecStart1)
pt2 = rhino.PointAdd(ptA,vecStart2)
pt3 = rhino.PointAdd(ptA,vecStart3)
pt4 = rhino.PointAdd(ptA,vecStart4)

pt5 = rhino.PointAdd(ptB,vecMid1)
pt6 = rhino.PointAdd(ptB,vecMid2)

pt7 = rhino.PointAdd(ptC,vecEnd1)
pt8 = rhino.PointAdd(ptC,vecEnd2)
pt9 = rhino.PointAdd(ptC,vecEnd3)
pt10 = rhino.PointAdd(ptC,vecEnd4)

crv = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt7,pt8,pt9,pt10,pt6,pt1))
srf = rhino.AddPlanarSrf(array(crv))
rhino.DeleteObject crv

hole = srf

End Function

1204random select

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Friday, December 04, 2009 12:04:27 PM

Call Main()
Sub Main()
Dim arrObjects, selPer, arrSuccess(), sCount, i

‘ input
arrObjects = Rhino.GetObjects(“pick objects to randomly select from”, 0)
selPer = Rhino.GetReal(“percentage to select”, 50)

‘ loop through each object
For i = 0 To UBound(arrObjects)

If (Rnd*100) <= selPer Then
‘ add to array
ReDim Preserve arrSuccess(sCount)
arrSuccess(sCount) = arrObjects(i)
sCount = sCount + 1
End If

Next

Rhino.SelectObjects arrSuccess
End Sub

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

1204_dancing

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Friday, November 13, 2009 10:55:04 PM

Call Main()
Sub Main()
Dim strCurveID, t, arrPt, arrPts(),arrObstacles, threshold
strCurveID = Rhino.GetObject(“Select a curve to sample”, 4, True, True)
arrObstacles = rhino.GetObjects(“select obstacle points”,1)
threshold = rhino.GetReal(“enter a threshold”,3.2)

Dim count,transPt, transPtOld, transPtNew, interLine, arrParameter
Dim midPt, newCrv
Dim arrPt1(), arrPt2()

rhino.AddLayer “substanceProfile”, RGB(255,0,0)

count = 0
For t = 0.0 To 1.0 Step 0.025
ReDim Preserve arrPts(count)

If count > 0 Then
transPtOld = transPt ‘TRANS2
End If

arrParameter = AddPointAtR1Parameter(strCurveID, t,arrObstacles,threshold)

ReDim Preserve arrPt1(count)
ReDim Preserve arrPt2(count)
arrPt1(count) = arrParameter(1)
arrPt2(count) = arrParameter(2)

arrPts(count) = arrParameter(0)
transPt = arrParameter(2)’TRANS1
transPtNew = arrParameter(1)
‘rhino.Addpoint transPt

If count > 0 Then
interLine = rhino.AddLine(transPtOld, transPtNew)

midPt = rMidPrepPt(interLine)
newCrv = rhino.AddCurve(array(transPtOld,midPt,transPtNew))
rhino.DeleteObject interLine

End If
count = count + 1
Next

‘Dim profileCrv1, profileCrv2, profile
‘profileCrv1 = rhino.AddCurve(arrPt1)
‘ProfileCrv2 = rhino.AddCurve(arrPt2)

Dim profile

profile = connectCrv(arrPt1,arrPt2)

Rhino.ObjectLayer profile, “substanceProfile”

‘Rhino.ObjectLayer profileCrv1, “substanceProfile”
‘Rhino.ObjectLayer profileCrv2, “substanceProfile”

‘Call Rhino.EnableRedraw(True)
End Sub

Function connectCrv(crv1,crv2)

‘print Ubound(crv2)
Dim count,count2, i, j, arrProfilePts()

count = 0
For i = 0 To Ubound(crv1)
ReDim Preserve arrProfilePts(count)
arrProfilePts(count) = crv1(i)
count = count + 1
Next

count = Ubound(arrProfilePts)+1
count2 = count
For j = Ubound(crv2) + count To count Step -1
‘print count
‘print j
ReDim Preserve arrProfilePts(count)
arrProfilePts(count) = crv2(j-count2)

count = count + 1
Next

count = Ubound(arrProfilePts)+1
ReDim Preserve arrProfilePts(count)
arrProfilePts(count) = arrProfilePts(0)

connectCrv = rhino.AddCurve(arrProfilePts)

End Function

Function AddPointAtR1Parameter(strCurveID, dblUnitParameter,arrObstacles,threshold)
AddPointAtR1Parameter = Null

Dim crvDomain, dblR1Param, arrR3Point, strPointID
crvDomain = Rhino.CurveDomain(strCurveID)

dblR1Param = crvDomain(0) + dblUnitParameter * (crvDomain(1) – crvDomain(0))

arrR3Point = Rhino.EvaluateCurve(strCurveID, dblR1Param)

strPointID = Rhino.AddPoint(arrR3Point)

‘AddPointAtR1Parameter = strPointID

Dim tangentVec, prepVec,reversePrepVec
tangentVec = Rhino.CurveCurvature(strCurveID, dblUnitParameter)(1)
prepVec = rhino.VectorRotate(tangentVec,-90,array(0,0,1))
prepVec = rhino.VectorUnitize(prepVec)
prepVec = rhino.VectorScale(prepVec,1.75+rnd*1)
reversePrepVec = rhino.VectorReverse(prepVec)

Dim pt1, pt2, midPt

pt1 = rhino.PointAdd(arrR3Point, prepVec)
pt2 = rhino.PointAdd(arrR3Point, reversePrepVec)
midPt = array((pt1(0)+pt2(0))/2,(pt1(1)+pt2(1))/2,(pt1(2)+pt2(2))/2)

pt1 =  scale (arrObstacles,threshold,pt1,midPt)
pt2 =  scale (arrObstacles,threshold,pt2,midPt)

‘pt1 = rhino.AddPoint(pt1)
‘pt2 = rhino.AddPoint(pt2)
Dim crv ,newCrv

crv = rhino.AddLine(pt1,pt2)
midPt = midPrepPt(crv)
newCrv = rhino.AddCurve(array(pt1,midPt,pt2))
rhino.DeleteObject crv

AddPointAtR1Parameter = array(strPointID,pt1,pt2)

End Function

Function midPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,0.75)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

midPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function rMidPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,-90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,0.75)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

rMidPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function scale (arrObstacles,threshold,pt,midPt)

dim j,xyzPt,attXYZArr(),closestPtIndex,dist,adjAmount,vec,newPt

‘find the closetobstacles
For j = 0 To UBound(arrObstacles)
xyzPt = Rhino.PointCoordinates(arrObstacles(j))
ReDim Preserve attXYZArr(j)
attXYZArr(j) = xyzPt
Next

‘calculate pt1, pt2 dist to obstacles
closestPtIndex = Rhino.PointArrayClosestPoint(attXYZArr, pt)
dist = Rhino.Distance(pt, attXYZArr(closestPtIndex))

‘if dist in threshold
If dist < threshold Then
adjAmount = 1 – ((threshold – dist)/threshold)
Else
adjAmount = 1
End If

‘move pt toward the mid pt
vec = rhino.VectorCreate(pt,midPt)
vec = rhino.VectorScale(vec,adjAmount)

newPt = rhino.PointAdd(midPt,vec)

‘return the new pos of pt
scale = newPt

End Function

Function at_ChangeColor(obj,tDist,aDist,sFactor)
Dim objColor, newColor
‘ caculate color
newColor = 255 – ((1 – ((tDist – aDist)/tDist)) * 255)
‘newColor = 255
‘ change color
objColor = Rhino.ObjectColor(obj, newColor)
‘Rhino.print objColor
‘    at_ChangeColor=
End Function

Function hole (arrPt)

arrPt = rhino.PointCoordinates(arrPt)

Dim vec1, vec2, vec3, vec4
Dim pt1, pt2, pt3, pt4
Dim crv

vec1 = array(0.5+0.5*rnd,0,0)
vec2 = array(0.25+0.25*rnd,0,0)
vec3 = array(0.5+0.5*rnd,0,0)
vec4 = array(0.25+0.25*rnd,0,0)

vec1 = rhino.VectorRotate(vec1,30*rnd-15,array(0,0,1))
vec2 = rhino.VectorRotate(vec2,30*rnd-15+90,array(0,0,1))
vec3 = rhino.VectorRotate(vec3,30*rnd-15+180,array(0,0,1))
vec4 = rhino.VectorRotate(vec4,30*rnd-15+270,array(0,0,1))

pt1 = rhino.PointAdd(arrPt,vec1)
pt2 = rhino.PointAdd(arrPt,vec2)
pt3 = rhino.PointAdd(arrPt,vec3)
pt4 = rhino.PointAdd(arrPt,vec4)

crv = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt1))
hole = crv

End Function

1209extrude

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Wednesday, December 09, 2009 9:10:30 PM

Call Main()
Sub Main()

Dim objSrf
objSrf = rhino.GetObjects(“get surfaces to shrink and extrude”,8)

Dim cPt, i, arrParam, arrNormal, extrudeSrf,line,extrudePt
‘scale
rhino.EnableRedraw False

For i = 0 To Ubound(objSrf)
cPt = centerPt(objSrf(i))
objSrf(i) = rhino.ScaleObject(objSrf(i),cPt,array(0.75+rnd*0.2,0.75+rnd*0.2,0.75+rnd*0.2))

arrParam = Rhino.SurfaceClosestPoint(objSrf(i), cPt)
arrNormal = Rhino.SurfaceNormal(objSrf(i), arrParam)

arrNormal = Rhino.VectorUnitize(arrNormal)
arrNormal = rhino.VectorScale(arrNormal,0.02+0.03*rnd)

extrudePt = rhino.PointAdd(cPt,arrNormal)

line = rhino.AddLine(cPt,extrudePt)

extrudeSrf = rhino.ExtrudeSurface(objSrf(i),line)

Next

‘extrude
rhino.EnableRedraw True

End Sub

Function centerPt(obj)

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

End Function

1210meshpoints

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Thursday, December 10, 2009 1:55:02 PM

Call Main()
Sub Main()

Dim meshes
meshes = rhino.GetObjects(“get a mesh”,32)

Dim i, j, vertices, faces, newVertices(), newMesh, newPt
For i = 0 To Ubound(meshes)

vertices = Rhino.MeshVertices (meshes(i))

faces = Rhino.MeshFaceVertices(meshes(i))

For j = 0 To Ubound(vertices)

vertices(j)(0) = vertices(j)(0) + rnd*1-0.05
vertices(j)(1) = vertices(j)(1) + rnd*1-0.05
vertices(j)(2) = vertices(j)(2) + rnd*1-0.05

newPt = array(vertices(j)(0),vertices(j)(1),vertices(j)(2))
vertices(j) = newPt

Next

newMesh = rhino.AddMesh(vertices,faces)

Next

End Sub

 

11.9 grid curve script_Sukie & Shen

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version 2009
1015 13:40:39

Call Main()
Sub Main()
Dim h
h = rhino.GetInteger(“give the height of robot”,500)
Dim minangle,maxangle

Dim gen1
gen1 = rhino.getinteger(“generation”,10)
Dim strn
strn = rhino.GetInteger(“curve dividing number”,30)
Dim ptn
ptn = rhino.getinteger(“give the dividing number of each circle”,6)
Dim noise
noise = rhino.getinteger(“give the z direction deviation for the points”,120)

‘———————————————– make the grid for the trees to grow
Dim m,p
Dim number,number1
number = rhino.getinteger(“give the number of x grid”,3)
number1= rhino.GetInteger(“give the number of y grid”,3)
Dim gridlength
gridlength = rhino.getinteger(“give the grid inteval”,1500)
Dim pt1,pt2
Dim robline
Dim stpt,edpt
Dim lenvec
Dim length
Dim rtvec
Dim ptarray
Dim i
Dim cenline
Dim l
Dim arrdvpts
Dim dvpts()
ReDim Preserve dvpts(ptn)
Dim degree
ReDim degree(ptn)
Dim closestpt
ReDim closestpt(ptn)
Dim vector
ReDim vector(ptn)
Dim data
Dim outpts
ReDim outpts(ptn)
Dim countgp
countgp = 0
For m = 0 To number
For p = 0 To number1
‘———————————————– get the properties of the robot line
pt1 = array(m*gridlength,p*gridlength,0)
pt2 = array(m*gridlength,p*gridlength,h)
robline = rhino.AddLine(pt1,pt2)
stpt = Rhino.CurveStartPoint(robline)
Call rhino.AddPoint(stpt)
edpt = rhino.CurveEndPoint(robline)
Call rhino.AddPoint(edpt)
lenvec = rhino.vectorcreate(edpt,stpt)
length = rhino.CurveLength(robline)
‘rtvec = Rhino.Curveframe(robline,rhino.CurveClosestPoint(robline,edpt))
rtvec = rhino.CurveNormal(robline)
If isnull (rtvec) Then Exit Sub
Dim gen
gen = gen1
Call rotatline(robline,rtvec,stpt,edpt,lenvec,gen)
‘——————————————————–select all the points and generate the central curve
ptarray = Rhino.ObjectsByType(1)
For i = 0 To ubound(ptarray)
ptarray(i) = rhino.pointcoordinates(ptarray(i))
Next
ptarray = Rhino.SortPointList(ptarray)

cenline = rhino.AddInterpCurve(ptarray)
Call rhino.LockObject(cenline)
Dim deletepts
deletepts = rhino.ObjectsByType(1)

Call rhino.deleteobjects(deletepts)

Next
Next
Dim deletecurs
deletecurs = rhino.ObjectsByType(4)

‘Call rhino.SelectObjects(deletecurs)
‘Call rhino.Command (“_delete”)
‘Call rhino.Command (“_unlock”)
End Sub
Function rotatline(robline,rtvec,stpt,edpt,lenvec,gen)

Dim line
line = rhino.CopyObject(robline,stpt,edpt)
line  = rhino.RotateObject(line,edpt,(-30+rnd*60),rtvec)
Dim endpt
endpt = rhino.CurveEndPoint(line)
Dim startpt
startpt = rhino.CurveStartPoint(line)

Dim endvec
endvec = rhino.CurveNormal(line)
Dim lvec
lvec = rhino.VectorCreate(endpt,startpt)
‘    ptarray(n) = startpt
‘    n = n+1
gen = gen -1
If gen = 0 Then Exit Function
Dim a
a = rnd*1
Dim line2
Dim spt
Dim ept
Dim lenvec2
Dim rtvec2
If a < 0.33 Then
line2 = rhino.RotateObject(line,startpt,120,lenvec)
spt = rhino.CurveStartPoint(line2)
ept = rhino.CurveEndPoint(line2)
lenvec2 = rhino.VectorCreate(ept,spt)
rtvec2 = rhino.CurveNormal(line2)
Call rhino.AddPoint(ept)
Call rotatline(line2,rtvec2,spt,ept,lenvec2,gen)
End If
If a > 0.33 And a < 0.66 Then
line2 = rhino.RotateObject(line,startpt,240,lenvec)
spt = rhino.CurveStartPoint(line2)
ept = rhino.CurveEndPoint(line2)
lenvec2 = rhino.VectorCreate(ept,spt)
rtvec2 = rhino.CurveNormal(line2)
Call rhino.AddPoint(ept)
Call rotatline(line2,rtvec2,spt,ept,lenvec2,gen)
End If
If a > 0.66 And a<1 Then
Call rhino.AddPoint(endpt)
Call rotatline(line,endvec,startpt,endpt,lvec,gen)
End If

End Function

 

09.28.Helix.Al.Crvs_Nicole

Option Explicit

‘Script written by Nicole Acaron-Toro

 

Call Main()

Sub Main()

 

Dim arrAttPts, arrStartPts, i, extLines, addPoints, ctrPoints, arrCtrPoints, crvVertex, j, distPoints, arrPts, line, points

 

‘ user input – attractors, objects

arrStartPts = Rhino.GetObjects(“select start points”, 1)

 

For i = 0 To UBound(arrStartPts)

arrStartPts(i) = Rhino.PointCoordinates(arrStartPts(i))

arrAttPts = Rhino.GetObjects(“select the attractor points”, 1)

 

For j = 0 To UBound(arrAttPts)

arrAttPts(j) = Rhino.PointCoordinates(arrAttPts(j))

‘extLines = Rhino.AddLine (arrStartPt, arrAttPts(i))

 

addPoints = Rhino.PointAdd(arrStartPts(i), arrAttPts(j))

distPoints = Rhino.Distance(arrStartPts(i), arrAttPts(j))

ctrPoints = Rhino.PointDivide(addPoints, 2)

ctrPoints = Rhino.AddPoint(ctrPoints)

arrCtrPoints = Rhino.PointCoordinates(ctrPoints)

 

crvVertex = Rhino.MoveObject (ctrPoints, arrCtrPoints, Array(arrCtrPoints(0),arrCtrPoints(1),(distPoints*0.5)^2))

crvVertex = Rhino.PointCoordinates(crvVertex)

 

arrPts = Array(arrStartPts(i), crvVertex, arrAttPts(j))

line = Rhino.AddInterpCurve(arrPts)

 

Call curveDiv(line)

Rhino.DeleteObject line

Next

Next

 

points = Rhino.ObjectsByType(1)

Rhino.DeleteObjects points

End Sub

 

Function curveDiv(line)

 

Dim crvPoints, arrCrvPoints, dblTangPar, crvTangs, intPlane, intPlanePt, i, arrIntPlanes, j

 

crvPoints = Rhino.DivideCurve(line, 30)

 

For i = 0 To UBound(crvPoints)

 

arrCrvPoints = Rhino.AddPoint(crvPoints(i))

arrCrvPoints = Rhino.PointCoordinates(arrCrvPoints)

 

dblTangPar = Rhino.CurveClosestPoint(line, arrCrvPoints)

crvTangs = Rhino.CurveTangent(line, dblTangPar)

 

intPlane = Rhino.PlaneFromNormal(arrCrvPoints, crvTangs)

intPlane = Rhino.AddCircle(intPlane, 0.2)

 

intPlanePt = Rhino.CurveStartPoint(intPlane)

intPlanePt = Rhino.AddPoint(intPlanePt)

Next

 

Call interpolatedHelix(arrIntPlanes)

 

End Function

 

Function interpolatedHelix(arrIntPlanes)

 

Dim j, intPlanePts, intPlaneDivisions(), Count

 

arrIntPlanes = Rhino.ObjectsByType(4)

‘ user input

For j = 0 To UBound(arrIntPlanes)

 

intPlanePts = Rhino.DivideCurve(arrIntPlanes(j), 4, False, True)

ReDim Preserve intPlaneDivisions(Count)

intPlaneDivisions(Count) = intPlanePts

Count = Count + 1

Next

 

Dim blnPtsArray: blnPtsArray = 0, arrCrv: arrCrv = 0, helixCrv, k

 

helixCrv = Rhino.AddCurve(Array(intPlaneDivisions(arrCrv)(blnPtsArray), intPlaneDivisions(arrCrv + 1)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 2)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 3)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 4)(blnPtsArray), intPlaneDivisions(arrCrv + 5)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 6)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 7)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 8)(blnPtsArray), intPlaneDivisions(arrCrv + 9)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 10)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 11)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 12)(blnPtsArray), intPlaneDivisions(arrCrv + 13)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 14)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 15)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 16)(blnPtsArray), intPlaneDivisions(arrCrv + 17)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 18)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 18)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 19)(blnPtsArray), intPlaneDivisions(arrCrv + 20)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 21)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 22)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 23)(blnPtsArray), intPlaneDivisions(arrCrv + 24)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 25)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 26)(blnPtsArray + 3), intPlaneDivisions(arrCrv + 27)(blnPtsArray), intPlaneDivisions(arrCrv + 28)(blnPtsArray + 1), intPlaneDivisions(arrCrv + 29)(blnPtsArray + 2), intPlaneDivisions(arrCrv + 30)(blnPtsArray + 3) ))

 

For k = 0 To UBound(arrIntPlanes)

If Rhino.IsCircle(arrIntPlanes(k)) Then

Rhino.DeleteObject arrIntPlanes(k)

End If

Next

 

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

Pages of Code / RVB / Back