@Kent1Cooper wrote:
.... a modification of LastNo.lsp, >here<, should be able to do it. ....
By way of asking for further clarification, here's such a modification:
;| NthToLast.LSP [function name: NL]
To select the Nth-To-Last entity at user-specified number N.
Use by typing (NL qu) where 'qu' is integer quantity from last
[inclusive -- (NL 1) is the same as plain (entlast)]
Kent Cooper; 15 December 2023
|;
(defun NL (qu / ss)
(setq ss (ssadd))
(if (and (entlast) (>= (sslength (ssget "_X")) qu))
(progn ; then
(repeat (1- qu)
(ssadd (entlast) ss) (entdel (entlast))
); repeat
(setq nthtolast (entlast)); target object
(repeat (setq qu (1- qu))
(entdel (ssname ss (setq qu (1- qu)))); bring back
); repeat
nthtolast
); progn
(prompt "\nNot that many objects in drawing."); else
); if
); defun
The clarification question is: @ВeekeeCZ 's solution takes the one that is the designated number of objects before the last object, that is, (entlast-i 3) finds the 3rd object before the last object, that is, the 4th-to-last object in the drawing. That may be what you meant in your request, but it doesn't sound like what I would want the specified number to represent -- with mine (NL 3) finds the matching-number 3rd-to-last object. [It can do it the other way by changing line 11 to just (repeat qu .]
It also checks first whether there are enough objects in the drawing to go back as far as requested, and notifies you if not in understandable terms, instead of with the cryptic ; error: Automation Error. Description was not provided.
.
Kent Cooper, AIA