Ad

Monday, February 08, 2010

Area in Acres

Sometimes you want an area of polylines in acres. The code below will let you select one polyline at a time and return the cumulative area of the polylines selected. I’ve used a Sub to start the command and a function to loop until the user doesn’t select something. It might be able to be done in a better manner.
   1: Option Explicit
   2:  
   3: Dim dArea As Double
   4:     
   5: Sub GetArea()
   6:         
   7:     Do Until AddArea = False
   8:         
   9:     Loop
  10:     
  11: End Sub
  12:  
  13: Function AddArea() As Boolean
  14:     
  15:     Dim vPt As Variant
  16:     Dim oAcadObj As AcadObject
  17:     On Error Resume Next
  18:     ThisDrawing.Utility.GetEntity oAcadObj, vPt, "Select polyline: "
  19:     
  20:     If oAcadObj Is Nothing Then
  21:         dArea = 0
  22:         AddArea = False
  23:         Exit Function
  24:     End If
  25:     
  26:     If (TypeOf oAcadObj Is AcadLWPolyline) Then
  27:         Dim oPoly As AcadLWPolyline
  28:         Set oPoly = oAcadObj
  29:         dArea = dArea + (oPoly.Area / 43560)
  30:         ThisDrawing.Utility.Prompt "Area: " & Format(dArea, "#,##0.00") & " Acres" & vbCrLf
  31:         AddArea = True
  32:     Else
  33:         ThisDrawing.Utility.Prompt "Select Only Polylines" & vbCrLf
  34:         AddArea = True
  35:     End If
  36:     
  37: End Function

Here’s the completed code if you want to download it: http://style.civil3dreminders.com/AreaAcres.dvb It was created in Civil 3D 2010, so if you download the above file you might have to change the references.

5 comments:

tony carcamo said...

Does the polyline are have to be completely closed?

Christopher Fugitt said...

No it does not. If you want it to check if the polyline is closed you can modify the code with this:
If (TypeOf oAcadObj Is AcadLWPolyline) Then
Dim oPoly As AcadLWPolyline
Set oPoly = oAcadObj
If oPoly.Closed Then
dArea = dArea + (oPoly.Area / 43560)
ThisDrawing.Utility.Prompt "Area: " & Format(dArea, "#,##0.00") & " Acres" & vbCrLf
Else
ThisDrawing.Utility.Prompt "The Polyline needs to be closed." & vbCrLf
End If
AddArea = True

Unknown said...

What does one type to run the command?

Unknown said...

I use VBARUN to run it, but where is it supposed to display the area?

Christopher Fugitt said...

It should display it in the command line.

LinkWithin

Blog Widget by LinkWithin

Ad