A pool of resources
Lead On

    


This rhinoscript, developed for circulation diagrams, converts curves into variable styles of surfaced three dimensional arrows. The arrows themselves can vary in scale, proportion, angle, and several other parameters.


platform: Rhino Script
function: Representation Aid

 


Option Explicit
'Script written by <David Mans>
'Script copyrighted by <Neoarchaic Design>
'Script version Sunday, June 08, 2008 1:19:49 AM

Call Main()
Sub Main()
	Dim crv: crv = Rhino.GetObjects("Select Curves",4)
	If isNull(crv) Then Exit Sub
	Dim arrItems, arrValues, arrResults
	arrItems = array("scale_width","twist_angle","tip_location","tip_angle","start_width","end_width","tip_length","type_(1)or(2)","curved arrows")
	arrValues = array(1,0,.95,45,.2,.5,1,1,True)
	arrResults = Rhino.PropertyListBox (arrItems, arrValues ,,"Arrow Parameters")
	Dim i
	If arrResults(0) < .1 Then
		arrResults(0) = .1
	End If
	If arrResults(2) > .99 Then
		arrResults(2) = .99
	End If
	If arrResults(4) < .01 Then
		arrResults(4) = .01
	End If
	If arrResults(5) < .01 Then
		arrResults(5) = .01
	End If
	If arrResults(7) < 1 Then
		arrResults(7) = 0
	ElseIf arrResults(7) > 1 Then
		arrResults(7) = 1
	End If

	Call Rhino.EnableRedraw(False)
	For i = 0 To uBound(crv) Step 1
		Call reparameterize(crv(i))
		Call curveArrows(crv(i),CDbl(arrResults(0)),CDbl(arrResults(1)),CDbl(arrResults(2)),CDbl(arrResults(3)),CDbl(arrResults(4)),CDbl(arrResults(5)),CDbl(arrResults(6)),CInt(arrResults(7)),CBool(arrResults(8)))
	Next
	Call Rhino.EnableRedraw(True)
