ssget generates selections set in a reversed order i.e. entlast is the first element. and still your function is iterating 2814 times. why? because it searches though all layouts.
>
entlast is the first element
I do not think so:
Comando: (setq kkkk (ssget "_X"))
<Selection set: 11b>
Comando: (ssname kkkk 0)
<Nome entità: 7ffffb60c70>
Comando: (entlast)
<Nome entità: 7ffffb61930>
Comando: (ssname kkkk 1)
<Nome entità: 7ffffb449f0>
Comando: (ssname kkkk (1- (sslength kkkk)))
<Nome entità: 7ffffb06700>
Comando: (ssname kkkk (sslength kkkk))
nil
entnext starts from the beginning and steps through all vertexes but doesn't go into layouts.
I think entnext steps through all entities (DWG with only 3 entities):
(defun VK_entprev1 (e / e1 e2 Countr)
(setq Countr 0)
(setq e1 (entnext))
(while (and e1 (not (eq e (setq e2 (entnext e1)))))
(setq e1 e2 Countr (1+ Countr))
(princ "\n ") (princ (entget e2) )
)
(list e1 Countr)
)
>
((-1 . <Nome entità: 7ffffb60d60>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE8E) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1887.13 222.152 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0465439) (91 . 0) (70 . 0) (50 . 0.0))
((-1 . <Nome entità: 7ffffb60d70>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE8F) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1829.33 165.574 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0601886) (91 . 0) (70 . 0) (50 . 0.0))
...
((-1 . <Nome entità: 7ffffb60e50>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE9D) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1954.41 267.061 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0465439) (91 . 0) (70 . 0) (50 . 4.25351))
((-1 . <Nome entità: 7ffffb60e60>) (0 . SEQEND) (330 . <Nome entità: 7ffffb60d50>) (5 . AE9E) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (-2 . <Nome entità: 7ffffb60d50>))
((-1 . <Nome entità: 7ffffb44a40>) (0 . VIEWPORT) (330 . <Nome entità: 7ffffb44a20>) (5 . 94D4) (100 . AcDbEntity) (67 . 1) (410 . L2) (8 . 0) (100 . AcDbViewport) (10 975.889 259.916 0.0) (40 . 396.146) (41 . 286.588) (68 . 1) (69 . 1) (12 975.889 259.916 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 286.588) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffb06170>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
((-1 . <Nome entità: 7ffffbf7cc0>) (0 . CIRCLE) (330 . <Nome entità: 7ffffb44a20>) (5 . B08C) (100 . AcDbEntity) (67 . 1) (410 . L2) (8 . 0) (100 . AcDbCircle) (10 891.453 209.204 0.0) (40 . 33.0551) (210 0.0 0.0 1.0))
benchmark both function with (entnext (entnext)) as an argument
Why?