(defun _rect (p1 p2 / lt point2d x1 y1 x2 y2 pts)
(defun lt (pt) (trans pt 1 0))
(defun point2d (pt) (list (car pt) (cadr pt)))
;(command "_.ucs" "w")
(setq
x1 (apply 'min (mapcar 'car (list p1 p2)))
y1 (apply 'min (mapcar 'cadr (list p1 p2)))
x2 (apply 'max (mapcar 'car (list p1 p2)))
y2 (apply 'max (mapcar 'cadr (list p1 p2)))
pts (mapcar 'point2d(mapcar 'lt (list (list x1 y1) (list x2 y1) (list x2 y2) (list x1 y2))))
)
(cond
((and pts)
(entmake
(apply 'append
(cons
(list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(410 . "Model")
'(8 . "0")
'(38 . 0)
'(62 . 256)
'(67 . 0)
(cons 90 (length pts))
'(70 . 1)
)
(mapcar 'list (mapcar '(lambda (a) (cons 10 a)) pts))
)
)
)
)
)
(princ)
)
Usage:
(setq p1 '(200 200) p2 '(100 100))
(_rect p1 p2)
This will create rectangle in current UCS starting from first point in lower left corner and drawn in counter-clockwise direction as a closed polyline.
If you work in World UCS remove ; in front (command "_.ucs" "w") in above code
I hope you know how to add it to your code
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.