Offsetting Objects

The Offset method creates a new object with boundaries offset a specified distance from an existing object's boundaries. You can apply this method to the Arc, Circle, Ellipse, Line, LightweightPolyline, Polyline, Spline, and Xline objects. This method returns an array of the newly created object(s). Even though this array frequently contains only one object of the same type as the object from which it is offset, this is not always this case, as seen in the example below.

varObjectArray = Object.Offset(OffsetDistance) Table 10-4 explains this method's parameter.

Table 10-4. The Object.Offset Method Parameter

Name_Data Type Description_

OffsetDistance Double A nonzero number that indicates the offset's size and direction.

Negative numbers mean that the offset makes the new object smaller than the original. If this has no meaning, as for a single straight line, a negative number positions the new object closer to the WCS origin.

In Figure 10-4, the center object is an Ellipse from which the two other objects have been offset. You can see that the new objects are not Ellipses as each point of each new object is the same distance from the original Ellipse. In these cases, the returned object is a Spline. In this example, the negative offset must be greater than 50.

Figure 10-4. Offset objects

The following code sample creates the Ellipse and Splines in Figure 10-4 and shows the user a message box of the new objects' types.

Public Sub OffsetEllipse()

Dim objEllipse As AcadEllipse Dim varObjectArray As Variant Dim dblCenter(2) As Double Dim dblMajor(2) As Double dblMajor(0) = 100#

Set objEllipse = ThisDrawing.ModelSpace.AddEllipse(dblCenter, dblMajor, _

varObjectArray = objEllipse.Offset(50)

MsgBox "The offset object is a " & varObjectArray(0).ObjectName varObjectArray = objEllipse.Offset(-25)

MsgBox "The offset object is a " & varObjectArray(0).ObjectName

Figure 10-4. Offset objects

Offset Object

Offset Object

End Sub

■ Note For the sake of accuracy, because offsetting an Ellipse creates nonelliptical Spline entities, instead consider creating new Ellipse entities with calculated geometry. This produces accurate Ellipse entities instead of approximated elliptical Splines. The same is true for offsetting Spline or curve-fitted Polyline or LightweightPolyline entities.

0 0

Post a comment