Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:arraypolar [2015/09/14] (current)
Line 1: Line 1:
 +====== Creating Polar Arrays ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to create polar arrays of objects using RhinoScript.//​
 +
 +=====Question=====
 +I noticed that [[developer:​rhinoscript|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.
 +
 +<code vb>
 + ​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
 +
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/arraypolar.txt ยท Last modified: 2015/09/14 (external edit)