Author Topic: New error old code  (Read 981 times)

0 Members and 1 Guest are viewing this topic.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
New error old code
« on: May 25, 2022, 02:07:27 AM »
Hi All.
This is doing my head in.  This code is nearly as old as me.  It has been working for years, previously in AutoCAD and more recent years BricsCAD (v22).  Now it has suddenly failed with the following error.
; ----- Error around expression -----
; (ENTGET EN)
;
; error : Unknown Error in Lisp or CAD system or 'Stack Overflow'
Code - Auto/Visual Lisp: [Select]
  1. ; update the value of an attribute in a block
  2.  
  3. (defun PB:update_att (ent att newval / en ed flag)
  4.  
  5.    (if (= (cdr (assoc 0 (entget ent))) "INSERT")
  6.       (progn
  7.          (setq en (entnext ent)
  8.                ed (entget en)
  9.                flag T
  10.          ); End setq
  11.          (while (and (= (cdr (assoc 0 ed)) "ATTRIB")
  12.                      (= flag T)
  13.                 ); End and
  14.             (if (= (cdr (assoc 2 ed)) att)
  15.                (progn
  16.                   (setq ed (subst (cons 1 newval) (assoc 1 ed) ed)
  17.                         flag (not T)
  18.                   ); End setq
  19.                   (entmod ed)
  20.                   (entupd en)
  21.                ); End progn
  22.             ); End if
  23.             (setq en (entnext en)
  24.                   ed (entget en)
  25.             ); End setq
  26.          ); End while
  27.       ); End progn
  28.    ); End if
  29.    (princ)
  30.    
  31. ); End defun
  32.  

Any ideas why this may have started happening.
I'd rather have a bottle in front of me than a frontal lobotomy.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: New error old code
« Reply #1 on: May 25, 2022, 03:57:40 AM »
Not sure, but try to change first line :

Code - Auto/Visual Lisp: [Select]
  1. (if (= (cdr (assoc 0 (entget ent))) "INSERT")
  2. ...
  3.  

to this :

Code - Auto/Visual Lisp: [Select]
  1. (if (and (= (cdr (assoc 0 (setq ed (entget ent)))) "INSERT") (= (cdr (assoc 66 ed)) 1))
  2. ...
  3.  

With this change, you'll be able to apply sub function only to those INSERT entities that in essence have ATTRIB (s) attached - basically it'll automatically filter out XREF and all other INSERT (weather they are "dynamic" or "classic") that don't have ATTRIB (s) attached...
I can only guess - you probably applied sub to those that don't have DXF '(66 . 1) - XREF or INSERT [ without ATTRIB (s) ] which is perhaps why CAD rised an error [ assuming that you previously didn't have any issues regarding this sub ]...
I don't believe that very much changed in newer BricsCAD V22 in relation to AutoLISP and so on... Good thing is that you can see throwing error(s), though IMHO, VLIDE (AutoCAD) is much better for debugging purposes than BLADE (BricsCAD)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: New error old code
« Reply #2 on: May 25, 2022, 06:05:16 PM »
Thanks Ribarm
I have already filtered for (66.1) in the calling program in the ssget command.
The important point for me is that this code has worked for years.  The error is new.
I'd rather have a bottle in front of me than a frontal lobotomy.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: New error old code
« Reply #3 on: May 25, 2022, 09:26:50 PM »
Further investigation has revealed that any of my LISP routines with entget fail.   There must be a conflict with new computer, new Windows 11, new v22 BricsCAD.  I have logged a support ticket with BricsCAD.
I'd rather have a bottle in front of me than a frontal lobotomy.

mhupp

  • Bull Frog
  • Posts: 250
Re: New error old code
« Reply #4 on: May 26, 2022, 11:17:54 AM »
looks like this issue has been around for a while.
https://forum.bricsys.com/discussion/10780/serious-problem-with-entnext

tldr use (cons 410 (getvar 'ctab)) with your ssget to limit your selection set.

----Edit
 or maybe its time to update.
Code - Auto/Visual Lisp: [Select]
  1. ;; Set Attribute Value  -  Lee Mac
  2. ;; Sets the value of the first attribute with the given tag found within the block, if present.
  3. ;; blk - [vla] VLA Block Reference Object
  4. ;; tag - [str] Attribute TagString
  5. ;; val - [str] Attribute Value
  6. ;; Returns: [str] Attribute value if successful, else nil.
  7.  
  8. (defun LM:vl-setattributevalue ( blk tag val )
  9.     (setq tag (strcase tag))
  10.     (vl-some
  11.        '(lambda ( att )
  12.             (if (= tag (strcase (vla-get-tagstring att)))
  13.                 (progn (vla-put-textstring att val) val)
  14.             )
  15.         )
  16.         (vlax-invoke blk 'getattributes)
  17.     )
  18. )
« Last Edit: May 26, 2022, 10:57:51 PM by mhupp »

d2010

  • Bull Frog
  • Posts: 323
Re: New error old code
« Reply #5 on: May 27, 2022, 12:36:59 AM »
Thanks Ribarm
I have already filtered for (66.1) in the calling program in the ssget command.
The important point for me is that this code has worked for years.  The error is new.
Is posibile this Lines failed, StartPoint of error
................<err??>
  (setq ed (subst (cons 1 newval) (assoc 1 ed) ed)
</err??>