Option Explicit
‘Adolfo Nadal -Archiologics

Call Main()
Sub Main()
Dim strObj : strObj = Rhino.GetObject(“obj”,4)
Dim strCrvs : strCrvs = Rhino.GetObjects(“crvs”,4)

Dim arrCtPt : arrCtPt = Rhino.CurveAreaCentroid(strObj)

‘let’s try to get the fckg normal vector to the curve
Dim strdecide: strdecide = Rhino.GetString(“wanna try to select points on your own?”,”yes”,array(“yes”,”no”))
Dim objDom : objDom = CurveDomain(strObj)
Dim xP
Dim yP

If strdecide = “no” Then
xP = Rhino.EvaluateCurve(strObj,0)
yP = Rhino.EvaluateCurve(strObj,(objDom(1)-objDom(0))/4)
arrCtPt(0) = Rhino.GetPoint (“center Pt”)
xP = Rhino.GetPoint(,,”pt 1 on X dir”)
yP = Rhino.GetPoint(,,”pt 1 on Y dir”)
End If

Dim vNormal : vNormal = Rhino.VectorAdd (Rhino.VectorUnitize(Rhino.VectorCrossProduct(xP,yP)),arrCtPt(0))

Dim arrPerpPlane : arrPerpPlane = Rhino.PlaneFromFrame(arrCtPt(0),xP,yP)

‘let’s try to do the same with the curves…
Dim strCrv
Dim crvPt, crvTangent, crvPerp, crvNormal
Dim crvCurvature
Dim t

Dim orientObj()
Rhino.EnableRedraw False
For Each strCrv In strCrvs

Dim crvDom : crvDom = Rhino.CurveDomain(strCrv)

Dim arrStPt : arrStPt = Rhino.CurveStartPoint(strCrv)
Dim arrEnPt : arrEnPt = Rhino.CurveEndPoint(strCrv)
Dim m : m=0

For t =0 To crvDom(1) Step (crvDom(1)-crvDom(0))/2
crvCurvature = Rhino.CurveCurvature(strCrv,t)
If IsNull (crvCurvature) Then
crvPt = Rhino.EvaluateCurve(strCrv,t)
crvTangent = Rhino.VectorUnitize(Rhino.CurveTangent(strCrv,t))
crvPerp = Array(0,0,1)
crvPt = crvCurvature(0)
crvTangent = Rhino.VectorUnitize(crvCurvature(1))
crvPerp = Rhino.VectorUnitize(crvCurvature(4))
End If

crvNormal = Rhino.VectorAdd(Rhino.VectorUnitize(Rhino.VectorCrossProduct(crvTangent,crvPerp)),crvPt)
Dim CrossSectionPlane : CrossSectionPlane = Rhino.PlaneFromFrame(crvPt,crvPerp,crvNormal)
Dim xPtgt : xPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(1)),crvPt)
Dim zPtgt : zPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(2)),crvPt)

Dim strObj2 : strObj2 = Rhino.CopyObject(strObj,array(0,0,0),array(0,0,0))

‘We orient the object
ReDim Preserve orientObj(m)
orientObj(m) = Rhino.OrientObject (strObj2,array(arrCtPt(0),xP,yP),array(crvPt,xPtgt,crvNormal),1)

‘we scale the object
‘for the scalefactor we need to “unitize” the domain
Dim scalefactor, n
Dim unitize : unitize = crvDom(1)-crvDom(0)
n = 180*(t-crvDom(0))/unitize
If n = 0 Or n Mod 180 =0 Then
scalefactor =.5
scalefactor = (1/(2*sin(n)))+1/2
End If

Rhino.ScaleObject orientObj(m),crvPt,array(scalefactor,scalefactor,scalefactor)
m =m+1
Rhino.Command “Sweep1 _SelID ” & strCrv & ” _SelID ” & orientObj(0) & ” _SelID ” & orientObj(1) & ” _SelID ” & orientObj(2) & “_enter _enter Natural enter enter”

Rhino.EnableRedraw True
End Sub


Leave a Reply

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

You are commenting using your 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