Circular Objects

This section demonstrates how to create the various circular objects.

The Arc Object

You create an Arc object by using the AddArc method. This method takes four arguments that determine the position and size of the arc:

Set ArcObject = Object.AddArc(CenterPoint, Radius, StartAngle, EndAngle) Table 8-2 provides a brief description of each argument.

Table 8-2. AddArc Method Parameters

Name

Data Type

Description

CenterPoint

Variant

A three-element array of doubles specifying the center of the arc in the WCS

Radius

Double

The radius of the arc

StartAngle

Double

The start angle of the arc given in radians with respect to the X-axis of the WCS

EndAngle

Double

The end angle of the arc given in radians with respect to the X-axis of the WCS

Arcs are drawn counterclockwise from the start angle to the end angle, as shown in Figure 8-1.

Triangle And Circle Combined

Figure 8-1. The Arc object

Figure 8-1. The Arc object

The following example creates an arc in the active drawing space (model or paper space) utilizing user input:

Public Sub TestAddArc() Dim varCenter As Variant Dim dblRadius As Double Dim dblStart As Double Dim dblEnd As Double Dim objEnt As AcadArc

On Error Resume Next '' get input from user With ThisDrawing.Utility varCenter = .GetPoint(, vbCr & "Pick the center point: ") dblRadius = .GetDistance(varCenter, vbCr & "Enter the radius: ") dblStart = .GetAngle(varCenter, vbCr & "Enter the start angle: ") dblEnd = .GetAngle(varCenter, vbCr & "Enter the end angle: ") End With

'' draw the arc If ThisDrawing.ActiveSpace = acModelSpace Then

Set objEnt = ThisDrawing.ModelSpace.AddArc(varCenter, dblRadius, _

dblStart, dblEnd)

Else

Set objEnt = ThisDrawing.PaperSpace.AddArc(varCenter, dblRadius, dblStart, dblEnd) End If objEnt.Update End Sub

The Circle Object

You can create a Circle object by specifying the position of the center and the radius, and using the AddCircle method:

Set CircleObject = Object.AddCircle(CenterPoint, Radius) Table 8-3 provides a brief description of each argument.

Table 8-3. AddCircle Method Parameters

Name

Data Type

Description

CenterPoint

Variant

A three-element array of doubles specifying the center of the

circle in the WCS

Radius

Double

The radius of the circle

Figure 8-2 illustrates the Circle object.

Figure 8-2 illustrates the Circle object.

Figure 8-2. The Circle object

The following example creates a circle based on user input:

Public Sub TestAddCircle() Dim varCenter As Variant Dim dblRadius As Double Dim objEnt As AcadCircle

On Error Resume Next

'' get input from user With ThisDrawing.Utility varCenter = .GetPoint(, vbCr & "Pick the centerpoint: ") dblRadius = .GetDistance(varCenter, vbCr & "Enter the radius: ") End With

'' draw the entity If ThisDrawing.ActiveSpace = acModelSpace Then

Set objEnt = ThisDrawing.ModelSpace.AddCircle(varCenter, dblRadius) Else

Set objEnt = ThisDrawing.PaperSpace.AddCircle(varCenter, dblRadius) End If objEnt.Update End Sub

The Ellipse Object

You use the AddEllipse method to create a fully closed Ellipse object. This method takes three parameters:

Set EllipseObject = Object.AddEllipse(CenterPoint, MajorAxis, RadiusRatio) Table 8-4 describes the AddEllipse method's parameters.

Table 8-4. AddEllipse Method Parameters

Name

Data Type

Description

CenterPoint

Variant

A three-element array of doubles specifying the center of the ellipse in the WCS.

MajorAxis

Variant

A three-element array of doubles specifying the vector of the major axis of the ellipse from the CenterPoint.

RadiusRatio

Double

The ratio of the lengths of the minor to major axis vectors: 0 < RadiusRatio < 1. A value of 1 generates an ellipse object that looks like a circle.

If you want to create an elliptical arc, set the StartAngle and EndAngle properties after you create the full Ellipse object, as shown in Figure 8-3.

Figure 8-3. The Ellipse object

Figure 8-3. The Ellipse object

The following example creates a new Ellipse object by first setting the center axis, major axis, and radius ratio. It then gets a start and an end angle from the user to convert the closed Ellipse into an elliptical arc.

Public Sub TestAddEllipse()

Dim dblCenter(0 To 2) As Double

Dim dblMajor(0 To 2) As Double

Dim dblRatio As Double

Dim dblStart As Double

Dim dblEnd As Double

Dim objEnt As AcadEllipse

On Error Resume Next

'' setup the ellipse parameters dblCenter(0) = 0: dblCenter(1) = 0: dblCenter(2) = 0 dblMajor(0) = 10: dblMajor(1) = 0: dblMajor(2) = 0 dblRatio = 0.5

'' draw the ellipse If ThisDrawing.ActiveSpace = acModelSpace Then

Set objEnt = ThisDrawing.ModelSpace.AddEllipse(dblCenter, dblMajor, dblRatio) Else

Set objEnt = ThisDrawing.PaperSpace.AddEllipse(dblCenter, dblMajor, dblRatio) End If objEnt.Update

'' get angular input from user With ThisDrawing.Utility dblStart = .GetAngle(dblCenter, vbCr & "Enter the start angle: ") dblEnd = .GetAngle(dblCenter, vbCr & "Enter the end angle: ") End With

'' convert the ellipse into elliptical arc With objEnt

.StartAngle = dblStart .EndAngle = dblEnd .Update End With End Sub

Was this article helpful?

0 0

Responses

  • Fre-qalsi
    HOW TO DRAW THREE VIEWS OF A CIRCULAR OBJECT AUTOCAD?
    6 years ago

Post a comment