Jump to content

error: bad argument type: lentityp nil


humphe

Recommended Posts

I am not an experienced lisper, but I can manipulate some lisp routines that we have. We are trying to run a lisp routine that at one time had worked, but now I am getting the error:

 

error: bad argument type: lentityp nil

 

What we are trying to do is replace a block with an updated block that is named the same thing on a batch of drawings. Below is where the lisp routine is getting hung up or breaking. And I am not seeing why it is not going through the loop and completing the routine.

 

(defun c:redef_instruments ()

(setvar "clayer" "specblk")

(setq lst_blk (ai_table "BLOCK" 1))

(if lst_blk

(progn

(foreach str_blk lst_blk

(setq file_blk

(open (strcat (getvar "dwgprefix") "InstrumentMap.csv") "r")

)

(while (setq record (read-line file_blk))

(setq str_name (nth 0 (strparse record ",")))

(if

(and

(= (strcase str_name) (strcase str_blk))

(> (length (strparse record ",")) 1)

(/= (setq str_newname (nth 1 (strparse record ","))) "")

)

(progn

(redefineinstruments str_name str_newname)

)

)

)

(close file_blk)

)

)

)

)

(defun redefineinstruments (old new / blist

attlst_old attlst_new

val scx scy scz

)

(setq ss_old (ssget "x" (list '(0 . "INSERT") (cons 2 old))))

(if ss_old

(progn

(setq blist

(sel2lst ss_old)

)

(foreach nb blist

(command "insert"

(strcat new "=" (findfile (strcat new ".dwg")))

(getval 10 nb)

"XYZ"

1

1

1

(rtod (getval 50 nb))

)

(setq attlst_old (att2lst nb))

(setq attlst_new (att2lst (entlast)))

(setval 1 (getval 1 (nth 0 attlst_old)) (nth 0 attlst_new))

(setval 1 (getval 1 (nth 1 attlst_old)) (nth 1 attlst_new))

(setval 1 (getval 1 (nth 3 attlst_old)) (nth 2 attlst_new))

(setval 1 (getval 1 (nth 4 attlst_old)) (nth 3 attlst_new))

(setval 1 (getval 1 (nth 5 attlst_old)) (nth 4 attlst_new))

(setval 1 (getval 1 (nth 6 attlst_old)) (nth 5 attlst_new))

(setval 1 (getval 1 (nth 7 attlst_old)) (nth 6 attlst_new))

(setval 1 (getval 1 (nth 8 attlst_old)) (nth 7 attlst_new))

(setval 1 (getval 1 (nth 9 attlst_old)) (nth 8 attlst_new))

(setval 1 (getval 1 (nth 10 attlst_old)) (nth 9 attlst_new))

(setval 1 (getval 1 (nth 11 attlst_old)) (nth 10 attlst_new))

(setval 1 (getval 1 (nth 12 attlst_old)) (nth 11 attlst_new))

(setval 1 (getval 1 (nth 13 attlst_old)) (nth 12 attlst_new))

(entdel nb)

)

)

)

(entupd (entlast))

)

 

Any help or direction would be very much appreciated. Also if someone could comment the code in the first half so that I could understand what the code is acually doing.

 

Thanks a million

Link to comment
Share on other sites

Also on the above we want to keep the attributes form the old block remove the third attribute and move all other values of the attributes up one i.e.: the nth 3 = nth 2

Link to comment
Share on other sites

Hi,

You have not posted the strparse function (it may be located in another lisp you run at startup). If you're missing it that'll be your problem, otherwise you'll need to post it so we can see what else is wrong with it.

Here is some of your code commented, hope it helps:

; Define Function redef_instruments
(defun c:redef_instruments ()
 ; Change Current Layer
 (setvar "clayer" "specblk")
 ; Get Block List in current drawing
 (setq lst_blk (ai_table "BLOCK" 1))
 ;If there's a block list
 (if lst_blk
   ; then do everything within the progn parenthesis
   (progn
     ; for each block in the block list
     (foreach str_blk lst_blk
   ; open InstrumentMap.csv located in the same folder as the current drawing
   (setq file_blk
          (open (strcat (getvar "dwgprefix") "InstrumentMap.csv") "r")
         )
   ; iterate through each line in the csv file until it runs out
   (while (setq record (read-line file_blk))
     ; look for coma, return strname [i][b][color=Red](MISSING strparse FUNCTION)[/color][/b][/i]
     (setq str_name (nth 0 [b][color=Red](strparse[/color][/b] record ",")))
     ; if everything returns true in the AND parenthesis
     (if
       (and
         ;
         (= (strcase str_name) (strcase str_blk))
         (> (length [b][color=Red](strparse[/color][/b] record ",")) 1)
         (/= (setq str_newname (nth 1 [b][color=Red](strparse[/color][/b] record ","))) "")
         )
       (progn
         (redefineinstruments str_name str_newname)
         )
       )
     )
   (close file_blk)
   )
     )
   )
 )

; Redefine Instructments Function
(defun redefineinstruments (old new / blist
               attlst_old attlst_new
               val scx scy scz
               )
 (setq ss_old (ssget "x" (list '(0 . "INSERT") (cons 2 old))))
 (if ss_old
   (progn
     (setq blist
        (sel2lst ss_old)
       )
     (foreach nb blist
   (command "insert"
        (strcat new "=" (findfile (strcat new ".dwg")))
        (getval 10 nb)
        "XYZ"
        1
        1
        1
        (rtod (getval 50 nb))
        )
   (setq attlst_old (att2lst nb))
   (setq attlst_new (att2lst (entlast)))
   (setval 1 (getval 1 (nth 0 attlst_old)) (nth 0 attlst_new))
   (setval 1 (getval 1 (nth 1 attlst_old)) (nth 1 attlst_new))
   (setval 1 (getval 1 (nth 3 attlst_old)) (nth 2 attlst_new))
   (setval 1 (getval 1 (nth 4 attlst_old)) (nth 3 attlst_new))
   (setval 1 (getval 1 (nth 5 attlst_old)) (nth 4 attlst_new))
   (setval 1 (getval 1 (nth 6 attlst_old)) (nth 5 attlst_new))
   (setval 1 (getval 1 (nth 7 attlst_old)) (nth 6 attlst_new))
   (setval 1 (getval 1 (nth 8 attlst_old)) (nth 7 attlst_new))
   (setval 1 (getval 1 (nth 9 attlst_old)) (nth 8 attlst_new))
   (setval 1 (getval 1 (nth 10 attlst_old)) (nth 9 attlst_new))
   (setval 1 (getval 1 (nth 11 attlst_old)) (nth 10 attlst_new))
   (setval 1 (getval 1 (nth 12 attlst_old)) (nth 11 attlst_new))
   (setval 1 (getval 1 (nth 13 attlst_old)) (nth 12 attlst_new))
   (entdel nb)
   )
     )
   )
 (entupd (entlast))
 )

Link to comment
Share on other sites

This is in another Lisp routine that is loaded also.

 

;;STRPARSE FOR PARSING STRING (and keeping null tokens)

(defun strparse (strng chs / len c l s chsl cnt)

;;delim==one-of-chs.

(setq chsl (strtol chs))

(setq len (strlen strng)

s ""

cnt (1+ len)) ;_ end of setq

(while (> (setq cnt (1- cnt)) 0)

(setq c (substr strng cnt 1))

(if (member c chsl)

(if (/= cnt len)

;; "1,2," -> ("1" "2") and not ("1" "2" "")

(setq l (cons s l)

s "") ;_ end of setq

) ;_ end of if

(setq s (strcat c s))) ;_ end of if

) ;_ end of while

(cons s l)

;; ",1,2" -> ("" "1" "2")

) ;_ end of defun

Link to comment
Share on other sites

I was reading another post and somebody was saying that entupd at the end of the Lisp might be giving the error: bad argument type: lentityp nil?

 

Thank you for the help strings it is clearing up mudy water.

Link to comment
Share on other sites

Just a note, when you post, enclose code within code brackets [ CODE][/code].

 

If this code has been posted somewhere else why don't you ask in there?

 

Anyways...

 

Why don't you comment out the line (entupd (entlast)) and see if it works...?

 

The function strparse uses another function strtol that is missing.

Link to comment
Share on other sites

Just to go further in the self-help direction, do you use the visual lisp editor? If so you can pause the lisp somewhere and then step through each line. That way you will find out where the error occurs. Also a good way to learn.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...