据我所知,使用assoc函数是在关联列表中找到关键值,这就像字典搜索你需要给关键搜索特定值检查更多here。
在应用函数assoc之后,它的输出是列表格式,见下面的例子。
(assoc 8 (entget (car (entsel)) ))
选择像(8 . "0")这样的实体输出后
这是您的案例名称中所选实体的图层名称可能不同
再检查一个例子
(assoc 10 (entget (car (entsel)) ))
选择实体输出后是(10 3.25 5.5 0.0)
输出值是所选实体的插入坐标。
请注意,Strcat函数只加入字符串检查更多here。
在第5行的函数中,您尝试使用列表连接字符串,以确定错误发生的原因。
当你提到错误时,我认为你需要加入价值3000.0.
为此你可以改变你的功能如下。
(defun c:getObjectLenght()
(setq a (car (entsel "\nSelect a object: ")))
(setq b (entget a))
(setq c (if (assoc 142 b) (rtos (cdr (assoc 142 b))) "Not Found" ) )
;Note that rtos function use to convert decimal value into sting.
; And if condition use in case entity not contain Key value 142 so to avoid error.
(prompt (strcat "\nThe value of 142 is: " c))
(princ)
)
我从来没有遇到过DXF代码assoc 142我谷歌,但没有找到太多。