MarcoW 发表于 2022-7-6 11:20:14

请帮我解决这个“whil”

你好
 
只是为了学习过程,我想做一个块的选择集,然后“一个一个”地镜像每个块。因此,我需要用每个循环计算并减去1。。。
 
我怎么一个接一个地到达街区?
 
下面是我的代码,红色部分是怎么回事!
谢谢你的帮助。
 
附:例行公事并不特别,只是为了学习/了解。
 
 
(defun c:test (/)
(setq oldfiledia (getvar "filedia"))
(setvar "filedia" 0)
(prompt
   "\t« « You should now select one ore more blocks » »"
)
(if (setq ss (ssget '((0 . "INSERT"))))
   (progn (setq i (sslength ss))
          (while (not (minusp (setq i (1- i))))
            (setq blst (entget (ssname ss i))
                  mpt1 (getpoint "Mirrorline point 1")
                  mpt2 (getpoint "Mirrorline point 2")
            )
            (command "_.mirror" blst mpt1 mpt2)
          )
   )
   (princ "Nothing selected!!")
)
(setvar "filedia" oldfiledia)
(princ)
)
(princ)
;Code partial comes from "a lesson" LeeMac once taught me :-)
; I need to localize and make some error trap, I know...;-)

jammie 发表于 2022-7-6 11:26:39

嘿MarcoW
 
(setq blst (entget (ssname ss i))
 
重新运行elist,但mirror只接受一个ename或一个选择集
 
(setq blst (ssname ss i))
 
(command "_.mirror" blst "" mpt1 mpt2 ....

JohnM 发表于 2022-7-6 11:32:20

只是几个典型的新手错误,但这是一次很好的尝试(坚持下去)
有几种方法可以使用while循环,我所做的这一更正只是其中之一
 

(defun c:test (/)
(setq oldfiledia (getvar "filedia"))
(setvar "filedia" 0)
(prompt
   "\t« « You should now select one ore more blocks » »"
)
(if (setq ss (ssget '((0 . "INSERT"))))
   (progn (setq i (sslength ss))
      (setq cnt 0);_counter
          (while (< cnt i)   
            (setq blst (ssname ss cnt);_did not need entget this gets the entname
                  mpt1 (getpoint "Mirrorline point 1")
                  mpt2 (getpoint "Mirrorline point 2")
            )
   ;_added "" after blst to tell it no more abjects will be selected
   ;_added "no" to the question to delete source object
            (command "_.mirror" blst "" mpt1 mpt2 "no" "")
   (setq cnt (1+ cnt));_add 1 to the counter
          );_while
   )
   (princ "Nothing selected!!")
)
(setvar "filedia" oldfiledia)`
(princ)
)
(princ)

MarcoW 发表于 2022-7-6 11:41:41

谢谢你们,我会复制并粘贴到~Vlide~。我会回来问更多关于舒尔的问题!

alanjt 发表于 2022-7-6 11:46:03

只是一点编辑。。。
 
(defun c:Test (/ i ss mp1 mp2)
(if (setq i-1
         ss (ssget "_:L" '((0 . "INSERT")))
   )
   (while (setq e (ssname ss (setq i (1+ i))))
   (and (setq mp1 (getpoint "\nSpecify first mirror point: "))
          (setq mp2 (getpoint mp1 "\nSpecify next mirror point: "))
          (command "_.mirror" e "" "_non" mp1 "_non" mp2)
   )
   )
)
(princ)
)

MarcoW 发表于 2022-7-6 11:53:58

谢谢大家帮助我!很棒的学习。虽然我会保留一些问题,但当然!
 
首先:我的常规仍然失败。。。“要点必须明确”
我不知道,但我觉得这和“osnap”有关。转动它不起作用。就在我发布例程之前,我注意到了这一点(下面的红色部分):
 
 
这样的事情会引起那样的麻烦
嗯,Alanjt,谢谢你。
 
我所做的是创建一个例程来镜像我的块,然后再次镜像它们。如果你仔细想想,你会发现这并不是什么都没发生!!
 
这是我的例行公事,欢迎批评!我需要一些时间来创造这一点,我知道这是混乱的,而不是它应该是这样。像variablenames,他们呢?是不是太长了?
 
我使用了很多“老式”lisp(命令“_.mirror”…)。
这是一种避免的方法吗?它慢吗。。。?
 
正如所说:我已经准备好接受一些严肃的评论。
 
提前感谢!!
 

; double mirror function
; 21-10-2010 MarcoW
; great help ~ CADTutor ~
(defun c:test (/ mirrorlinepoint1 mirrorlinepoint2
            selectionset numberblocks counter
            blocklist ent entdata newinspt
            newrot newinspt2 rotdgr)

(setq mirrorlinepoint1 (getpoint "Mirrorline point 1")
       mirrorlinepoint2 (getpoint mirrorlinepoint1 "Mirrorline point 2")
)
(prompt
   "          « « You really should select one ore more blocks now...» »"
)
(if (setq selectionset (ssget '((0 . "INSERT"))))
   (progn (setq numberblocks (sslength selectionset))
          (setq counter 0)
          (while (< counter numberblocks)
            (setq blocklist (ssname selectionset counter))
            (command
            "_.mirror"
            blocklist
            ""
            mirrorlinepoint1
            mirrorlinepoint2
            "no"
            ""
            )
            (setq ent (entlast))
            (setq entdata (entget ent))
            (setq newinspt(cdr (assoc 10 entdata))
                  newrot    (cdr (assoc 50 entdata))
                  newinspt2 (polar newinspt (+ newrot pi) 50)
            )
            (setq rotdgr (/ (* newrot 180) pi))
            (command "_.mirror"
                     (entlast)
                     ""
                     "_NON"
                     newinspt
                     "_NON"
                     newinspt2
                     "Yes"
                     ""
            )
            (setq counter (1+ counter))
          )
   )
   (princ "Nothing selected!!")
)
(princ)
)
(princ)


 
编辑:我想知道,现在我过滤“插入”。因为其他东西,比如线条等,都不起作用。我需要如何处理它,以便我的例程(测试)为所有选定的块执行它的工作,而所有未选定的块都是“正常镜像的”。

alanjt 发表于 2022-7-6 12:02:13

很乐意帮忙。
我还想给大家展示一种更简单的方法来逐步通过选择集。

MarcoW 发表于 2022-7-6 12:02:25

是的,艾伦,你做到了,代码也短得多。
但我对我所取得的成就感到高兴:——)

alanjt 发表于 2022-7-6 12:13:45

 
你做这件事的方式没有错。我只是告诉你另一条路线。我希望你不要认为我说你的代码相比之下是垃圾,因为这正是我要说的眨眼:
 
只是开玩笑。

MarcoW 发表于 2022-7-6 12:16:27

 
好吧,Alanjt!!!
页: [1] 2
查看完整版本: 请帮我解决这个“whil”