乐筑天下

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

[编程交流] 将两个LISP合并为一个

[复制链接]

3

主题

10

帖子

7

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 17:27:07 | 显示全部楼层 |阅读模式
嗨,我需要帮助。我想从现有的两个LISP中找到新的LISP。
第一个交付选择集(根据属性值),第二个应使用该选择集(更改选定对象的层)。
我认为这很琐碎,但我不知道怎么做。我在谷歌上花了一些时间,但什么也没学到。
 
我不喜欢在执行过程中选择任何东西。
稍后我将在代码中自己更改层名称(这是我对许多相同属性(具有不同的特定属性值)的全局层更改想法的第一步)。
 
 
1.
  1. (defun c:attselect ( / ss2 ss tag val n na)
  2. (setq ss2 (ssadd))
  3. (sssetfirst nil nil)
  4. (princ "\nSelect blocks containing attributes.")
  5. (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  6.    (progn
  7.     (setq tag "COLOR"
  8.           val "OR (1)"
  9.     );setq
  10.     (if (equal tag "")
  11.         (setq tag "*")
  12.     );if
  13.     (if (equal val "")
  14.         (setq val "*")
  15.     );if
  16.     (setq n 0)
  17.     (repeat (sslength ss)
  18.     (setq na (ssname ss n))
  19.     (if (sample_att_match na tag val)
  20.         (setq ss2 (ssadd na ss2))
  21.     );if
  22.     (setq n (+ n 1));setq
  23.     );repeat
  24.     (if (equal (getvar "cmdnames")  "")
  25.         (sssetfirst ss2 ss2)
  26.         (command ss2)
  27.     );if
  28.    );progn then
  29. );if
  30. (princ)
  31. );defun c:attselect
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. (defun sample_att_match ( na tag val / e1 a b flag)
  34. (while (and (setq na (entnext na))
  35.             (setq e1 (entget na))
  36.             (not (equal (cdr (assoc 0 e1)) "SEQEND"))
  37.             (not flag)
  38.        );and
  39.   (if (equal (cdr (assoc 0 e1)) "ATTRIB")
  40.       (progn
  41.        (setq a (cdr (assoc 2 e1)) ;2 is tag
  42.              b (cdr (assoc 1 e1)) ;1 is value
  43.        );setq
  44.        (if (and a
  45.                 (wcmatch a tag)
  46.                 b
  47.                 (wcmatch b val)
  48.            );and
  49.            (setq flag T);then jump out of the loop
  50.        );if
  51.       );progn then attrib
  52.   );if
  53. );while
  54. flag
  55. );defun sample_att_match
  56. (princ "\nType ATTSELECT to run")
  57. (princ)

 
我对我在某处找到的原始代码(标记“COLOR”,val“OR(1)”)进行了更改。
 
