Object Arrays

Use the ArrayPolar and ArrayRectangular methods to create an array of objects based on an existing object. Both methods copy the base object into a regular pattern at a specified distance from one another.

Creating a Polar Array of Objects

A polar array is a pattern of drawing objects lying on an arc's path. The ArrayPolar method creates a polar array, placing a specified number of objects over an angle. It returns an array of the new objects.

varObjectArray = DrawingObject.ArrayPolar (NumberofObjects, _ AngleToFill, ArrayCenter)

Table 10-8 explains this method's parameters.

Table 10-8. ArrayPolar Method Parameters

Name

Data Type

Description

NumberofObjects

Long

The number of objects in the polar array.

AngleToFill

Double

A nonzero value representing the angle, measured counterclockwise in radians, over which the array path will extend.

ArrayCenter

Variant

A three-element array of doubles specifying the 3-D WCS coordinates of the arc's center.

Always set the NumberofObjects parameter greater than 1. The original object is counted as an element of the polar array, even though this method doesn't return it in the object array. Consequently, the size of the object array is NumberofObjects-1. If you set NumberofObjects to 1, the method returns an empty array, but doesn't raise an error.

Figure 10-8 shows an ellipse arranged along an arc using the ArrayPolar method.

Numberof0bjects=5

Numberof0bjects=5

Base Object

4 Objects in Returned Array of Objects

AngleToFill

ArrayCenter

Figure 10-8. ArrayPolar arrangement of ellipses

The distance from the ArrayCenter to objects depends upon the object type. To specify the distance to the objects and the vector from which to measure the AngleToFill, use a circle or arc's center, a block or shape's insertion point, text's start point, or a line or trace's end point.

The following example shows how to implement this method. The objects returned in the array are designated as red.

Public Sub CreatePolarArray()

Dim objDrawingObject As AcadEntity Dim varEntityPickedPoint As Variant Dim varArrayCenter As Variant Dim lngNumberofObjects As Long Dim dblAngletoFill As Double Dim varPolarArray As Variant Dim intCount As Integer

On Error Resume Next

ThisDrawing.Utility.GetEntity objDrawingObject, varEntityPickedPoint, _

"Please select an entity to form the basis of a polar array" If objDrawingObject Is Nothing Then

MsgBox "You did not choose an object" Exit Sub End If varArrayCenter = ThisDrawing.Utility.GetPoint(, _ "Pick the center of the array: ") lngNumberofObjects = ThisDrawing.Utility.GetInteger( _

"Enter total number of objects required in the array: ") dblAngletoFill = ThisDrawing.Utility.GetReal( _

"Enter an angle (in degrees less than 360) over which the array should extend: ")

dblAngletoFill = ThisDrawing.Utility.AngleToReal _

(CStr(dblAngletoFill), acDegrees) If dblAngletoFill > 359 Then MsgBox "Angle must be less than 360 degrees", vbCritical Exit Sub End If varPolarArray = objDrawingObject.ArrayPolar(lngNumberofObjects, _

dblAngletoFill, varArrayCenter)

For intCount = 0 To UBound(varPolarArray) varPolarArray(intCount).Color = acRed varPolarArray(intCount).Update

Next End Sub

■ Note Unlike the AutoCAD ARRAY command, there is no ActiveX method available to control rotation of copied entities in polar arrays. You must handle that yourself through programming to rotate each copied entity appropriately along the array path's circumference.

Creating a Rectangular Array of Objects

A rectangular array is a grid pattern of drawing objects. This pattern may be two- or three-dimensional and you can construct it using the ArrayRectangular method. Just like the ArrayPolar method, this method returns an array of objects that hold a reference to the new drawing objects.

varObjectArray = DrawingObject.ArrayRectangular (NumberOfRows, _ NumberOfColumns, NumberOfLevels, DistBetweenRows, _ DistBetweenColumns, DistBetweenLevels)

Table 10-9 explains this method's parameters.

Table 10-9. ArrayRectangular Method Parameters

Name

Data Type

Description

NumberofRows

Long

A positive number representing the number of rows in the rectangular array. If this parameter is set to 1, then NumberofColumns must be greater than 1.

NumberOfColumns

Long

A positive number representing the number of columns in the rectangular array. If this parameter is set to 1, then NumberofRows must be greater than 1.

NumberOfLevels

Long

A positive number representing the number of levels in a 3-D array.

DistBetweenRows

Double

The distance between the rows. If this parameter is positive, rows extend upwards from the base object; if negative they extend downwards. If set to zero, objects are placed on top of the base object.

DistBetweenColumns

Double

The distance between the columns. If this parameter is positive, rows extend upwards from the base object; if negative they extend downwards. If set to zero, objects are placed on top of the base object.

DistBetweenLevels

Double

The distance between the levels. If this parameter is positive, rows extend upwards from the base object; if negative they extend downwards. If set to zero, objects are placed on top of the base object.

Figure 10-9 shows a two-dimensional rectangular array. A three-dimensional array is a simple extension of a two-dimensional array.

NumberofColumns=3

NumberofColumns=3

DistBetweenColumns

Figure 10-9. Objects arranged with ArrayRectangular

To create a two-dimensional array, set the NumberOfLevels parameters to 1, as shown in the following code example. Again, the new objects will be colored red in the array.

Public Sub Create2DRectangularArray()

Dim objDrawingObject As AcadEntity Dim varEntityPickedPoint As Variant Dim lngNoRows As Long Dim lngNoColumns As Long Dim dblDistRows As Long Dim dblDistCols As Long Dim varRectangularArray As Variant Dim intCount As Integer

On Error Resume Next

ThisDrawing.Utility.GetEntity objDrawingObject, varEntityPickedPoint, _ "Please pick an entity to form the basis of a rectangular array: " If objDrawingObject Is Nothing Then

MsgBox "You did not choose an object" Exit Sub End If lngNoRows = ThisDrawing.Utility.GetInteger( _

"Enter the required number of rows: ") lngNoColumns = ThisDrawing.Utility.GetInteger( _

"Enter the required number of columns: ") dblDistRows = ThisDrawing.Utility.GetReal( _

"Enter the required distance between rows: ") dblDistCols = ThisDrawing.Utility.GetReal( _

"Enter the required distance between columns: ")

varRectangularArray = objDrawingObject.ArrayRectangular(lngNoRows, _

lngNoColumns, 1, dblDistRows, dblDistCols, 0) For intCount = 0 To UBound(varRectangularArray) varRectangularArray(intCount).Color = acRed varRectangularArray(intCount).Update

Next End Sub

Was this article helpful?

0 0

Post a comment