legg1979 发表于 2022-7-6 00:01:56

从Setq运行Defun?

我正在尝试从setq运行lisp。
 
我确信有一种更有效的方法,但我很坚强&知识很少。
 
我有一个lisp,我想用于许多块插入、文本注释和其他一些事情。
我不是在寻找重写的代码,我只是需要能够从setq运行“defun”。
代码开头的setq是每个文件中唯一会更改的内容。我确实有代码工作,但必须去通过,找到并编辑每个差异。我正在努力使它更容易改变。
 
她是我代码的摘录。我有一个单独的c:defun,它运行并调用“the sub命令”&我在同一个lisp中编写了new1和new2 defun。我的问题是运行new1或new2
 
 

(setq value-1 "changeable-value") ;this is the 1st stored value

(setq new1 (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.

(setq new2 (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.




(defun the-sub-command()
(initget 1 "EXG PROP")
(setq exg-prop (getkword"\nExisting or Proposed? : "))      ;get INFO
(COND
((= exg-prop "EXG") new1)


((= exg-prop "PROP") new2)


(T (prompt "\nOpps there was an error!"))
)
(princ)
)



(defun new1()
......the commands
(princ)
)


(defun new2()
......the commands
(princ)
)

BlackBox 发表于 2022-7-6 00:18:58


;; ...
(COND
((= exg-prop "EXG") (new1))


((= exg-prop "PROP") (new2))


(T (prompt "\nOpps there was an error!"))
)
;; ...

legg1979 发表于 2022-7-6 00:23:17

谢谢你的回复,但我在发帖之前已经试过了&只是仔细检查了一下,没有成功。
 
它试图运行的命令在Defun之前没有C:。
当运行代码而不是运行命令时,我在命令行中得到一个错误
 
; 错误:函数错误:“可变值通用文本1”

MSasu 发表于 2022-7-6 00:34:24

BlackBox建议你的是正确的!
 
请注意,New1/New2函数似乎是在where调用后定义的;这个问题被以下事实掩盖了:您使用相同的符号来存储字符串,然后是函数定义!

legg1979 发表于 2022-7-6 00:45:20

谢谢
 
那么,我想做的事情是可以实现的吗?
我试图通过在即将出现的问题上学习嘴唇,如果有正确的方法,请有人给我指出正确的方向
干杯

MSasu 发表于 2022-7-6 00:59:39

我看没有理由不能实现!尝试如下调整代码:
 
(setq value-1 "changeable-value") ;this is the 1st stored value
(setq new1 string1 (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.
(setq new2 string2 (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.

;move function definitions here!
(defun new1()
......the commands
(princ)
)

(defun new2()
......the commands
(princ)
)


(defun the-sub-command()
(initget 1 "EXG PROP")
(setq exg-prop (getkword"\nExisting or Proposed? : "))      ;get INFO
(COND
((= exg-prop "EXG")(new1))
((= exg-prop "PROP") (new2))
(T (prompt "\nOpps there was an error!"))
)
(princ)
)

MSasu 发表于 2022-7-6 01:10:56

另外两条评论:
连接字符串时不应该有空格吗?
(strcat value-1 " " "generic text1")
第二,在选项中使用一个字母的关键字不是更好吗?它与AutoCAD行为相匹配,使用更简单:
(initget 1 "Existing Proposed")
此外,您的提示中不建议使用所需的输入(“EXG”甚至不直观)。
页: [1]
查看完整版本: 从Setq运行Defun?