humphe 发表于 2022-7-6 12:12:03

错误:错误的参数类型:lent

我不是一个有经验的lisper,但我可以操作一些我们有的lisp例程。我们正在尝试运行一个lisp例程,该例程曾经工作过,但现在我遇到了错误:
 
错误:错误的参数类型:lentyp nil
 
我们要做的是用一个更新的块替换一个块,该块在一批图形上命名为相同的东西。下面是lisp例程挂起或中断的地方。我不明白为什么它没有完成循环和例行程序。
 
(defun c:redef_仪器()
(setvar“clayer”“specblk”)
(setq lst\U blk(ai\U表格“BLOCK”1))
(如果是lst_blk
(程序
(foreach str\u blk lst\u blk
(setq file_blk
(打开(strcat(getvar“dwgprefix”)“InstrumentMap.csv”)“r”)
)
(while(setq记录(read line file_blk))
(setq str_名称(第n个0(strparse记录“,”))
(如果
(和
(=(strcase str\u name)(strcase str\u blk))
(>(长度(strparse记录“,”)1)
(/=(setq str_newname(第n个1(strparse记录“,”))“”)
)
(程序
(重新定义Instruments str\u name str\u newname)
)
)
)
(关闭file_blk)
)
)
)
)
(重新定义仪器(旧/新/blist
attlst\u旧attlst\u新
val scx scy scz
)
(setq ss_old(ssget“x”(list)(0。“INSERT”)(cons 2 old)))
(如果ss_旧
(程序
(setq blist
(sel2lst ss_old)
)
(foreach nb blist)
(命令“插入”
(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(第0个attlst\u旧))(第0个attlst\u新))
(setval 1(getval 1(nth 1 attlst\u old))(nth 1 attlst\u new))
(设置值1(设置值1(第3个attlst\u旧))(第2个attlst\u新))
(设置值1(设置值1(第4个attlst\u旧))(第3个attlst\u新))
(设置值1(设置值1(第5个attlst\u旧))(第4个attlst\u新))
(设置值1(设置值1(第6个attlst\u旧))(第5个attlst\u新))
(设置值1(设置值1(第7个attlst\u旧))(第6个attlst\u新))
(设置值1(设置值1(第8个attlst\u旧))(第7个attlst\u新))
(设置值1(设置值1(第9个attlst\u旧))(第8个attlst\u新))
(设置值1(设置值1(第10个attlst\u旧))(第9个attlst\u新))
(设置值1(设置值1(第11个attlst\u旧))(第10个attlst\u新))
(设置值1(设置值1(第12个attlst\u旧))(第11个attlst\u新))
(设置值1(设置值1(第13个attlst\u旧))(第12个attlst\u新))
(entdel nb)
)
)
)
(entupd(entlast))
)
 
任何帮助或指导都将不胜感激。另外,如果有人能在上半部分对代码进行注释,这样我就能理解代码真正在做什么。
 
非常感谢

humphe 发表于 2022-7-6 12:25:50

此外,我们希望保留旧块中的属性,删除第三个属性,并将属性的所有其他值向上移动一个,即:第n个3=第n个2

SteveK 发表于 2022-7-6 12:42:00

你好
您尚未发布strparse函数(它可能位于启动时运行的另一个lisp中)。如果你错过了它,这将是你的问题,否则你需要张贴它,这样我们就可以看到它还有什么问题。
以下是您的一些代码评论,希望能有所帮助:
; 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 (MISSING strparse FUNCTION)
   (setq str_name (nth 0 (strparse record ",")))
   ; if everything returns true in the AND parenthesis
   (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)
   )
   )
   )
)

; 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))
)

humphe 发表于 2022-7-6 12:49:21

这在另一个加载的Lisp例程中。
 
;;STRPARSE用于解析字符串(并保留空令牌)
(defun strparse(strng chs/len c l s chsl cnt)
;;delim==一个chs。
(setq chsl(strtol chs))
(setq len(strlen strng)
s“”
cnt(1+len));_setq结束
(而(>(setq cnt(1-cnt))0)
(setq c(substr strng cnt 1))
(if(成员c chsl)
(如果(/=cnt len)
;; “1,2,”->(“1”“2”)而非(“1”“2”)
(setq l(cons s l)
s“”);_setq结束
) ;_ if结束
(setq s(strcat c s));_if结束
) ;_ while结束
(cons s l)
;; ",1,2" -> ("" "1" "2")
) ;_ defun结束

humphe 发表于 2022-7-6 12:53:05

我在读另一篇帖子,有人说Lisp末尾的entupd可能会给出错误:错误的参数类型:lentyp nil?
 
谢谢你的帮助,它正在清理泥水。

SteveK 发表于 2022-7-6 13:03:39

请注意,在发布时,请将代码括在代码括号中。
 
如果这个代码已经发布在其他地方,为什么你不在那里问呢?
 
无论如何。。。
 
为什么不注释掉这行(entupd(entlast))并看看它是否有效。。。?
 
函数strparse使用另一个缺少的函数strtol。

SteveK 发表于 2022-7-6 13:13:33

在自助方面,您是否使用visual lisp编辑器?如果是这样的话,你可以在某个地方暂停Lisp程序,然后逐行检查每一行。这样你就会发现错误发生的地方。也是学习的好方法。
页: [1]
查看完整版本: 错误:错误的参数类型:lent