明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1199|回复: 4

字符串转变量

[复制链接]
发表于 2023-2-18 09:39:18 | 显示全部楼层 |阅读模式
80明经币
本帖最后由 刘炎华 于 2024-7-6 23:40 编辑

请教一下大家,字符串如何转变量?

  (setq blkname "A4")
  (setq blktag "零件号")

附件: 您需要 登录 才可以下载或查看,没有账号?注册

最佳答案

查看完整内容

(defun getva(en attname / return e test ent) (setq e en return nil test t) (while(and test(setq e(entnext e))) (setq ent(entget e)) (cond ((not(=(cdr(assoc 0 ent))"ATTRIB"))(setq test nil)) ((=(cdr(assoc 0 ent))"SEQEND")(setq test nil)) ((=(cdr(assoc 2 ent))attname)(setq return(cdr(assoc 1 ent))test nil)) ) ) return ) (setq ss(ssget "x" '((0 . "I ...
发表于 2023-2-18 09:39:19 | 显示全部楼层
刘炎华 发表于 2024-7-7 10:58
是这样改吗?
  (set (read "blkname") "A4")
  (set (read "blktag") "零件号")

(defun getva(en attname / return e test ent)
  (setq e en return nil test t)
  (while(and test(setq e(entnext e)))
    (setq ent(entget e))
    (cond
      ((not(=(cdr(assoc 0 ent))"ATTRIB"))(setq test nil))
      ((=(cdr(assoc 0 ent))"SEQEND")(setq test nil))
      ((=(cdr(assoc 2 ent))attname)(setq return(cdr(assoc 1 ent))test nil))
    )
  )
  return
)
(setq ss(ssget "x" '((0 . "INSERT")(2 . "A4"))))
(setq es(vl-remove-if 'listp(mapcar 'cadr(ssnamex ss))))
(setq vs(mapcar '(lambda(x)(getva x "零件号"))es))
回复

使用道具 举报

 楼主| 发表于 2024-7-6 23:42:24 | 显示全部楼层
请教一下大家,字符串如何转变量?
回复

使用道具 举报

发表于 2024-7-7 09:41:44 | 显示全部楼层
;;; (set (read "字符串")  值)
_$  (set (read "A4") "零件号")
"零件号"
_$ (set (read "A5") 1234.56)
1234.56

_$ a4
"零件号"
_$ a5
1234.56
回复

使用道具 举报

 楼主| 发表于 2024-7-7 10:58:16 | 显示全部楼层
本帖最后由 刘炎华 于 2024-7-7 11:01 编辑
yshf 发表于 2024-7-7 09:41
;;; (set (read "字符串")  值)
_$  (set (read "A4") "零件号")
"零件号"

是这样改吗?
  (set (read "blkname") "A4")
  (set (read "blktag") "零件号")
  这个工具原来是要选择属性块对应的标记,想改成指定的块和标记(不用选择了)
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-23 10:52 , Processed in 0.249877 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表