benhubel 发表于 2022-7-5 17:03:55

为什么ssdel删除实体

我正在编写一个例程,该例程要求我从选择集中删除对象,同时仍保留原始集。遇到问题后,我创建了一个测试例程来查看ssdel是如何运行的。我希望它从selC中删除selB,同时保持selA和selD不变,以保持原始选择。不过,它正在从所有相关的选择集中删除selB。它为什么这样做,我该如何修复它?
 
(defun c:TD () ;Test Delete

(setq selA(ssget)) ;get base selection A
(setq selB(ssget)) ;get selection B to remove from selection C
(setq selC selA)   ;copies selection A and removes selection B to return the difference
(setq selD selA)   ;extra variable to test how ssdel works

(setq i 0) ;index
(repeat (sslength selB) ;repeat for each entity in selB
   (ssdel (ssname selB i) selC) ;intended to remove selB from selC. It is also removeing selB from selA, which I don't want.
   (setq i (1+ i))) ;increment
)

;Functions below are used to test which geometry is contained in which selection set
(defun c:dela () ;delete geometry in selection A
(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.

(defun c:delb () ;delete geometry in selection B
(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.

(defun c:delc () ;delete geometry in selection C
(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.

(defun c:deld () ;delete geometry in selection d
(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.

David Bethel 发表于 2022-7-5 17:27:02

这不会复制选取集,
 

(setq selC selA)

 
它只是将另一个指针指向原始选择集
 

Command: sq

Variable Name:   ss1

Variable Value:   (ssget)

Select objects: Other corner: 3 found

Select objects:<Selection set: 701>

Command: sq

Variable Name:   ss2

Variable Value:   (ssget)

Select objects: c
First corner: Other corner: 2 found

Select objects: c
First corner: Other corner: 1 found

Select objects:<Selection set: 702>

Command: (setq ss3 ss1)
<Selection set: 701>

Command: (sslength ss3)
3

Command: (ssdel (ssname ss1 0) ss3)
<Selection set: 701>

Command: (sslength ss1)
2

Command: !SS3
<Selection set: 701>

Command: !SS1
<Selection set: 701>

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

benhubel 发表于 2022-7-5 17:34:20

非常感谢。我将对这件事进行研究。如果你有关于如何修改例程以使其按我所希望的方式工作的建议,那将非常棒,但我认为我现在有足够的信息来搜索答案。我非常感谢你这么快就回答了。谢谢

David Bethel 发表于 2022-7-5 17:41:38

要复制选取集,请执行以下操作:
 

(defun css (ss / rs i en)
(setq rs (ssadd)
(setq i 0)
(while (setq en (ssname ss i))
      (ssadd en rs)
      (setq i (1+i)))
rs)

 

(setq ss2 (css ss1))

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

marko_ribar 发表于 2022-7-5 17:54:59

你甚至可以用更少的代码来实现它。。。只有您必须安装Express Tools:
 

(setq ss2 (acet-ss-union (list ss1)))

benhubel 发表于 2022-7-5 18:10:13

谢谢你们!我花了比我预想的更长的时间才弄明白。它现在工作得很好。我也很高兴有两个版本,因为我现在可以在更广泛的例程中使用它。我确实安装了Express Tools,所以我在那里很好。为了便于将来需要它的人参考,在我的代码中实现的最终解决方案如下:
 
(defun c:TD () ;Test Delete

(setq selA (ssget)) ;get base selection A
(setq selB (ssget)) ;get selection B to remove from selection C
(setq selC (acet-ss-union (list selA))) ;creates a new selection set and copies selection A

(setq i 0) ;index
(repeat (sslength selB) ;repeat for each entity in selB
   (ssdel (ssname selB i) selC) ;removes selB from selC
   (setq i        (1+ i))) ;increment
)

;Functions below are used to test which geometry is contained in which selection set
(defun c:dela () ;delete geometry in selection A
(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.

(defun c:delb () ;delete geometry in selection B
(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.

(defun c:delc () ;delete geometry in selection C
(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.
页: [1]
查看完整版本: 为什么ssdel删除实体