Because your code
elv (caddr (trans (car pts) 1 zdir))
is looking for the Z. I could have conditionally removed that but it seemed to me to be easier to
understand the final code the way I did it. Perhaps & should have only added the Z to the first point only.
OK, this may be better.
;; Expects pts to be a list of 2D or 3D points
;; Returns the ename of the new pline object
(defun makePline (pts ; list of points
closed ; 1 for closed 0 overwise
layer ; if new layer entmake will create it
;; must be a valid layer name
/ zdir elv)
;; catch nil layer name - CAB added
(or layer (setq layer (getvar "CLAYER")))
;; code by gile, modified by CAB
(if (caddr pts)
(setq zdir (trans '(0 0 1) 1 0 t)
elv (caddr (trans (car pts) 1 zdir))
)
)
(entmakex ; CAB added x
(append
(list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 8 layer) ; CAB added
(cons 90 (length pts))
(cons 70 closed) ; 1 for closed 0 overwise
(if elv (cons 38 elv) '(38 . 0.))
(if zdir (cons 210 zdir) '(210 0. 0. 1.))
)
(mapcar '(lambda (pt) (cons 10 (trans pt 1 zdir))) pts)
)
)
)