yu960312 发表于 2023-9-15 20:53:21

如何获取批量给字符串变量所赋的值?

(defun C:GG(/)
;; 批量给字符串变量赋值
(setq n 0)
(repeat 8
(setq n (1+ n))
(set (read (strcat "lst_" (itoa n))) (strcat "A_" (itoa n)))
)

;; 如何批量获取变量的值???
(setq n 0)
(repeat 8
(setq n (1+ n))
(princ "\n")
(princ (read (strcat "lst_" (itoa n))))
)
(princ)
)


yu960312 发表于 2023-9-15 21:07:26

问题已解决,不好意思
(defun C:GG(/)
;; 批量给字符串变量赋值
(setq n 0)
(repeat 8
(setq n (1+ n))
(set (read (strcat "lst_" (itoa n))) (strcat "a_" (itoa n)))
)

;; 批量获取变量值
(setq n 0)
(repeat 8
(setq n (1+ n))
(setq str(vl-symbol-value (read (strcat "lst_" (itoa n)))))
(princ "\n")
(princ str)
)
(princ)
)

飞雪神光 发表于 2023-9-15 22:50:57

(eval(read (strcat "lst_" (itoa n)))) eval也可以

yu960312 发表于 2023-9-15 22:56:56

飞雪神光 发表于 2023-9-15 22:50
(eval(read (strcat "lst_" (itoa n)))) eval也可以

感谢大佬解惑

xyp1964 发表于 2023-9-15 23:41:11

(defun c:tt (/)
"批量给字符串变量赋值"
(setq        n   0
        lst '()
)
(repeat 8
    (setq n   (1+ n)
          a   (strcat "lst_" (itoa n))
          b   (strcat "a_" (itoa n))
          lst (cons a lst)
    )
    (set (read a) b)
)
"批量获取变量值"
(setq lst (reverse lst))
(princ (mapcar '(lambda (x) (eval (read x))) lst))
(princ)
)

yu960312 发表于 2023-9-16 07:50:24

xyp1964 发表于 2023-9-15 23:41


谢谢,了解了
页: [1]
查看完整版本: 如何获取批量给字符串变量所赋的值?