AutoCAD VBA - Polygon
AutoCAD VBA - Polygon
(OP)
I'm new to VBA. I would like to automate in autocad the generation of either close or open polygon then if it is closed polygon it would also calculate the area. The input data should be the angle and length for each line in the polygon. The input data maybe also extracted automatically from a .txt file. It should be applicable to "n" number of lines. Sample below is a equiangular triangle. . Angle rotation is counterclockwise using the default reference origin of the Autocad.Thanks in advance.
Input data: angle in decimal degrees length
sample 120 500
240 500
0 500
Input data: angle in decimal degrees length
sample 120 500
240 500
0 500





RE: AutoCAD VBA - Polygon
Keith
Sub AddBlock()
Dim autocadApp As AcadApplication
Dim blockObj As AcadPolyline
Dim dwgObj As AcadDocument
Dim points(0 To 11) As Double
Set autocadApp = GetObject(, "AutoCAD.Application")
Set dwgObj = autocadApp.ActiveDocument
points(0) = x * 1.5: points(1) = 0: points(2) = 0
points(3) = x * 1.5 + 1.5: points(4) = 0: points(5) = 0
points(6) = x * 1.5 + 1.5: points(7) = 61 / 96: points(8)=0
points(9) = x * 1.5: points(10) = 61 / 96: points(11) = 0
Set blockObj = dwgObj.ModelSpace.AddPolyline(points)
With blockObj
.Closed = True
.Layer = "srw"
.LinetypeScale = 1 / 3
End With
End Sub