Option Explicit Sub Pattern() Dim i1,i2,i3 Dim strBaseSurface Dim intDomainU,intDomainV, dblU,dblV, arrParameter, dblBaseU,dblParameterU,dblParameterV Dim arrNormal,arrPntOnPar Dim arrCPtBody(),arrCount Dim dblShiftV,dblShiftU Dim arrPoint '//////////////////////////////////////// '/////////// Parameters /////////////// '//////////////////////////////////////// Dim parDivisionU,parDivisionV Dim parShiftV,parShiftU 'Parameter which defines division of pattern in U and V direction. parDivisionU = 140 parDivisionV = 140 'Parameter which defines pattern itself, by shifting control points. 'Parameter value must be between -2 and 2. parShiftV = 0.5 parShiftU = 0.5 '//////////////////////////////////////// '/////////// Parameters /////////////// '//////////////////////////////////////// 'Prompts user to pick “bone” surface, and calculates division of pattern. strBaseSurface = Rhino.GetObject("Select Srf.",8) intDomainU = Rhino.SurfaceDomain (strBaseSurface, 0) intDomainV = Rhino.SurfaceDomain (strBaseSurface, 1) dblU = (intDomainU(1)-intDomainU(0))/parDivisionU dblV = (intDomainV(1)-intDomainV(0))/parDivisionV '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'First "For" defines new position of control point in V direction according to parameters. dblBaseU = dblU i3=-1 For i1=0 To parDivisionU-4 dblBaseU = dblBaseU + dblU dblParameterV = 0 If i1 = 1 Then dblShiftV = 0 End If If i1 > 1 Then If i1 Mod 2 = 1 Then dblShiftV = 0 End If End If If i1 = 0 Then dblShiftV = parShiftV End If If i1 > 1 Then If i1 Mod 2 = 0 Then dblShiftV = parShiftV End If End If 'Second "For" defines new position of control point in U direction according to parameters. dblParameterV = (dblV*dblShiftV)+ dblV For i2=0 To parDivisionV-4 i3=i3+1 If i2 = 1 Then dblShiftU = 0 End If If i2 > 1 Then If i2 Mod 2 = 1 Then dblShiftU = 0 End If End If If i2 = 0 Then dblShiftU = parShiftU End If If i2 > 1 Then If i2 Mod 2 = 0 Then dblShiftU = parShiftU End If End If dblParameterU = dblBaseU + (dblU*dblShiftU) dblParameterV = dblParameterV + dblV 'This part creates 3D point based on newly calculated UV parameters of the surface 'and adds a normal vector at this point as a direction of movement. arrParameter = Array(dblParameterU,dblParameterV) arrPntOnPar = Rhino.SurfaceEvaluate (strBaseSurface, arrParameter, 1) arrNormal = Rhino.SurfaceNormal (strBaseSurface, arrParameter) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'This part tests if the 3D point is "odd or even" point of pattern 'and according to result it reverse direction of movement or not. If i1 = 1 Then arrNormal = Rhino.VectorReverse (arrNormal) End If If i1 > 1 Then If i1 Mod 2 = 1 Then arrNormal = Rhino.VectorReverse (arrNormal) End If End If If i2 = 1 Then arrNormal = Rhino.VectorReverse (arrNormal) End If If i2 > 1 Then If i2 Mod 2 = 1 Then arrNormal = Rhino.VectorReverse (arrNormal) End If End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'This part stores newly calculated points of pattern in to dynamic array. arrPoint = Rhino.PointAdd (arrPntOnPar(0), arrNormal) ReDim Preserve arrCPtBody(i3) arrCPtBody(i3) = arrPoint ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Next Next 'This part finally adds new surface with plastic pattern according to parameters defined at beginning. arrCount = Array(parDivisionU-3,parDivisionV-3) Rhino.AddSrfPtGrid arrCount, arrCPtBody '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub Pattern