Calculate the area defined by points entered from the user To obtain the area specified by points from the userYou can measure an arbitrary closed region defined by the 2D or 3D points specified by the user. The points must be coplanar.
To obtain the area specified by points from the user
- Use the GetPoint method in a loop to obtain the points from the user.
- Create a lightweight polyline from the points provided by the user. Use the AddLightweightPolyline method to create the polyline.
- Use the Area property to obtain the area of the newly created polyline.
- Erase the polyline using the Erase method.
Calculate the area defined by points entered from the user
This example prompts the user to enter five points. A polyline is then created out of the points entered. The polyline is closed, and the area of the polyline is displayed in a message box.
Sub Ch3_CalculateDefinedArea()
Dim p1 As Variant
Dim p2 As Variant
Dim p3 As Variant
Dim p4 As Variant
Dim p5 As Variant
' Get the points from the user
p1 = ThisDrawing.Utility.GetPoint(, vbCrLf & "First point: ")
p2 = ThisDrawing.Utility.GetPoint(p1, vbCrLf & "Second point: ")
p3 = ThisDrawing.Utility.GetPoint(p2, vbCrLf & "Third point: ")
p4 = ThisDrawing.Utility.GetPoint(p3, vbCrLf & "Fourth point: ")
p5 = ThisDrawing.Utility.GetPoint(p4, vbCrLf & "Fifth point: ")
' Create the 2D polyline from the points
Dim polyObj As AcadLWPolyline
Dim vertices(0 To 9) As Double
vertices(0) = p1(0): vertices(1) = p1(1)
vertices(2) = p2(0): vertices(3) = p2(1)
vertices(4) = p3(0): vertices(5) = p3(1)
vertices(6) = p4(0): vertices(7) = p4(1)
vertices(8) = p5(0): vertices(9) = p5(1)
Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline _
(vertices)
polyObj.Closed = True
ThisDrawing.Application.ZoomAll
' Display the area for the polyline
MsgBox "The area defined by the points is " & _
polyObj.Area, , "Calculate Defined Area"
End Sub