AutoCAD 2025 (entnext (entlast)) bug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If your drawing is complex enough, be careful when applying the (entnext (entlast)) method to find the very last entity in the drawing (say an attribute). While loop until entnext=nil will end up in an infinite loop.
Issue:
(entnext (entlast)) returns unexpected enames....
then
(progn (setq e (entlast)) (while (setq e (entnext e))))
cause a crash (infinite loop)
Expected:
nil for (entnext (entlast)) if the last entity is “main entity” (not a insert with atts, nor 3dpoly)
Where:
AutoCAD 2025+
Necessary minimum steps to reproduce:
(could be done in any ACAD version)
• attach a XREF to Model
• add a block to Layout (without atts)
• draw an object to Model (probably must be the last step)
• save, close, reopen
• execute (entnext (entlast)), possibly also (entget (entlast)) or (entget (entnext (entlast)))
Test files attached. (Xref with 1 line. Block of 1 line. One line in model)
Test code:
(defun c:entnexttest ( / e n) (setq e (entlast)) (setq n (getint "Number of next from the lastone: ")) (while (and (setq e (entnext e)) (> (setq n (1- n)) 0)) (princ (entget e)) (terpri) ) (princ) )
Result for 20:
Command: ENTNEXTTEST Number of next from the lastone: 20 ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . LINE) (330 . ) (5 . 14BD) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 10.0 10.0 0.0) (11 11.0 11.0 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14B0) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbBlockReference) (2 . layout-block-line) (10 5.0 5.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0)) ((-1 . ) (0 . INSERT) (330 . ) (5 . 14BC) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbBlockReference) (2 . xref) (10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
So, it returns 3 entities and goes over again.