×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

AutoCAD VBA - Polygon
2

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

RE: AutoCAD VBA - Polygon

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

RE: AutoCAD VBA - Polygon

2
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources