To create a region, use the AddRegion method. This method will create a region out of every closed loop formed by the input array of curves. AutoCAD converts closed 2D and planar 3D polylines to separate regions, then converts polylines, lines, and curves that form closed planar loops. If more than two curves share an endpoint, the resulting region might be arbitrary. Because of this, several regions may actually be created when using the AddRegion method. Use a variant to hold the newly created array of regions.
To calculate the total number of Region objects created, use the UBound and LBound VBA functions, as in the following example:
UBound(objRegions) - LBound(objRegions) + 1
where objRegions is a variant containing the return value from AddRegion. This statement will calculate the total number of regions created.
The following code example creates a region from a single circle.
Sub Ch4_CreateRegion()
' Define an array to hold the
' boundaries of the region.
Dim curves(0 To 0) As AcadCircle
' Create a circle to become a
' boundary for the region.
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 2
center(1) = 2
center(2) = 0
radius = 5#
Set curves(0) = ThisDrawing.ModelSpace.AddCircle _
(center, radius)
' Create the region
Dim regionObj As Variant
regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
ZoomAll
End Sub