乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 32|回复: 6

[编程交流] 从Setq运行Defun?

[复制链接]

4

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 00:01:56 | 显示全部楼层 |阅读模式
我正在尝试从setq运行lisp。
 
我确信有一种更有效的方法,但我很坚强&知识很少。
 
我有一个lisp,我想用于许多块插入、文本注释和其他一些事情。
我不是在寻找重写的代码,我只是需要能够从setq运行“defun”。
代码开头的setq是每个文件中唯一会更改的内容。我确实有代码工作,但必须去通过,找到并编辑每个差异。我正在努力使它更容易改变。
 
她是我代码的摘录。我有一个单独的c:defun,它运行并调用“the sub命令”&我在同一个lisp中编写了new1和new2 defun。我的问题是运行new1或new2
 
 
  1. (setq value-1 "changeable-value") ;this is the 1st stored value
  2. (setq new1 (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.
  3. (setq new2 (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.
  4. (defun the-sub-command()
  5. (initget 1 "EXG PROP")
  6. (setq exg-prop (getkword  "\nExisting or Proposed? [Existing/Proposed]: "))        ;get INFO
  7. (COND
  8. ((= exg-prop "EXG") new1)
  9. ((= exg-prop "PROP") new2)
  10. (T (prompt "\nOpps there was an error!"))
  11. )
  12. (princ)
  13. )
  14. (defun new1()
  15. ......the commands
  16. (princ)
  17. )
  18. (defun new2()
  19. ......the commands
  20. (princ)
  21. )
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 00:18:58 | 显示全部楼层
  1. ;; ...
  2. (COND
  3. ((= exg-prop "EXG") [b][color="red"]([/color][/b]new1[b][color="red"])[/color][/b])
  4. ((= exg-prop "PROP") [b][color="red"]([/color][/b]new2[b][color="red"])[/color][/b])
  5. (T (prompt "\nOpps there was an error!"))
  6. )
  7. ;; ...
回复

使用道具 举报

4

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 00:23:17 | 显示全部楼层
谢谢你的回复,但我在发帖之前已经试过了&只是仔细检查了一下,没有成功。
 
它试图运行的命令在Defun之前没有C:。
当运行代码而不是运行命令时,我在命令行中得到一个错误
 
; 错误:函数错误:“可变值通用文本1”
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 00:34:24 | 显示全部楼层
BlackBox建议你的是正确的!
 
请注意,New1/New2函数似乎是在where调用后定义的;这个问题被以下事实掩盖了:您使用相同的符号来存储字符串,然后是函数定义!
回复

使用道具 举报

4

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 00:45:20 | 显示全部楼层
谢谢
 
那么,我想做的事情是可以实现的吗?
我试图通过在即将出现的问题上学习嘴唇,如果有正确的方法,请有人给我指出正确的方向
干杯
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 00:59:39 | 显示全部楼层
我看没有理由不能实现!尝试如下调整代码:
 
  1. (setq value-1 "changeable-value") ;this is the 1st stored value
  2. (setq [color=red][s]new1[/s] string1[/color] (strcat value-1 "generic text1")) ;this is the 1st stored value combined with a 1st generic value.
  3. (setq [color=red][s]new2[/s] string2[/color] (strcat value-1 "generic text2")) ;this is the 1st stored value combined with a 2nd generic value.
  4. [color=red];move function definitions here![/color]
  5. [color=blue](defun new1()
  6. ......the commands
  7. (princ)
  8. )
  9. (defun new2()
  10. ......the commands
  11. (princ)
  12. )[/color]
  13. (defun the-sub-command()
  14. (initget 1 "EXG PROP")
  15. (setq exg-prop (getkword  "\nExisting or Proposed? [Existing/Proposed]: "))        ;get INFO
  16. (COND
  17. ((= exg-prop "EXG")  [color=red]([/color]new1[color=red])[/color])
  18. ((= exg-prop "PROP") [color=red]([/color]new2[color=red])[/color])
  19. (T (prompt "\nOpps there was an error!"))
  20. )
  21. (princ)
  22. )
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 01:10:56 | 显示全部楼层
另外两条评论:
连接字符串时不应该有空格吗?
  1. (strcat value-1 [color=red]" "[/color] "generic text1")

第二,在选项中使用一个字母的关键字不是更好吗?它与AutoCAD行为相匹配,使用更简单:
  1. (initget 1 "Existing Proposed")

此外,您的提示中不建议使用所需的输入(“EXG”甚至不直观)。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:13 , Processed in 0.515549 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表