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

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