AutoCAD 2025 (entnext (entlast)) bug

AutoCAD 2025 (entnext (entlast)) bug

ВeekeeCZ
Consultant Consultant
2,061 Views
19 Replies
Message 1 of 20

AutoCAD 2025 (entnext (entlast)) bug

ВeekeeCZ
Consultant
Consultant

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.

 

 

 @ambrosl  @artc2  @Bud_Schroeder_ADESK 

2,062 Views
19 Replies
Replies (19)
Message 2 of 20

Moshe-A
Mentor
Mentor

@ВeekeeCZ  hi,

 

do not yet have 2025 installed but testing it on 2023 

 

 (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)
   )
 
noting is echoed...
if 'e' gets the last entity then the (while) test expr stops right on the first iteration cause there is not next entity
sorry but, what i am missing here?
 
Moshe
 
0 Likes
Message 3 of 20

ВeekeeCZ
Consultant
Consultant

@Moshe-A wrote:
 
noting is echoed...
sorry but, what i am missing here?
Moshe
 

 

@Moshe-A 

 

That's what you are supposed to get, and you do for all releases up to 2024. 

Just the 2025 release returns something else... as it seems it returns the entire database in reversed order.

0 Likes
Message 4 of 20

Moshe-A
Mentor
Mentor

wow

 

thank you for this discovery and i assume your installation is update

should be report to Autodesk?!

 

 

0 Likes
Message 5 of 20

ВeekeeCZ
Consultant
Consultant

Thanks. This program, in the alpha/beta/release stages, has been going through various testing processes for more than a year. I doubt I'm the first to discover this. Quite possibly I just have no information about the problem being reported or about the fix. So I inform. And yes, 3 ADSK employees were notified. 

0 Likes
Message 6 of 20

ec-cad
Collaborator
Collaborator

Strange indeed.!  Why would they mess with a function that has been working just fine for 'ever' ?

Compiler issue ?

ECCAD

0 Likes
Message 7 of 20

john.uhden
Mentor
Mentor

@ec-cad et al,

I'm not sure what his problem is, but one has to be careful with entlast.

It will always return the last primary entity, but if it is a block with attributes or a polyline with vertices, then there are additional subsequent entities not returned.

This can be a PITA if you are expecting (entnext (entlast)) to return the next primary entity.

Ergo, I use this:

   ;;----------------------------------------
   ;; Function to get absolutely last entity:
   ;;
   (defun @entlast ( / elast e)
     (setq elast (entlast))
     (while (setq e (entnext elast))
       (setq elast e)
     )
     elast
   )

 

John F. Uhden

0 Likes
Message 8 of 20

hb
Contributor
Contributor

Is there already a solution or a service pack for the problem with the entsel

0 Likes
Message 9 of 20

ВeekeeCZ
Consultant
Consultant

Unfortunately, Autodesk has not responded at all. The issue is registered under "new" status, and that's it.

Nada, don't care.

0 Likes
Message 10 of 20

asteiner3DERF
Explorer
Explorer

This is a serious problem for me also. I don't use the entlast function, but some of my programs cycle through all the entities starting with (entnext). Since (entnext (entlast)) is returning an entity, I am having issues and also get stuck in this infinite loop. This needs to get resolved. I guess for the time being I am going to compare the (entnext ename) with (entlast). If they are the same, I exit the loop.

0 Likes
Message 11 of 20

asteiner3DERF
Explorer
Explorer

I discovered the (entnext ename) won't reach (entlast) in a loop. entnext is not performing as defined by AutoLISP help documentation.

0 Likes
Message 12 of 20

john.uhden
Mentor
Mentor

@asteiner3DERF ,

I don't think your conclusion is correct.

Reread #7.

John F. Uhden

0 Likes
Message 13 of 20

asteiner3DERF
Explorer
Explorer

Using your method made my routine go into an endless loop.

0 Likes
Message 14 of 20

john.uhden
Mentor
Mentor

@asteiner3DERF ,

I do see a shortcoming in my function if there are no graphic entities in the drawing, but it shouldn't loop because (entnext nil) will error out...

Command: (setq e (entnext nil))
; error: bad argument type: lentityp nil

Of course it could be my brain that is erroring out.  @kent1cooper, @beekeeCZ, @hak_vz, @dbroad, @paulli_mapa, @sea_haven, @leeminardi, Whadya think?

John F. Uhden

0 Likes
Message 15 of 20

Sea-Haven
Mentor
Mentor

@asteiner3DERF the question is a bit like "its not working", what is the object that is being looked for and what is parent object. Can Dumpit.lsp reveal properties that your looking for.

0 Likes
Message 16 of 20

ВeekeeCZ
Consultant
Consultant

@asteiner3DERF wrote:

This is a serious problem for me also. ....This needs to get resolved....


 

Agree. Since my last post, Autodesk, after 6 weeks, changed the issue's status, accepted the issue and promised nothing.

 

Personally, I gave up on 2025 and downgraded to 24. It's not just this issue.

0 Likes
Message 17 of 20

ronjonp
Mentor
Mentor

@ВeekeeCZ I'm running AutoCAD 2025.1 and have found a bug when adding a leader to an mleader via right click menu. It puts the mleader on the current layer. Can someone else confirm this?

 

 

0 Likes
Message 18 of 20

ВeekeeCZ
Consultant
Consultant

Yes, that bug appeared with Update1, and this issue has probably been known since the release day.

 

Edit. See THIS. Correction: Not a bug; it was "intentional." They then received feedback that editing MLEADERS is not the workflow people want. 🙂

Message 19 of 20

ziggy63
Contributor
Contributor

Yes, this is a serious bug and I don’t understand why Autodesk does not fix it -it’ can’ be that hard!-, but I believe I ‘ve found a workaround. It’s not a very elegant solution but it works. I thing the problem occurs whenever you use (entlast) and the last entity in the drawing happens to be a block. So, to avoid the infinite loop, you can draw a small line just before the (entlast) and then erase it after the final (entnext). For example, suppose that you want to select all the entities that are created after using the “copy” command (or any other command). You could do it like that:

 

(defun Acad2025EntnextProblem ( / p1 p2)
  (if (= (substr (getvar "acadver") 1 2) "25")
    (progn
      (setq p1 (list 0.0 0.0 0.0) p2 (list 0.01 0.0 0.0))
      (if (= (cdr (assoc 0 (entget(entlast)))) "INSERT")
        (progn
          (command "._line" p1 p2 "")
          (setq AcadLine2025 (entlast))
        ) ; progn
      ) ; if
    ) ; progn
  ) ; if
) ; defun

(defun EntnextTest ( / AcadLine2025 enl et ss)
  ; Draw the AcadLine2025
  (Acad2025EntnextProblem)
  (setq enl (entlast))
  ;  do something (e.g. create new entities with "Copy")
  (command "._copy")
  (while (> (getvar "cmdactive") 0) (command pause))
  (setq ss (ssadd))
  (while (setq enl (entnext enl))
    ; select all the new entities that were created
    (setq et (cdr (assoc 0 (entget enl))))
    (if (and (/= et "ATTRIB")(/= et "SEQEND") (/= et "VERTEX"))
      (ssadd enl ss)
    ) ; if
  ) ; while
  ; Erase the AcadLine2025
  (entdel AcadLine2025)
  ss
) ; defun

 

 

I  repeat, it's not a very elegant solution, but I think it will do the job until Autodesk fixes the bug.

 

Edit: The correct line at the end of the EntnextTest function is:

(if AcadLine2025  (entdel AcadLine2025))

Message 20 of 20

asteiner3DERF
Explorer
Explorer

Thanks for looking into this.

0 Likes