乐筑天下

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

[编程交流] 为什么ssdel删除实体

[复制链接]

16

主题

69

帖子

54

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-5 17:03:55 | 显示全部楼层 |阅读模式
我正在编写一个例程,该例程要求我从选择集中删除对象,同时仍保留原始集。遇到问题后,我创建了一个测试例程来查看ssdel是如何运行的。我希望它从selC中删除selB,同时保持selA和selD不变,以保持原始选择。不过,它正在从所有相关的选择集中删除selB。它为什么这样做,我该如何修复它?
 
  1. (defun c:TD () ;Test Delete
  2. (setq selA(ssget)) ;get base selection A
  3. (setq selB(ssget)) ;get selection B to remove from selection C
  4. (setq selC selA)   ;copies selection A and removes selection B to return the difference
  5. (setq selD selA)   ;extra variable to test how ssdel works
  6. (setq i 0) ;index
  7. (repeat (sslength selB) ;repeat for each entity in selB
  8.    (ssdel (ssname selB i) selC) ;intended to remove selB from selC. It is also removeing selB from selA, which I don't want.
  9.    (setq i (1+ i))) ;increment
  10. )
  11. ;Functions below are used to test which geometry is contained in which selection set
  12. (defun c:dela () ;delete geometry in selection A
  13. (If(/= nil selA)(command ".erase" selA "")(princ "\n selA is empty. Run TD to initialize"))(princ)) ;if selA contains entities, delete them. If not, display error.
  14. (defun c:delb () ;delete geometry in selection B
  15. (If(/= nil selB)(command ".erase" selB "")(princ "\n selB is empty. Run TD to initialize"))(princ)) ;if selB contains entities, delete them. If not, display error.
  16. (defun c:delc () ;delete geometry in selection C
  17. (If(/= nil selC)(command ".erase" selC "")(princ "\n selC is empty. Run TD to initialize"))(princ)) ;if selC contains entities, delete them. If not, display error.
  18. (defun c:deld () ;delete geometry in selection d
  19. (If(/= nil selD)(command ".erase" selD "")(princ "\n selD is empty. Run TD to initialize"))(princ)) ;if selD contains entities, delete them. If not, display error.
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 17:27:02 | 显示全部楼层
这不会复制选取集,
 
  1. (setq selC selA)  

 
它只是将另一个指针指向原始选择集
 
  1. Command: sq
  2. Variable Name:   ss1
  3. Variable Value:   (ssget)
  4. Select objects: Other corner: 3 found
  5. Select objects:  <Selection set: 701>
  6. Command: sq
  7. Variable Name:   ss2
  8. Variable Value:   (ssget)
  9. Select objects: c
  10. First corner: Other corner: 2 found
  11. Select objects: c
  12. First corner: Other corner: 1 found
  13. Select objects:  <Selection set: 702>
  14. Command: (setq ss3 ss1)
  15. <Selection set: 701>
  16. Command: (sslength ss3)
  17. 3
  18. Command: (ssdel (ssname ss1 0) ss3)
  19. <Selection set: 701>
  20. Command: (sslength ss1)
  21. 2
  22. Command: !SS3
  23. <Selection set: 701>
  24. Command: !SS1
  25. <Selection set: 701>

 
 
在本例中,查看所有内容如何引用回选择集701
 
-大卫
回复

使用道具 举报

16

主题

69

帖子

54

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-5 17:34:20 | 显示全部楼层
非常感谢。我将对这件事进行研究。如果你有关于如何修改例程以使其按我所希望的方式工作的建议,那将非常棒,但我认为我现在有足够的信息来搜索答案。我非常感谢你这么快就回答了。谢谢
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 17:41:38 | 显示全部楼层
要复制选取集,请执行以下操作:
 
  1. (defun css (ss / rs i en)
  2. (setq rs (ssadd)
  3. (setq i 0)
  4. (while (setq en (ssname ss i))
  5.       (ssadd en rs)
  6.       (setq i (1+i)))
  7. rs)

 
  1. (setq ss2 (css ss1))

即时编写-未经测试
 
-大卫
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 17:54:59 | 显示全部楼层
你甚至可以用更少的代码来实现它。。。只有您必须安装Express Tools:
 
  1. (setq ss2 (acet-ss-union (list ss1)))
回复

使用道具 举报

16

主题

69

帖子

54

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-5 18:10:13 | 显示全部楼层
谢谢你们!我花了比我预想的更长的时间才弄明白。它现在工作得很好。我也很高兴有两个版本,因为我现在可以在更广泛的例程中使用它。我确实安装了Express Tools,所以我在那里很好。为了便于将来需要它的人参考,在我的代码中实现的最终解决方案如下:
 
  1. (defun c:TD () ;Test Delete
  2. (setq selA (ssget)) ;get base selection A
  3. (setq selB (ssget)) ;get selection B to remove from selection C
  4. (setq selC (acet-ss-union (list selA))) ;creates a new selection set and copies selection A
  5. (setq i 0) ;index
  6. (repeat (sslength selB) ;repeat for each entity in selB
  7.    (ssdel (ssname selB i) selC) ;removes selB from selC
  8.    (setq i        (1+ i))) ;increment
  9. )
  10. ;Functions below are used to test which geometry is contained in which selection set
  11. (defun c:dela () ;delete geometry in selection A
  12. (If(/= nil selA)(command ".erase" selA "")(princ "\n selA is empty. Run TD to initialize"))(princ)) ;if selA contains entities, delete them. If not, display error.
  13. (defun c:delb () ;delete geometry in selection B
  14. (If(/= nil selB)(command ".erase" selB "")(princ "\n selB is empty. Run TD to initialize"))(princ)) ;if selB contains entities, delete them. If not, display error.
  15. (defun c:delc () ;delete geometry in selection C
  16. (If(/= nil selC)(command ".erase" selC "")(princ "\n selC is empty. Run TD to initialize"))(princ)) ;if selC contains entities, delete them. If not, display error.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 09:10 , Processed in 0.438671 second(s), 75 queries .

© 2020-2025 乐筑天下

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