乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 47|回复: 4

[编程交流] 需要While expre的帮助

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 15:20:35 | 显示全部楼层 |阅读模式
几天来,我一直在尝试使例程正常工作,但在visual lisp代码检查器中找不到克服此错误的方法;“错误:错误函数:(“1”“Plant\uu”“1164”)”。
当我逐步遍历代码时,它会给出正确的结果,但为了得到正确的结果,我跳过了while表达式。所以我相信这就是我的错误所在。在autocad窗口中运行例程时,出现以下错误:“错误:错误参数类型:consp nil”。
 
有什么建议吗?
(附件是我用来收集标签数据的文件)
 
注:getattdata程序是另一个lisp例程的一部分,该例程将块数据收集到列表中,并与前一个程序保持相同。我创建的唯一部分是npinum程序部分。
 
 
  1. ;;;--- Function to get the block data
  2. (defun getAttData(/ eset dataList blkCntr en enlist blkType blkName entName
  3.                     attTag attVal group66)
  4. ;;;--- Set up an empty list
  5. (setq dataList(list))
  6. ;;;--- If that type of entity exist in drawing
  7. (if (setq eset(ssget ":s" (list (cons 0 "INSERT"))))
  8.    (progn
  9.      ;;;--- Set up some counters
  10.      (setq blkCntr 0 cntr 0)
  11.      ;;;--- Loop through each entity
  12.      (while (< blkCntr (sslength eset))
  13.        ;;;--- Get the entity's name
  14.        (setq en(ssname eset blkCntr))
  15.        ;;;--- Get the DXF group codes of the entity
  16.        (setq enlist(entget en))
  17.        ;;;--- Get the name of the block
  18.        (setq blkName(cdr(assoc 2 enlist)))
  19.        ;;;--- Check to see if the block's attribute flag is set
  20.        (if(cdr(assoc 66 enlist))
  21.          (progn
  22.            ;;;--- Get the entity name
  23.            (setq en(entnext en))
  24.            ;;;--- Get the entity dxf group codes
  25.            (setq enlist(entget en))
  26.            ;;;--- Get the type of block
  27.            (setq blkType (cdr(assoc 0 enlist)))
  28.            ;;;--- If group 66 then there are attributes nested inside this block
  29.            (setq group66(cdr(assoc 66 enlist)))
  30.            ;;;--- Loop while the type is an attribute or a nested attribute exist
  31.            (while(or (= blkType "ATTRIB")(= group66 1))
  32.              ;;;--- Get the block type
  33.              (setq blkType (cdr(assoc 0 enlist)))
  34.              ;;;--- Get the block name         
  35.              (setq entName (cdr(assoc 2 enlist)))
  36.              ;;;--- Check to see if this is an attribute or a block
  37.              (if(= blkType "ATTRIB")
  38.                (progn
  39.                  ;;;--- Save the name of the attribute
  40.                  (setq attTag(cdr(assoc 2 enlist)))
  41.                  ;;;--- Get the value of the attribute
  42.                  (setq attVal(cdr(assoc 1 enlist)))
  43.                  ;;;--- Save the data gathered
  44.                  (setq dataList(append dataList(list (list blkName attTag attVal))))
  45.                  ;;;--- Increment the counter
  46.                  (setq cntr (+ cntr 1))
  47.                  ;;;--- Get the next sub-entity or nested entity as you will
  48.                  (setq en(entnext en))
  49.                  ;;;--- Get the dxf group codes of the next sub-entity
  50.                  (setq enlist(entget en))
  51.                  ;;;--- Get the block type of the next sub-entity
  52.                  (setq blkType (cdr(assoc 0 enlist)))
  53.                  ;;;--- See if the dxf group code 66 exist.  if so, there are more nested attributes
  54.                  (setq group66(cdr(assoc 66 enlist)))
  55.                )
  56.              )
  57.            )
  58.          )
  59.          ;;;--- Else, the block does not contain attributes
  60.          (progn
  61.            ;;;--- Setup a bogus tag and value
  62.            (setq attTag "" attVal "")
  63.            ;;;--- Save the data gathered
  64.            (setq dataList(append dataList(list (list blkName attTag attVal))))
  65.          )
  66.        )
  67.        (setq blkCntr (+ blkCntr 1))
  68.      )
  69.    )                    
  70. )
  71. dataList
  72. )
  73. (defun c:npinum(/ datalist cnt pl ln off ls vr txt)
  74.          ;;;--- Get a the data from the blocks
  75.          (setq dataList(getattData))
  76.          ;;;--- Set up counter
  77.   (setq cnt 0)
  78.          ;;;--- Define pl
  79.     (setq pl "Plant__")
  80.     ;;;--- Set loop off switch
  81.     (setq off 0)
  82.     ;;;--- Loop to find the Correct Tag
  83. (while (= off 0)
  84.   (
  85.          ;;;--- Get each entry
  86.      (setq ls (nth cnt dataList))
  87.       ;;;--- Get only the Tag Name
  88.     (setq vr (nth 1 ls))
  89.   ;;;--- Check if Tag matches
  90.    (If (= vr pl)
  91.        (progn
  92.           ;;;--- Set txt to Tag Value
  93.    (setq txt(last ls))
  94.    ;;;--- Turn off Loop
  95.    (setq off(+ off 1))
  96.        )
  97.       ;;;--- If txt not found look at next item
  98.      (Progn
  99. (setq cnt (+ cnt 1))
  100.      )
  101.    )
  102.         )
  103.       )   
  104.         ;;;--- Set layer to 0 layer
  105. (command "layer" "set" "0" "")
  106.    ;;;--- Place text with Tag Value
  107.         (Command "MTEXT" PAUSE "WIDTH" "3" txt "")   
  108. (princ)
  109. ))