2.
  1. ; Changes selected objects to Layer PL1
  2. (defun c:setpl1 ()
  3. (tolayer
  4.    (ssget "_:L") ;;selection
  5.    "PL1"         ;;Layer
  6.    )
  7. (princ)
  8. )
  9. (defun tolayer ( ss lay / i e )
  10. ;;; ss - pickset
  11. ;;; lay -layer name
  12. (repeat (setq i (sslength ss))
  13.    (entmod
  14.      (subst
  15.        (cons 8 lay)
  16.        (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
  17.        (entget e)
  18.        )
  19.      )
  20.    )
  21. )

 
此代码可在此论坛上找到:http://www.cadtutor.net/forum/showthread.php?67438-LISP-to-move-selected-objects-to-a-specified-layer
VVA出版。
Thanx他,第一个代码的创建者(未知)。
Thanx未来的“合路器”
回复

使用道具 举报

66

主题

180

帖子

119

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
341
发表于 2022-7-5 17:44:42 | 显示全部楼层
你能不能把这个添加到你的第一个Lisp程序的末尾,在
  1. (C:setpl1)
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:54:47 | 显示全部楼层
几个变化
 
  1. not tested
  2. (defun c:attselect ( / ss2 tag val n na) ss has been removed so makes it a global variable
  3. ignore setpl1
  4. (defun c:test ()
  5. (c:attselect)
  6. (setq lay "PL1")
  7. (defun tolayer ( ss lay / i e ) ;ignore setpl1
  8. )
回复

使用道具 举报

3

主题

10

帖子

7

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 18:05:27 | 显示全部楼层
隐马尔可夫模型。。我没有成功地执行你的建议。我缺乏知识。我一直在尝试,添加,置换,实验,我一直在阅读AlfaLISP,JeffryLISP。。。找不到与“合并”相关的主题。我不理解在一个代码(在一个*.lsp中)中执行不同函数的一般逻辑。
拜托,你能帮我做吗?我会努力从中获取知识,而不仅仅是使用它
回复

使用道具 举报

3

主题

10

帖子

7

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 18:17:37 | 显示全部楼层
嗨,我决定先读一本书。我确实学到了一些东西,现在很多事情都更清楚了。。。我让代码工作。请记住,我是LISP的初学者,现在我很高兴代码能够正常工作。
 
在我看来,变量ss2应该是全局的,因为我需要tolayer函数中的选择集。这样就行了。
 
我需要进一步的帮助,每一条评论都很有帮助。我觉得自己又像个学生了(没有人对这个话题做准备就无法得到教授的咨询)。
我附上了示例1。dwg以便于测试。
请看代码中的注释。
 
代码如下:
 
  1. ;|combining attselect and layer change.
  2. c:test- it works!
  3. - at the end should do this: select all blocks in drawing, filter it by attribute value "OR (1)", change layer of those to PURPLE
  4. - main command that combines two of those:
  5.         c:attselect - selects all blocks in layer GREEN with attribute value "OR (1)"
  6.         c:tolay - it changes selection layer to PURPLE
  7. idea1: I wish that I dont need to select manualy whole drawing with mouse. I wish LISP do it without me.
  8. idea2: Later... :-)        |;
  9. ;final combining command
  10. (defun c:test ()
  11. (c:attselect)
  12. (c:tolay)
  13. )
  14. ;makes selection (only blocks within layer GREEN)
  15. (defun c:attselect ( / ss tag val n na)
  16. (setq ss2 (ssget "all" '((8 . "GREEN")(0 . "INSERT"))))       
  17. ;|
  18. comment for line above
  19. this is original line in original command: (setq ss2 (ssadd))  
  20. I'm trying to make this selection automatic (without mouse input of selecting all
  21. I don't know how!!!
  22. |;
  23. (sssetfirst nil nil)
  24. (princ "\nSelect blocks containing attributes.")
  25. (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  26.    (progn
  27.     (setq tag "COLOR"
  28.           val "OR (1)"
  29.     );setq
  30.     (if (equal tag "")
  31.         (setq tag "*")
  32.     );if
  33.     (if (equal val "")
  34.         (setq val "*")
  35.     );if
  36.     (setq n 0)
  37.     (repeat (sslength ss)
  38.     (setq na (ssname ss n))
  39.     (if (sample_att_match na tag val)
  40.         (setq ss2 (ssadd na ss2))
  41.     );if
  42.     (setq n (+ n 1));setq
  43.     );repeat
  44.     (if (equal (getvar "cmdnames")  "")
  45.         (sssetfirst ss2 ss2)
  46.         (command ss2)
  47.     );if
  48.    );progn then
  49. );if
  50. (princ)
  51. );defun c:attselect
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. (defun sample_att_match ( na tag val / e1 a b flag)
  54. (while (and (setq na (entnext na))
  55.             (setq e1 (entget na))
  56.             (not (equal (cdr (assoc 0 e1)) "SEQEND"))
  57.             (not flag)
  58.        );and
  59.   (if (equal (cdr (assoc 0 e1)) "ATTRIB")
  60.       (progn
  61.        (setq a (cdr (assoc 2 e1)) ;2 is tag
  62.              b (cdr (assoc 1 e1)) ;1 is value
  63.        );setq
  64.        (if (and a
  65.                 (wcmatch a tag)
  66.                 b
  67.                 (wcmatch b val)
  68.            );and
  69.            (setq flag T);then jump out of the loop
  70.        );if
  71.       );progn then attrib
  72.   );if
  73. );while
  74. flag
  75. );defun sample_att_match
  76. (princ "\nType ATTSELECT to run")
  77. (princ)
  78. ; changes layer of selection provided by attselect
  79. (defun c:tolay ()
  80. (command "_.chprop" (eval ss2) "" "_layer" "PURPLE" "")
  81. )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 18:38:48 | 显示全部楼层
理想1:尝试ssget“X”查找ssget的帮助,您可以做围栏、点、多边形内等X=全部,再加上其他。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 03:32 , Processed in 0.947406 second(s), 64 queries .

© 2020-2025 乐筑天下

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