Lee Mac 发表于 2022-7-6 15:42:38

好吧,我要用这个把自己逼疯了。。。
 
为什么此实体集合中缺少一个圆?
 

(defun c:test(/ l1 c1 eLst ss)
(setq ss (ssadd))
(command "_line" "0,5" "0,11" "")
(setq l1 (entlast))
(command "_circle" "0,5" "5")
(setq c1 (entlast))
(command "-array" l1 c1 "" "P" "0,0" "3" "" "Y")
(setq eLst (Ent_List_to_End c1))
(foreach n eLst (ssadd n ss))
(command "_move" ss l1 "" pause pause)
)

(defun Ent_List_to_End(ent / a)
(reverse
   (if(setq a(entnext ent))
      (cons ent(Ent_List_to_End a)))))

 
似乎太简单了,不会出错

CarlB 发表于 2022-7-6 15:47:23

因为您添加到列表中的第一项是c1的“entnext”;您需要首先将c1添加到列表中。

Lee Mac 发表于 2022-7-6 15:48:44

好的,我接受你的观点,卡尔,但是为什么这不移动c1?
 

(defun c:test(/ l1 c1 eLst ss)
(setq ss (ssadd))
(command "_line" "0,5" "0,11" "")
(setq l1 (entlast))
(command "_circle" "0,5" "5")
(setq c1 (entlast))
(command "-array" l1 c1 "" "P" "0,0" "3" "" "Y")
(setq eLst (Ent_List_to_End c1))
(foreach n eLst (ssadd n ss))
(command "_move" ss l1 c1 "" pause pause)
)

(defun Ent_List_to_End(ent / a)
(reverse
   (if(setq a(entnext ent))
      (cons ent(Ent_List_to_End a)))))

CarlB 发表于 2022-7-6 15:52:20

我得到它确实移动c1,它不移动右下角的圆,这是(entlast)。
 
我误解了你在列表中添加项目的惯例,它最初确实添加了c1,因为它是第一个循环的“a”。但是当“entnext a”为nil时,循环停止,因此实际上无法将最后一项添加到列表中。我想
 
 
**编辑**
这个实体集合例程没有递归版本那么优雅,但似乎可以工作。此外,还修改了移动命令:
 
(defun c:test()
(setq ss (ssadd))
(command "_line" "0,5" "0,11" "")
(setq l1 (entlast))
(command "_circle" "0,5" "5")
(setq c1 (entlast))
(command "-array" l1 c1 "" "P" "0,0" "3" "" "Y")
(setq eLst (Ent_List_to_End c1))
(foreach n eLst (ssadd n ss))
(command "_move" ss l1 "" pause pause)
)
(defun Ent_List_to_End(ent / a entlist)

(while ent
    (setq entlist (cons ent entlist))
    (setq ent (entnext ent))
)
entlist
)

badien 发表于 2022-7-6 15:57:51

CarlB的功能很棒!!
如果你仍然想使用你的函数,你可以参考下面的文件,我只添加了另一个函数来选择你的函数错过的对象。
希望这有帮助!!
干杯
选择“上一个”。LSP

Lee Mac 发表于 2022-7-6 16:00:42

啊,我现在明白了。。。因为它测试实体的entnext,所以它将错过其中一个实体。。。即“entlast”
 
非常感谢卡尔为解决这个问题贡献的时间,我非常感谢。
 
我已经测试了你的代码,正如预期的那样,它工作得很好。
 
在您建议原始代码不包含“entlast”之后,我稍微更改了代码,发现这也有效:
 
同样感谢Badien的代码,非常感谢您的时间。

David Bethel 发表于 2022-7-6 16:02:48

李,
 
使用(ssadd)怎么样-大卫
 

Lee Mac 发表于 2022-7-6 16:05:59

谢谢David的建议,这肯定会让事情更加简洁。
 
干杯
 
页: 1 [2]
查看完整版本: 数组实体集合