broncos15 发表于 2022-7-5 18:15:54

超级清除lisp只能这样工作

因此,我在编写lisp例程以清除绘图中的所有内容时遇到了问题。这个问题必须处理wblock命令。它似乎有一半的时间可以工作,而另一半的时间它在代码的Y部分出错,这让我感到困惑。我的代码如下
(defun c:superpurge (/ file path pathfile *error* oldecho olddia)
(vl-load-com)
(defun *error* (msg)   ;This defines the error function so that if something goes wrong, it exits quietly and resets the variables
   (if oldecho
   (setvar 'cmdecho oldecho)
   )
   (if olddia
   (setvar 'CMDDIA olddia)
   )
   (if (not
(member msg '("Function cancelled" "quit / exit abort"))
)
   (princ (strcat "\nError: " msg))
   )
   (princ)
)
(setq oldecho (getvar 'CMDECHO)) ;I am setting the variable oldecho equal to the variable cmdecho
(setvar "CMDECHO" 0)
(setq olddia (getvar 'CMDDIA))
(setvar "CMDDIA" 0)
(cond
   ((or (= (getvar 'writestat) 0) ;If the drawing is read only or hasn't ever been saved ie Drawing1, then it won't run
(= (getvar 'DWGTITLED) 0)
    )
    (alert
      "\n Superpurge cannot be used in files that haven't been named or are read only."
    )
   )
   (t   ;This is the "else" portion of the cond statement
    (setq file (getvar "DWGNAME")) ;This gets the drawing name
    (setq path (getvar "DWGPREFIX")) ;This gets the drawing's path
    (setq pathfile (strcat path file)) ;This combines the two variables into one
    (repeat 3
      (vl-cmdf "._AECCPURGESTYLES")
      (while (eq (logand (getvar "cmdactive") 1) 1)
(command "_Y")
      )
    )
    (command "._PURGE" "_A" "*" "_N")
    (command "._PURGE" "_R" "*" "_N")
    (command-s "-WBLOCK" pathfile "_Y" "*" "_Y")
    ;Here I am running wblock and saving over the current drawing
    (princ "\nYour drawing is now squeaky clean")
   )
)
(setvar "CMDECHO" oldecho);Resetting the variable cmdecho to its original value
(setvar "CMDDIA" olddia)
(princ)    ;Exit quietly
)

broncos15 发表于 2022-7-5 18:26:06

所以我一直在搞乱它,并阅读了代码无数次,我没有发现任何错误。似乎没有任何押韵或理由说明它何时起作用,何时不起作用,只是wblock命令不想总是起作用。我能想到的代码的唯一其他改进是将清除样式的重复函数更改为while not语句,当清除样式给出“没有未使用的样式”时停止有没有一种方法可以纠正while语句来实现这一点?我选择重复3次,只是因为我从未见过需要运行3次以上的场景,但如果没有必要,最好不要再次运行Aeccpurgestyles,因为这是代码中最慢的部分。

rlx 发表于 2022-7-5 18:40:52

不知道代码的其余部分,但我一直讨厌所有的命令echo,所以现在我使用
 
 
(defun LG_Purge () (vla-purgeall (vla-get-activeDocument (vlax-get-acad-object))))
 
 
你可以随时调用这个函数。
 
 
Gr.Rlx

Lee Mac 发表于 2022-7-5 18:55:21

请注意,此方法将忽略冗余的多重引线样式。

broncos15 发表于 2022-7-5 19:05:13

RLX,谢谢你的代码,这是绕过命令echo的一种有用方法(我觉得它们很讨厌)。Lee,那么代码是否遗漏了所有类型的样式,比如所有AECC样式(曲面样式、直线和曲线等),或者仅遗漏了多重引线样式?Lee,我试图为清除样式部分编写一个循环,但直到每个样式都像我希望的那样被清除,它才继续运行

rlx 发表于 2022-7-5 19:09:19

 
我以前用过
3
 
你可以搜索purger。lsp开启http://jtbworld.com/autocad-purger-lsp
 
gr.Rlx

Lee Mac 发表于 2022-7-5 19:18:59

 
恐怕我不能说——我没有使用垂直应用程序的经验。
页: [1]
查看完整版本: 超级清除lisp只能这样工作