NPI_xx。图纸
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 15:35:38 | 显示全部楼层
嗨,elilewis,
 
欢迎来到论坛。
 
正如您所说,npinum例程中的while表达式似乎导致了错误。有一个额外的括号
 
 
 
尝试以下方法,看看效果如何
 
  1. (defun c:npinum(/ ); datalist cnt pl ln off ls vr txt)
  2.          ;;;--- Get a the data from the blocks
  3.          (setq dataList(getattData))
  4.          ;;;--- Set up counter
  5.   (setq cnt 0)
  6.          ;;;--- Define pl
  7.     (setq pl "Plant__")
  8.     ;;;--- Set loop off switch
  9.     (setq off 0)
  10.     ;;;--- Loop to find the Correct Tag
  11. (while (= off 0)
  12.   
  13. [color="Red"]   ;( -> Extra bracket removed[/color]
  14.   
  15.          ;;;--- Get each entry
  16.      (setq ls (nth cnt dataList))
  17.       ;;;--- Get only the Tag Name
  18.     (setq vr (nth 1 ls))
  19.   ;;;--- Check if Tag matches
  20.    (If (= vr pl)
  21.        (progn
  22.           ;;;--- Set txt to Tag Value
  23.    (setq txt(last ls))
  24.    ;;;--- Turn off Loop
  25.    (setq off(+ off 1))
  26.        )
  27.       ;;;--- If txt not found look at next item
  28.      (Progn
  29. (setq cnt (+ cnt 1))
  30.      )
  31.    )
  32.         );End of while
  33.    [color="Red"]     -> Extra bracket removed[/color]
  34.         ;;;--- Set layer to 0 layer
  35.    (command "layer" "set" "0" "")
  36.    ;;;--- Place text with Tag Value
  37.         (Command "MTEXT" PAUSE "WIDTH" "3" txt "")   
  38. (princ)
  39. )[color="Red"]
  40. -> Extra bracket removed
[/颜色]
 
当做
 
杰米
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:52:21 | 显示全部楼层
如果在ssget中只允许单个实体,那么您真的需要blkcounter吗?
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 16:10:14 | 显示全部楼层
谢谢大家的帮助。它现在可以正常工作,没有错误。我添加了一些东西,比如blkcounter,因为我稍后将扩展程序,逐步遍历每个块并自动放置文本。我是lisp编码的新手,需要从某个地方开始,不想咬太多。我一直在阅读不同的lisp代码,并试图找到正确的方法来使用表达式,它似乎是工作,但每个人和一段时间,我遇到了一个障碍。再次感谢您的帮助。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:24:56 | 显示全部楼层
没问题,很高兴现在一切正常。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 19:05 , Processed in 0.378262 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表