WARNING: You're viewing the older Rhino 5 version of this page! View the Rhino 6 version instead.

### Create Square Pipes

Demonstrates how to create square pipes using RhinoScript.

VBScript

Option Explicit

Sub SquarePipe

' Declare local variables
Dim arrCrvs, strCrv, dblLength
Dim arrStart, dblParam, arrPlane
Dim x0, x1, y0, y1, arrX, arrY
Dim arrPoints(4), strSqr

' Pick the input, or path, curves
arrCrvs = Rhino.GetObjects("Select curves", 4)
If IsNull(strCrv) Then Exit Sub

' Specify the lengths of the sides of the square
dblLength = Rhino.GetReal("Length of sides", 1.0, 0.0)
If Not IsNumeric(dblLength) Or dblLength <= 0 Then Exit Sub

Call Rhino.EnableRedraw(False)

For Each strCrv In arrCrvs

' Determine the curve's starting point
arrStart = Rhino.CurveStartPoint(strCrv)

' Determine the parameter at the starting point
dblParam = Rhino.CurveClosestPoint(strCrv, arrStart)

' Detemine the curve's perpendicular plane at its starting point.
' We can use this plane to cook up the coordinates of the square.
arrPlane = Rhino.CurvePerpFrame(strCrv, dblParam)

' Scale the vectors based on the user input
arrX = Rhino.VectorScale(arrPlane(1), dblLength * 0.5)
arrY = Rhino.VectorScale(arrPlane(2), dblLength * 0.5)

' Cook up some temporary points

' Define the points of the square
arrPoints(4) = arrPoints(0)

' Create the square