Your only calculating a distance for pt2gap not a point. then feeding that into pt3gap and it error there.
You have (polar distance angle distance) instead of (polar point angle distance)
Also their are 4 different ways to draw a rectangle so depending on what corner you start on pt 2 would be in a different location.
so using bounding box keeps the points in one orientation.
pt1 is always LL
pt3 is always UR
tho this means you can only use this on rectangles that use ortho and aren't on an angle.
(defun c:newrec (/ ent ptslst LL UR L&W len wid area pt1 pt2 pt3 pt4 gap lst)
;Draw a rectangle
(vl-load-com)
(command "_.rectang"
(while (< 0 (getvar 'CMDACTIVE)) (command pause)) ;waits for user to complete command
)
(setq ent (entlast)) ;Save first rectangle
(vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
(setq ptslst (cons (vlax-safearray->list minpt) ptslst)
ptslst (cons (vlax-safearray->list maxpt) ptslst)
)
(setq LL (apply 'mapcar (cons 'min ptslst))
UR (apply 'mapcar (cons 'max ptslst))
L&W (mapcar '- UR LL) ;gets length and width as a point from 0,0
)
(setq len (car L&W) ; length of rectangle
wid (cadr L&W) ; width of rectangle
area (* len wid)
PT1 LL ;reorders rectangle points so they are the same independent of how its drawn
PT2 (list (car LL) (cadr UR))
PT3 UR
)
(cond ;use cond more here https://www.afralisp.net/autolisp/tutorials/cond-vs-if.php
((< area 40)
(setq gap 4.0)
)
((and (>= area 40) (< area 60))
(setq gap 6.0)
)
((and (>= area 60) (< area 80))
(setq gap 8.0)
)
((and (>= area 80) (< area 100))
(setq gap 10.0)
)
((>= area 100)
(setq gap 12.0)
)
)
;Now find the total length. Two rectangles (plus the gap). width is stil the same "recw"
(setq pt3 (polar pt2 (angle pt2 pt3) (+ gap (* 2 len)))) ;rectangle length * 2 (Plus the gap distance)
(setq pt4 (polar pt3 (angle pt2 pt1) wid)) ;get the new third point of rectangle
;Make a new rectangle that’s twice the length of the original (plus the gap)
;(Command "line" pt1 pt2gap pt3gap pt4 pt1 "")
(entmake (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 4)
'(70 . 1)
(cons 10 pt1)
(cons 10 pt2)
(cons 10 pt3)
(cons 10 pt4)
)
)
(entdel ent) ;Delete first rectangle
)