Site Tools


Creating Polar Arrays

Developer: RhinoScript
Summary: Demonstrates how to create polar arrays of objects using RhinoScript.

Question

I noticed that RhinoScript does not have any array methods. That is, methods that transform objects similar to Rhino's array command, such as ArrayPolar? Is there a way to lay out objects similar to this using RhinoScript?

Answer

Consider the following example script code. Note, this code assumes that objects will be rotated around the world z-axis. But, one could certainly modify it to rotate around a user-defined axis.

 Option Explicit
 
 Sub MyArrayPolar
 
   Dim arrObjects, arrCenter, nCount
   Dim dAngle, arrAxis, arrXform, i
 
   arrObjects = Rhino.GetObjects("Select objects to array")
   If IsNull(arrObjects) Then Exit Sub
 
   arrCenter = Rhino.GetPoint("Center of polar array")
   If IsNull(arrCenter) Then Exit Sub
 
   nCount = Rhino.GetInteger("Number of items",,2)
   If IsNull(nCount) Then Exit Sub
 
   dAngle = 360.0 / nCount
 
   Rhino.EnableRedraw False
 
   For i = 1 To nCount - 1
     arrAxis = Array(0,0,1) ' world z-axis
     arrXform = Rhino.XformRotation(dAngle * i, arrAxis, arrCenter)
     Rhino.TransformObjects arrObjects, arrXform, True
   Next
 
   Rhino.EnableRedraw True
 
 End Sub


developer/scriptsamples/arraypolar.txt ยท Last modified: 2015/09/14 (external edit)