メッセージ1/6
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- パーマリンクを表示
- 印刷
- 報告
The (entlast) function returns the element that was inserted last.
Is it possible to find out what element was inserted 2,3,4,n steps earlier?
Jerzy
解決済! 解決策の投稿を見る。
The (entlast) function returns the element that was inserted last.
Is it possible to find out what element was inserted 2,3,4,n steps earlier?
Jerzy
解決済! 解決策の投稿を見る。
(defun entlast-i (i / d)
(setq d (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))))
(vlax-vla-object->ename (vla-item d (- (vla-get-count d) (1+ i))))
)
@jerzy.bajor wrote:
The (entlast) function returns the element that was inserted last.
Is it possible to find out what element was inserted 2,3,4,n steps earlier?
That should be possible, but clarify something.... Since an individual "step" could result it multiple objects [Array, Offset of an object convoluted enough that more than one object results, Inserting a Block pre-exploded, Exploding of a Polyline or Mtext, etc.], do you want the results of a given step, or are you looking for selecting the [for example] fourth-to-last [individual] object in the drawing?
If the latter, a modification of LastNo.lsp, >here<, should be able to do it. That Selects the last given quantity of objects in the drawing for example typing (LN 4) gets the last 4 objects, and I'm sure it could be adjusted to select only the specified one. It does it by actually deleting objects [temporarily] and taking advantage of the fact that (entdel) removes an object if it's there, but brings it back if it has been removed.
@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.
.
I am very glad to see that you have given attention to an error condition.
John F. Uhden