Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoCAD VBA - Polygon 2

Status
Not open for further replies.

aobjr

Mechanical
May 7, 2003
11
0
0
PH
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

 
Replies continue below

Recommended for you

Please test this LISP

(defun DTR (X) ;define DEGREE to RADIAN function
(/ (* X pi) 180.0)
) ;MULTIPLY THE DGR ING BY PI AND DIVIDE IT BY 18

(defun c:plg ()
(prin1 "\n TYPE PLG TO START") ;(clr)
(setq leng1 500) ;each length
(setq leng2 500)
(setq leng3 500)
(Setq ang1 (dtr 120)) ;each angle
(Setq ang2 (dtr 240))
(Setq ang3 (dtr 0))

(setq pt0 (list 0 0 0)) ; the origin point
(Setq pt1 (polar pt0 ang1 leng1)) ;polar gives the point from PT at ANG with LENG
(Setq pt2 (polar pt1 ang2 leng2))
(Setq pt3 (polar pt2 ang3 leng3))

(command "_pline" pt0 pt1 pt2 pt3 "") ;the poligon as a polyline

(command "_.AREA" "O" "L")
(SETQ AREA (getvar "AREA"))

(SETQ AREA1 (RTOS AREA 2 3))

(SETQ PERIM (getvar "PERIMETER"))

(SETQ PERIM1 (RTOS PERIM 2 3))


(SETQ SCRE ( STRCAT "THE AREA IS " AREA1 " AND PERIMETER IS " PERIM1 ))
(PRINC SCRE )

(COMMAND "._zoom" "E")
(COMMAND "._ZOOM" "0.9X")
(PRINC)
) ;end the program

Pardal
 
This is a modification of the lisp program given by "pardal"
This can draw a polygon of any number of equal sides, calculate its enclosed area and its perimeter.



; Program for drawing polygon of any number of sides (greater than 2 of course),
; given the length of each side, the number of sides and the origin point




(defun c:plg ()
(prin1 "\n TYPE PLG TO START") ;(clr)
(setq leng (getdist "\n Length of each side, mm:")
nos (getint "\n Number of sides:")
pt0 (getpoint "\n Pick origin point please :")
pt pt0
ang (/ (* pi 2.0) nos) ;Angle between each side
an ang
n 0) ; trouble shooting purposes
;(setq leng1 leng) ;old program
;(setq leng2 leng)
;(setq leng3 leng)
;(Setq ang1 (dtr 120)) ;old program
;(Setq ang2 (dtr 240))
;(Setq ang3 (dtr 0))

;(setq pt pt0) ; the origin point
;(Setq pt1 (polar pt0 ang1 leng1)) ;polar gives the point from PT at ANG with LENG... old program
;(Setq pt2 (polar pt1 ang2 leng2))
;(Setq pt3 (polar pt2 ang3 leng3))


;(command "_pline" pt0 pt1 pt2 pt3 "") ;the poligon as a polyline... old program
(repeat nos
(progn
(command "_line" pt (polar pt an leng)"")
(setq
pt (polar pt an leng)
an (+ an ang)
n (+ n 1)
)
)
)
(command "_pedit" pt "" "join" "all" "" "")
(command "_.AREA" "O" "L")
(SETQ AREA (getvar "AREA"))
(SETQ AREA1 (RTOS AREA 2 3))
(SETQ PERIM (getvar "PERIMETER"))
(SETQ PERIM1 (RTOS PERIM 2 3))
(SETQ SCRE ( STRCAT "THE AREA IS " AREA1 " AND PERIMETER IS " PERIM1 ))
(PRINC SCRE )
(COMMAND "._zoom" "E")
(COMMAND "._ZOOM" "0.9X")
(PRINC)
) ;end the program
 
Status
Not open for further replies.
Back
Top