Message 1 of 3
AreaCalc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The HVAC guys here at my office asked me to come up with an area calculation for them to use to do their loads. The following was something quick I came up with for them to use right away, but I'd like for them to be able to window a whole mess of rectangle or polyline areas and have the text automatically inserted into the center of those areas:
Public Sub AreaCalc()
Dim objEnt As AcadLWPolyline
Dim varPick As Variant
Dim sngArea As Single
Dim strArea As String
Dim objText As AcadText
Dim varInsert As Variant
Dim varScale As Variant
Dim dblHeight As Double
Dim strLayerName As String
Dim objLayer As AcadLayer
On Error Resume Next
With ThisDrawing.Utility
.GetEntity objEnt, varPick, vbCr & "Select area/s to calculate: "
If Err Then
MsgBox ("You did not select a polyline!")
Exit Sub
Else
sngArea = objEnt.Area
varInsert = .GetPoint(, vbCr & "Select insert point for area text: ")
End If
End With
varScale = ThisDrawing.GetVariable("dimscale")
Select Case varScale
Case "24"
dblHeight = 2
Case "48"
dblHeight = 4.5
Case "96"
dblHeight = 9
Case "128"
dblHeight = 12
Case "192"
dblHeight = 18
End Select
strArea = CInt(sngArea / 144)
If ThisDrawing.ActiveSpace = acModelSpace Then
Set objText = ThisDrawing.ModelSpace.AddText((strArea) & " SF", varInsert, dblHeight)
End If
strLayerName = "M-AREA"
If Not strLayerName Then
objLayer = ThisDrawing.Layers.Add(strLayerName)
objLayer.Linetype = "continuous"
objLayer.color = acWhite
End If
objText.Layer = "m-area"
objText.Update
End Sub
So how would you guys improve on this and make it so that the text is input in the center of each area automatically. Oh yeah, and also how would you change it to do multiple areas at once?
Thanks,
commakozzi
Public Sub AreaCalc()
Dim objEnt As AcadLWPolyline
Dim varPick As Variant
Dim sngArea As Single
Dim strArea As String
Dim objText As AcadText
Dim varInsert As Variant
Dim varScale As Variant
Dim dblHeight As Double
Dim strLayerName As String
Dim objLayer As AcadLayer
On Error Resume Next
With ThisDrawing.Utility
.GetEntity objEnt, varPick, vbCr & "Select area/s to calculate: "
If Err Then
MsgBox ("You did not select a polyline!")
Exit Sub
Else
sngArea = objEnt.Area
varInsert = .GetPoint(, vbCr & "Select insert point for area text: ")
End If
End With
varScale = ThisDrawing.GetVariable("dimscale")
Select Case varScale
Case "24"
dblHeight = 2
Case "48"
dblHeight = 4.5
Case "96"
dblHeight = 9
Case "128"
dblHeight = 12
Case "192"
dblHeight = 18
End Select
strArea = CInt(sngArea / 144)
If ThisDrawing.ActiveSpace = acModelSpace Then
Set objText = ThisDrawing.ModelSpace.AddText((strArea) & " SF", varInsert, dblHeight)
End If
strLayerName = "M-AREA"
If Not strLayerName Then
objLayer = ThisDrawing.Layers.Add(strLayerName)
objLayer.Linetype = "continuous"
objLayer.color = acWhite
End If
objText.Layer = "m-area"
objText.Update
End Sub
So how would you guys improve on this and make it so that the text is input in the center of each area automatically. Oh yeah, and also how would you change it to do multiple areas at once?
Thanks,
commakozzi