Well, if you can do that then this may be overkill but here it is anyway. There will be way more here than you are interested in and I'm sorry for bad coding techniques but this is a few years old. Of course you will not be interested in the buldges but I needed them to show the sheetmetal bends.
here is the form code:
'frmMain
Option Explicit
' form scope variables
' the offset (thickness of the shape)
Private dOffset As Double
' Insertion Point
Private Ipt(0 To 2) As Double
' Viewport scale
Private ViewScale As Double
' how many breaks
Private Breaks As Integer
' the blank length
Private brkLength As Double
' break calculation modifier
Private dblModifier As Double
Private Sub Go()
Dim varCoords As Variant
Dim NewCoords() As Double
' the three points necessary to build an angular dimension
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
Dim pt3(0 To 2) As Double
Dim varRet As Variant
Dim varStPt As Variant
Dim ObjEntity As AcadLWPolyline
Dim objNewEntity As AcadLWPolyline
Dim angle1 As Double
Dim angle2 As Double
Dim angle3 As Double
Dim Dir1 As Double
Dim Dir2 As Double
Dim DistTemp As Double
Dim Dist1 As Double
Dim Dist2 As Double
Dim Plus As Boolean
Dim aPlus As Boolean
Dim I As Integer
Dim J As Integer
Dim count As Integer
Dim NewCount As Integer
Dim currentY As Integer
Dim currentOppY As Integer
Dim ProjectExist As Boolean
Dim CurrSegCount As Integer
Dim CurrOppSegCount As Integer
Dim BulgeArray() As Integer
Dim AngleArray() As Double
Const x = 0
Const y = 1
' get the ployline
Set ObjEntity = Get_Poly
' if it's a closed polyline then it's going to look funky
If ObjEntity.Closed Then
MsgBox "This is a closed polyline, Hmmm..." & vbCr & _
"I REALLY Don't think you want to do that.. I quit"
End
End If
varCoords = ObjEntity.Coordinates
' if there are less than 5 points then you can't
' get an angle
If UBound(varCoords) < 5 Then ' inform and insult the user
MsgBox "This polyline has less than 2 sides you dork"
Exit Sub
End If
' set the new coordinates boundaries
count = UBound(varCoords)
ReDim NewCoords(count * 3)
NewCount = UBound(NewCoords)
' get the first vector of the polyline and the direction from point1 to point2
pt1(x) = varCoords(0): pt1(y) = varCoords(1)
pt2(x) = varCoords(2): pt2(y) = varCoords(3)
Dir1 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
' get the middle point so we can get a direction
Dist1 = Distance(pt1, pt2)
varStPt = ThisDrawing.Utility.PolarPoint(pt1, Dir1, 0.5 * Dist1)
angle1 = ThisDrawing.Utility.GetAngle(varStPt, "Pick Side To Offset: ")
' do we add 90 along the path or subtract 90 for the offset direction
Plus = isPlus(Dir1, angle1)
' and the array of the buldges
ReDim BulgeArray(CInt((count - 3) / 2) - 1)
ReDim AngleArray(UBound(BulgeArray))
' set the breaks to this number plus one
Breaks = UBound(BulgeArray) + 1
Dim TmpCount As Integer
' calculate the total segment count
TmpCount = CInt((count - 1) / 2)
TmpCount = (TmpCount * 2) + TmpCount
'initialize the j counter and the segment counters
J = 0
CurrSegCount = 0
CurrOppSegCount = TmpCount
' loop thru the points and process the polyline
For I = 5 To count Step 2
' points 1 thru 3
pt1(x) = varCoords(I - 5): pt1(y) = varCoords(I - 4)
pt2(x) = varCoords(I - 3): pt2(y) = varCoords(I - 2)
pt3(x) = varCoords(I - 1): pt3(y) = varCoords(I)
' get the distances
Dist1 = Distance(pt1, pt2)
Dist2 = Distance(pt2, pt3)
' get the directions
Dir1 = ThisDrawing.Utility.AngleFromXAxis(pt2, pt1)
Dir2 = ThisDrawing.Utility.AngleFromXAxis(pt2, pt3)
' set the small angle
angle1 = SmallAngle(Dir1, Dir2)
' reverse the direction of the first vector to follow the polyline path
Dir1 = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
' set the angle perpendicular to the current vector
If Plus Then
angle2 = Dir1 + dtr(90)
Else
angle2 = Dir1 - dtr(90)
End If
' is the current angle in the plus direction or not
aPlus = isPlus(Dir1, Dir2)
' first we sould test to see whether this is the first angle
' if it is then do the square corner stuff
If I = 5 Then ' first segment
' set the first and last points of the new polyline
' First Point
NewCoords(x) = varCoords(x): NewCoords(y) = varCoords(y)
' last point
NewCoords(NewCount - 1) = varCoords(x): NewCoords(NewCount) = varCoords(y)
' second to last point - move over the offset distance
varRet = ThisDrawing.Utility.PolarPoint(pt1, angle2, dOffset)
' set the coordinates
NewCoords(NewCount - 3) = varRet(x): NewCoords(NewCount - 2) = varRet(y)
' set the current y place and the opposite y place
currentY = 1
currentOppY = NewCount - 2
' segment index for the buldge calculation
CurrSegCount = 1
CurrOppSegCount = CurrOppSegCount - 2
End If
' do we project the bulge points on the existing line or the projected line
If Plus Then
If aPlus Then
ProjectExist = True
Else
ProjectExist = False
End If
Else
If aPlus Then
ProjectExist = False
Else
ProjectExist = True
End If
End If
' now calculate offset distance
If angle1 = 0 Then angle1 = dtr(360)
DistTemp = (dOffset / (Tan(0.5 * angle1)))
If angle1 = dtr(360) Then angle1 = 0
If ProjectExist Then ' project the buldge on the existing line
' go back dir1
varRet = ThisDrawing.Utility.PolarPoint(pt2, Dir1 - dtr(180), DistTemp)
NewCoords(currentY + 1) = varRet(x): NewCoords(currentY + 2) = varRet(y)
' now set the opposite corner
varRet = ThisDrawing.Utility.PolarPoint(varRet, angle2, dOffset)
NewCoords(currentOppY - 3) = varRet(x): NewCoords(currentOppY - 2) = varRet(y)
' now go up dir2
varRet = ThisDrawing.Utility.PolarPoint(pt2, Dir2, DistTemp)
NewCoords(currentY + 3) = varRet(x): NewCoords(currentY + 4) = varRet(y)
' reset currenty and opposite y
currentY = currentY + 4
currentOppY = currentOppY - 2
' set the buldge and move the counters
BulgeArray(J) = CurrSegCount
AngleArray(J) = Tan((dtr(180) - angle1) / 4)
CurrSegCount = CurrSegCount + 2
CurrOppSegCount = CurrOppSegCount - 1
Else ' project the buldge on the new line
' set angle3 to the perpendicular of the second line
If Plus Then
angle3 = Dir2 + dtr(90)
Else
angle3 = Dir2 - dtr(90)
End If
' set the existing
NewCoords(currentY + 1) = pt2(x): NewCoords(currentY + 2) = pt2(y)
' do the opposite
varRet = ThisDrawing.Utility.PolarPoint(pt2, angle2, dOffset)
NewCoords(currentOppY - 3) = varRet(x): NewCoords(currentOppY - 2) = varRet(y)
varRet = ThisDrawing.Utility.PolarPoint(pt2, angle3, dOffset)
NewCoords(currentOppY - 5) = varRet(x): NewCoords(currentOppY - 4) = varRet(y)
' reset the running counts of y placeholders
currentY = currentY + 2
currentOppY = currentOppY - 4
' set the buldge and move the counters
BulgeArray(J) = CurrOppSegCount
AngleArray(J) = Tan((dtr(180) - angle1) / 4)
CurrOppSegCount = CurrOppSegCount - 2
CurrSegCount = CurrSegCount + 1
End If
' If it's the last one then do the last stuff
If I = count Then ' the last one
' reset the offset angle to match
If Plus Then
angle2 = Dir2 + dtr(90)
Else
angle2 = Dir2 - dtr(90)
End If
NewCoords(currentY + 1) = varCoords(count - 1): NewCoords(currentY + 2) = varCoords(count)
' get the point we need
varRet = ThisDrawing.Utility.PolarPoint(pt3, angle2, dOffset)
' set the coordinates
NewCoords(currentY + 3) = varRet(x): NewCoords(currentY + 4) = varRet(y)
End If
' increment the buldge counter
J = J + 1
Next I
' make the polyline
Set objNewEntity = ThisDrawing.ModelSpace.AddLightWeightPolyline(NewCoords)
' do the bulges
Dim tmpDir As Double
For J = 0 To UBound(BulgeArray)
' which direction
If Plus Then
tmpDir = AngleArray(J)
Else
tmpDir = -AngleArray(J)
End If
objNewEntity.SetBulge BulgeArray(J), tmpDir
Next J
objNewEntity.Closed = True
' update the pline
objNewEntity.Update
' find the size of the object drawn so we can calculate the viewport
' and determine the scale factor
Dim varMin As Variant
Dim varMax As Variant
Dim Width As Double
Dim Height As Double
objNewEntity.GetBoundingBox varMin, varMax
' set the center point to be used by the viewport code
Ipt(0) = ((varMax(0) - varMin(0)) / 2) + varMin(0)
Ipt(1) = ((varMax(1) - varMin(1)) / 2) + varMin(1)
' get the height and width
Width = varMax(0) - varMin(0) + dOffset
Height = varMax(1) - varMin(1) + dOffset
If Width > 9.3 Or Height > 6.5 Then
ThisDrawing.SetVariable "Dimscale", 2
ViewScale = 0.5
Else
ThisDrawing.SetVariable "Dimscale", 1
ViewScale = 1
End If
' dimension the original one
Call DoDims(varCoords, ObjEntity)
End Sub
' takes a vector and a direction from the vector and returns
' whether or not the offset side perpendicular would be an addition
' of ninety degrees or a subtraction of ninety degrees from the
' original vector direction
Private Function isPlus(Vector As Double, Side As Double) As Boolean
Dim angle1 As Double
Dim angle2 As Double
angle1 = Vector
angle2 = Vector + dtr(180)
If angle2 > dtr(360) Then angle2 = angle2 - dtr(360)
If angle2 > angle1 Then ' angle 2 is the large one
If Side > angle1 And Side < angle2 Then
isPlus = True
Else
isPlus = False
End If
Else ' angle 1 is the large one
If Side > angle2 And Side < angle1 Then
isPlus = False
Else
isPlus = True
End If
End If
End Function
' get's the smallest angle of two vectors
Private Function SmallAngle(Vector1 As Double, Vector2 As Double) As Double
' subtract the smaller angle from the smaller one
If Vector1 > Vector2 Then
SmallAngle = Vector1 - Vector2
Else
SmallAngle = Vector2 - Vector1
End If
If SmallAngle > dtr(180) Then SmallAngle = dtr(360) - SmallAngle
End Function
Private Sub cmdGo_Click()
' get the aluminum thickness and select the
' modifier and the thickness
Select Case listType.ListIndex
Case 0
dblModifier = 0.076
dOffset = 0.05
Case 1
dblModifier = 0.095
dOffset = 0.0625
Case 2
dblModifier = 0.1425
dOffset = 0.09
Case 3
dblModifier = 0.19
dOffset = 0.125
Case 4
dblModifier = 0.285
dOffset = 0.1875
Case Else
' this should never happen so inform the user and exit
MsgBox "Something is wrong, see the programmer: "
Exit Sub
End Select
Me.Hide
Call Go
Call MakeLayout
End Sub
Private Sub DoDims(varCoords As Variant, ObjEntity As AcadEntity)
Dim txtHeight As Double
Dim DimOffset As Double
' the three points necessary to build an angular dimension
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
Dim pt3(0 To 2) As Double
' running blank and total length
Dim dblLength As Double
Dim dblTotalLength As Double
' included angle for calculations
Dim dblAngle As Double
' distance between the 2 end points for calculating
' the dimension text location
Dim dblDist As Double
' use x for x and y for y, z for z if needed
Const x = 0: Const y = 1: Const z = 2
' integer counter
Dim I As Integer
' left and right points for the dimensions
Dim lpt As Variant
Dim rpt As Variant
' get the drawing scale and set the text height and dimension var's
DwgScale = ThisDrawing.GetVariable("dimscale")
txtHeight = DwgScale * 0.125
DimOffset = DwgScale * 1
' point for the angular text location (temporary)
Dim varPT As Variant
' dimension object (temporary)
Dim objDim As AcadDimAngular
' set the initial length to zero
dblLength = 0
dblTotalLength = 0
' loop thru the polyline, extract the vertexes
' and calculate the angles, length and break distances
For I = 5 To UBound(varCoords) Step 2
' points 1 thru 3
pt1(x) = varCoords(I - 5)
pt1(y) = varCoords(I - 4)
pt2(x) = varCoords(I - 3)
pt2(y) = varCoords(I - 2)
pt3(x) = varCoords(I - 1)
pt3(y) = varCoords(I)
' add linear dimensions
lpt = pt1
rpt = pt2
' get the angle of the first line so we can draw the dimension
dblAngle = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
' draw the dimension
Call DrawDim(lpt, rpt, DimOffset, dblAngle, "STD1")
' test for the last line segment and if it is then draw the dimension
If I = UBound(varCoords) Then
lpt = pt2
rpt = pt3
dblAngle = ThisDrawing.Utility.AngleFromXAxis(pt2, pt3)
Call DrawDim(lpt, rpt, DimOffset, dblAngle, "STD1")
End If
' add the length of point 1 and 2
dblLength = dblLength + Distance(pt1, pt2)
dblTotalLength = dblTotalLength + Distance(pt1, pt2)
' get the distance of the 2 outer end points
dblDist = Distance(pt1, pt3)
' get the angle so we can get the halfway point
dblAngle = ThisDrawing.Utility.AngleFromXAxis(pt1, pt3)
' get the halfway point , we will use this to give us
' a text location for the temporary dimension
varPT = ThisDrawing.Utility.PolarPoint _
(pt1, dblAngle, 0.5 * dblDist)
' draw the dimension
Set objDim = ThisDrawing.ModelSpace.AddDimAngular _
(pt2, pt1, pt3, varPT)
' get the angle between the two segments
dblAngle = rtd(objDim.Measurement)
' if more than ninety then use the excluded angle
If dblAngle > 90 Then
dblAngle = 180 - dblAngle
End If
' subtract the break length calculated
dblLength = dblLength - ((dblAngle / 90) * dblModifier)
' if this is the last one then add the last chord
If I = UBound(varCoords) Then
dblLength = dblLength + Distance(pt2, pt3)
dblTotalLength = dblTotalLength + Distance(pt2, pt3)
End If
Next I
' show the user what the length is
' now it's time to get the text location
' get the bounding box coordinates
Dim varMin As Variant
Dim varMax As Variant
ObjEntity.GetBoundingBox varMin, varMax
' set the center point to be used by the viewport code
Ipt(0) = ((varMax(0) - varMin(0)) / 2) + varMin(0)
Ipt(1) = ((varMax(1) - varMin(1)) / 2) + varMin(1)
' set the break length variable to be used in the title block
brkLength = dblLength
' delete the original polyline because we don't need it anymore
ObjEntity.Delete
' now, let's zoom extents so you can see it all, baby
ThisDrawing.Application.ZoomCenter Ipt, 1
End Sub