Try this version.
(defun c:ltg (/ x1 y1 fx fy p1 px py block pxa pya osm newbies elast e ang eblk)
(setq x1 (getdist "\nInput width of room along X Axis: "))
(setq y1 (getdist "\nInput length of room along Y Axis: "))
(setq fx (getint "\nInput No of fittings along X Axis: "))
(setq fy (getint "\nInput No of Fittings along Y Axis: "))
(setq p1 (getpoint "\nSelect the lower left hand corner: "))
(setq ang (getangle p1 "\nSelect angle of room width (x-axis): <0>"))
(if (null ang)
(setq ang 0)
(setq ang (* 180.0 (/ ang pi))) ; Radians to Degrees
)
(if (or (null fx) (< fx 2))
(setq fx 1
px (/ x1 2)
pxa (+ (car p1) px)
)
(setq px (/ x1 fx) ;width divided by fittings
pxa (+ (car p1) (/ px 2.0)) ;divided by 2 plus X coord of P1
)
)
(if (or (null fy) (< fy 2))
(setq fy 1
py (/ y1 2)
pya (+ (cadr p1) py)
)
(setq py (/ y1 fy) ;length divide by fittings
pya (+ (cadr p1) (/ py 2.0)) ;divided by 2 plus Y coord of P1
)
)
;; get block name , default name if enter only
(setq block
(getstring "\nEnter block name you wish to insert: <RC-Light> ")
)
(if (or (= block "") (null block)) ; use default name
(setq block "RC-Light")
)
;; - If block exists then go ahead
(cond ((tblsearch "BLOCK" block)
(setq osm (getvar "OSMODE"))
(command "UNDO" "Begin")
(setvar "OSMODE" 0)
(setq elast (@cv_entlast))
(setq newbies (ssadd)) ;empty selection set
(command "-insert" block (list pxa pya) "1" "" 0)
(setq eblk (entlast))
;(setq eblk (@cv_entlast))
(ssadd eblk newbies)
(command "ARRAY" eblk "" "RECTANGULAR" fy fx)
(if (> fy 1) (command py))
(if (> fx 1) (command px))
(if (/= ang 0)
(progn
(setq e (if elast
(entnext elast)
(entnext)
)
)
(while e
(ssadd e newbies)
(setq e (entnext e))
)
(command ".rotate" newbies "" p1 ang)
)
)
(command "UNDO" "End")
(setvar "OSMODE" osm)
)
;; ELSE =====================================
((prompt (strcat "\n" block " Block not found."))
)
)
(princ) ; clean exit
)
;;------------------------------------------------------------
;; Function to get the absolutely last entity in the database:
;;
(defun @cv_entlast (/ e elast)
(setq elast (entlast))
(while (setq e (entnext elast))
(setq elast e)
)
elast
)