RhinoScript – Surfaces: Part 01

surfaces

GO BACK TO CODESHARE PAGE

Example 01: Notating the CVs on a surface

srfnums

 
Option Explicit
 
'Script written by www.supermanoeuvre.com

Call notateSurface()
 
Sub notateSurface()
 
	'------------------------------------------------------------------------------------------------------
	' USER INPUT
	Dim strSrf : strSrf = rhino.getObject("Gimme SURFACE object!", 8)
	If isNull(strSrf) Then Exit Sub
	Dim numSpans : numSpans = rhino.GetInteger("Gimme niumber of dots in each direction", 7, 4, 50)
	If isNull(numSpans) Then Exit Sub
 
	'------------------------------------------------------------------------------------------------------
	' SCRIPT BODY
	rhino.print "!!! SCRIPT STARTED !!!"
 
	'-------------------------------------------------------
	' Get U vals
	Dim arrSrfDomU : arrSrfDomU = Rhino.SurfaceDomain(strSrf,0)
	Dim uMin       : uMin       = arrSrfDomU(0)
	Dim uMax       : uMax       = arrSrfDomU(1)
	Dim uStep      : uStep      = (uMax-uMin) / numSpans
 
	'-------------------------------------------------------
	' Get V vals
	Dim arrSrfDomV : arrSrfDomV = Rhino.SurfaceDomain(strSrf,1)
	Dim vMin       : vMin       = arrSrfDomV(0)
	Dim vMax       : vMax       = arrSrfDomV(1)	
	Dim vStep      : vStep      = (vMax-vMin) / numSpans	
 
	'-------------------------------------------------------
	' Create nodes
	Dim i,j
	Dim Count
	Dim srfParam, arrPtEval
 
	count = 0
 
	For i = 0 To numSpans
		For j = 0 To numSpans
			arrPtEval = rhino.evaluateSurface( strSrf, Array(i*uStep,j*vStep) )	
			rhino.addtextDot count, arrPtEval
			count = count + 1
		Next		
	Next
 
	rhino.print "!!! SCRIPT COMPLETED !!!"
 
End Sub

As with anything, there are numerous ways to perform the same task. You could try doing most of the calculation of UV values within the definition of the loop itself, like this:

 
For i = uMin To uMax Step uStep
		For j = vMin To vMax Step vStep
			arrPtEval = rhino.evaluateSurface( strSrf, Array(i,j) )	
			rhino.addtextDot count, arrPtEval
			count = count + 1
		Next			
Next

Example 02: Notating the UV Domains on a surface

surfaces2

 
Option Explicit
'Script written by www.supermanoeuvre.com

Call notateSurfaceDomain()
 
Sub notateSurfaceDomain()
 
	'------------------------------------------------------------------------------------------------------
	' USER INPUT
	Dim strSrf : strSrf = rhino.getObject("Gimme SURFACE object!", 8)
	If isNull(strSrf) Then Exit Sub
 
	Dim numU : numU = rhino.getInteger("Gimme number of POINTS in the U direction of surface!", 8, 2, 20)
	If isNull(numU) Then Exit Sub
	Dim numV : numV = rhino.getInteger("Gimme number of POINTS in the V direction of surface!", 8, 2, 20)
	If isNull(numV) Then Exit Sub
 
	'------------------------------------------------------------------------------------------------------
	' SCRIPT BODY
	rhino.print "!!! SCRIPT STARTED !!!"
 
	'-------------------------------------------------------
	' Get U vals
	Dim arrSrfDomU : arrSrfDomU = Rhino.SurfaceDomain(strSrf,0)
	Dim uMin       : uMin       = arrSrfDomU(0)
	Dim uMax       : uMax       = arrSrfDomU(1)
	Dim uSteps     : uSteps     = (uMax-uMin) / numU
 
	'-------------------------------------------------------
	' Get V vals
	Dim arrSrfDomV : arrSrfDomV = Rhino.SurfaceDomain(strSrf,1)
	Dim vMin       : vMin       = arrSrfDomV(0)
	Dim vMax       : vMax       = arrSrfDomV(1)	
	Dim vSteps     : vSteps     = (vMax-vMin) / numV
 
	'-------------------------------------------------------
	' Create nodes
	Dim i,j
	Dim uCount, vCount
	Dim srfParam, arrPtEval, strLabel
 
	uCount = 0
 
	For i = uMin To uMax Step uSteps
		vCount = 0
		For j = vMin To vMax Step vSteps
			arrPtEval = rhino.evaluateSurface( strSrf, Array(i,j) )	
			strLabel  = "u: " & uCount & "__v: " & vCount
				rhino.addtextDot strLabel, arrPtEval
			vCount = vCount + 1			
		Next		
		uCount = uCount + 1		
	Next
 
	rhino.print "!!! SCRIPT COMPLETED !!!"
 
End Sub

GO BACK TO CODESHARE PAGE


About this entry