End Sub
Function curveArrows(curve, dblScale,twistAngle,tip,headAngle,edgeParaA,edgeParaB,width,dblType,CrvBln)
	curveArrows = Null
	Dim i,j, crv, tipEdge, crvCpy, crvDom, dis,scale, count, crvFrame, strProfSet(1),tempCrv, crvX, srf(3)
	Dim endPt, midPtA, midPtB
	count = 2+CInt(twistAngle/90)
	ReDim frame(count), pt(count*2+1), swProfSetA(count-1), swProfSetB(count-1),crvA(count-1),crvB(count-1),parameter(count)
	ReDim srfEdge(2), edgeA(count-1), edgeB(count-1)

	If width <> 0 Then
		tip = (Rhino.CurveLength(curve)-width)/Rhino.CurveLength (curve)
	End If
	crvDom = Rhino.CurveDomain(curve)(1)
	parameter(0) = 0
	For i = 0 To count-1 Step 1
		parameter(i) = (crvDom*tip/(count-1))*i
	Next
	parameter(count) = crvDom-(crvDom-crvDom*tip)*.5

	dis = Rhino.Distance(Rhino.EvaluateCurve(curve,crvDom*tip),Rhino.EvaluateCurve(curve,crvDom))*dblScale
	scale = dis*0.5

	j=0
	For i = 0 To count Step 1
		crvFrame = Rhino.CurveFrame(curve,parameter(i))
		If i = count Then
			frame(i) = Rhino.RotatePlane(crvFrame,(twistAngle/(count-1))*(i-1),crvFrame(1))
		Else
			frame(i) = Rhino.RotatePlane(crvFrame,(twistAngle/(count-1))*i,crvFrame(1))
		End If
		pt(j) = Rhino.PointAdd(frame(i)(0),Rhino.VectorRotate(Rhino.VectorScale(frame(i)(2),scale),90-headAngle,frame(i)(3)))
		j=j+1
		pt(j) = Rhino.PointAdd(frame(i)(0),Rhino.VectorRotate(Rhino.VectorScale(frame(i)(2),scale),90+headAngle,frame(i)(3)))
		j=j+1
		If i<count Then
			If CrvBln = True Then
				tempCrv = Rhino.AddInterpCurve(array(pt(j-2),frame(i)(0),pt(j-1)),3)
			Else
				tempCrv = Rhino.AddInterpCurve(array(pt(j-2),frame(i)(0),pt(j-1)),1)
			End If
			crvX = Rhino.SplitCurve(tempCrv,Rhino.CurveDomain(tempCrv)(1)*.5,True)
			reparameterize(crvX(0))
			crvA(i) = crvX(0)
			reparameterize(crvX(1))
			crvB(i) = crvX(1)
		End If
	Next
	crvCpy = Rhino.CopyObject(curve)
	crv = Rhino.SplitCurve (crvCpy , crvDom*tip,True)
	endPt = Rhino.EvaluateCurve(curve,crvDom)
	midPtA= Rhino.PointAdd(frame(count)(0),Rhino.VectorRotate(Rhino.VectorScale(frame(count)(2),scale*.5),90-headAngle,frame(count)(3)))
	midPtB= Rhino.PointAdd(frame(count)(0),Rhino.VectorRotate(Rhino.VectorScale(frame(count)(2),scale*.5),90+headAngle,frame(count)(3)))

	srfEdge(0) = Rhino.AddInterpCurve(array(endPt,midPtA,pt(j-4)))
	srfEdge(1) = Rhino.AddInterpCurve(array(endPt,midPtB,pt(j-3)))
	srfEdge(2) = Rhino.AddInterpCurve(array(endPt,frame(count)(0),frame(count-1)(0)))
	If dblType = 1 Then
		srf(0) = Rhino.AddEdgeSrf (array(crvA(count-1),crv(1),srfEdge(0)))
	End If
	srf(1) = Rhino.AddEdgeSrf (array(crvB(count-1),crv(1),srfEdge(1)))
	If edgeParaA>edgeParaB Then
		edgeParaB = -(edgeParaA-edgeParaB)/(count-1)
	ElseIf edgeParaB>edgeParaA Then
		edgeParaB = (edgeParaB-edgeParaA)/(count-1)
	Else
		edgeParaB = 0
	End If
	For i = 0 To  count-1 Step 1
		edgeA(i) = Rhino.SplitCurve(crvA(i),Rhino.CurveDomain(crvA(i))(1)*(1-(edgeParaA+edgeParaB*i)),True)
		edgeB(i) = Rhino.SplitCurve(crvB(i),Rhino.CurveDomain(crvB(i))(1)*(edgeParaA+edgeParaB*i),True)
	Next
	For i = 0 To count-1 Step 1
		swProfSetA(i) = ("_SelID " & edgeA(i)(1) & " ")
		swProfSetB(i) = ("_SelID " & edgeB(i)(0) & " ")

	Next
	strProfSet(0) = Join(swProfSetA)
	strProfSet(1) = Join(swProfSetB)
	If dblType = 1 Then
		Call Rhino.Command( "-_Sweep1 " & "_SelID " & crv(0) & " " & strProfSet(0) & " _Enter _Simplify=None Enter")
		srf(2)= Rhino.FirstObject()
	End If
	Call Rhino.Command( "-_Sweep1 " & "_SelID " & crv(0) & " " & strProfSet(1) & " _Enter  _Simplify=None Enter")
	srf(3)= Rhino.FirstObject()

	If dblType = 1 Then
		Call Rhino.JoinSurfaces(srf,True)
	Else
		Call Rhino.JoinSurfaces(array(srf(1),srf(3)),True)
	End If
	Call Rhino.DeleteObjects(crv)
	Call Rhino.DeleteObjects(srfEdge)
	For i = 0 To count-1 Step 1
		Call Rhino.DeleteObjects(edgeA(i))
		Call Rhino.DeleteObjects(edgeB(i))
	Next
End Function
Function reparameterize(strCurveID)
	If Rhino.IsCurve(strCurveID) = True Then
		Call rhino.SelectObject(strCurveID)
		Call rhino.Command("reparameterize 0 1")
		Call rhino.UnselectAllObjects()
	End If
	If Rhino.IsSurface(strCurveID) = True Then
		Call rhino.SelectObject(strCurveID)
		Call rhino.Command("reparameterize 0 1 0 1")
		Call rhino.UnselectAllObjects()
	End If
End Function


Reply