需要While expre的帮助
几天来,我一直在尝试使例程正常工作,但在visual lisp代码检查器中找不到克服此错误的方法;“错误:错误函数:(“1”“Plant\uu”“1164”)”。当我逐步遍历代码时,它会给出正确的结果,但为了得到正确的结果,我跳过了while表达式。所以我相信这就是我的错误所在。在autocad窗口中运行例程时,出现以下错误:“错误:错误参数类型:consp nil”。
有什么建议吗?
(附件是我用来收集标签数据的文件)
注:getattdata程序是另一个lisp例程的一部分,该例程将块数据收集到列表中,并与前一个程序保持相同。我创建的唯一部分是npinum程序部分。
;;;--- Function to get the block data
(defun getAttData(/ eset dataList blkCntr en enlist blkType blkName entName
attTag attVal group66)
;;;--- Set up an empty list
(setq dataList(list))
;;;--- If that type of entity exist in drawing
(if (setq eset(ssget ":s" (list (cons 0 "INSERT"))))
(progn
;;;--- Set up some counters
(setq blkCntr 0 cntr 0)
;;;--- Loop through each entity
(while (< blkCntr (sslength eset))
;;;--- Get the entity's name
(setq en(ssname eset blkCntr))
;;;--- Get the DXF group codes of the entity
(setq enlist(entget en))
;;;--- Get the name of the block
(setq blkName(cdr(assoc 2 enlist)))
;;;--- Check to see if the block's attribute flag is set
(if(cdr(assoc 66 enlist))
(progn
;;;--- Get the entity name
(setq en(entnext en))
;;;--- Get the entity dxf group codes
(setq enlist(entget en))
;;;--- Get the type of block
(setq blkType (cdr(assoc 0 enlist)))
;;;--- If group 66 then there are attributes nested inside this block
(setq group66(cdr(assoc 66 enlist)))
;;;--- Loop while the type is an attribute or a nested attribute exist
(while(or (= blkType "ATTRIB")(= group66 1))
;;;--- Get the block type
(setq blkType (cdr(assoc 0 enlist)))
;;;--- Get the block name
(setq entName (cdr(assoc 2 enlist)))
;;;--- Check to see if this is an attribute or a block
(if(= blkType "ATTRIB")
(progn
;;;--- Save the name of the attribute
(setq attTag(cdr(assoc 2 enlist)))
;;;--- Get the value of the attribute
(setq attVal(cdr(assoc 1 enlist)))
;;;--- Save the data gathered
(setq dataList(append dataList(list (list blkName attTag attVal))))
;;;--- Increment the counter
(setq cntr (+ cntr 1))
;;;--- Get the next sub-entity or nested entity as you will
(setq en(entnext en))
;;;--- Get the dxf group codes of the next sub-entity
(setq enlist(entget en))
;;;--- Get the block type of the next sub-entity
(setq blkType (cdr(assoc 0 enlist)))
;;;--- See if the dxf group code 66 exist.if so, there are more nested attributes
(setq group66(cdr(assoc 66 enlist)))
)
)
)
)
;;;--- Else, the block does not contain attributes
(progn
;;;--- Setup a bogus tag and value
(setq attTag "" attVal "")
;;;--- Save the data gathered
(setq dataList(append dataList(list (list blkName attTag attVal))))
)
)
(setq blkCntr (+ blkCntr 1))
)
)
)
dataList
)
(defun c:npinum(/ datalist cnt pl ln off ls vr txt)
;;;--- Get a the data from the blocks
(setq dataList(getattData))
;;;--- Set up counter
(setq cnt 0)
;;;--- Define pl
(setq pl "Plant__")
;;;--- Set loop off switch
(setq off 0)
;;;--- Loop to find the Correct Tag
(while (= off 0)
(
;;;--- Get each entry
(setq ls (nth cnt dataList))
;;;--- Get only the Tag Name
(setq vr (nth 1 ls))
;;;--- Check if Tag matches
(If (= vr pl)
(progn
;;;--- Set txt to Tag Value
(setq txt(last ls))
;;;--- Turn off Loop
(setq off(+ off 1))
)
;;;--- If txt not found look at next item
(Progn
(setq cnt (+ cnt 1))
)
)
)
)
;;;--- Set layer to 0 layer
(command "layer" "set" "0" "")
;;;--- Place text with Tag Value
(Command "MTEXT" PAUSE "WIDTH" "3" txt "")
(princ)
))
NPI_xx。图纸 嗨,elilewis,
欢迎来到论坛。
正如您所说,npinum例程中的while表达式似乎导致了错误。有一个额外的括号
尝试以下方法,看看效果如何
(defun c:npinum(/ ); datalist cnt pl ln off ls vr txt)
;;;--- Get a the data from the blocks
(setq dataList(getattData))
;;;--- Set up counter
(setq cnt 0)
;;;--- Define pl
(setq pl "Plant__")
;;;--- Set loop off switch
(setq off 0)
;;;--- Loop to find the Correct Tag
(while (= off 0)
;( -> Extra bracket removed
;;;--- Get each entry
(setq ls (nth cnt dataList))
;;;--- Get only the Tag Name
(setq vr (nth 1 ls))
;;;--- Check if Tag matches
(If (= vr pl)
(progn
;;;--- Set txt to Tag Value
(setq txt(last ls))
;;;--- Turn off Loop
(setq off(+ off 1))
)
;;;--- If txt not found look at next item
(Progn
(setq cnt (+ cnt 1))
)
)
);End of while
-> Extra bracket removed
;;;--- Set layer to 0 layer
(command "layer" "set" "0" "")
;;;--- Place text with Tag Value
(Command "MTEXT" PAUSE "WIDTH" "3" txt "")
(princ)
)
-> Extra bracket removed[/颜色]
当做
杰米 如果在ssget中只允许单个实体,那么您真的需要blkcounter吗? 谢谢大家的帮助。它现在可以正常工作,没有错误。我添加了一些东西,比如blkcounter,因为我稍后将扩展程序,逐步遍历每个块并自动放置文本。我是lisp编码的新手,需要从某个地方开始,不想咬太多。我一直在阅读不同的lisp代码,并试图找到正确的方法来使用表达式,它似乎是工作,但每个人和一段时间,我遇到了一个障碍。再次感谢您的帮助。 没问题,很高兴现在一切正常。
页:
[1]