ksperopoulos 发表于 2022-7-6 10:46:11

重复上一个命令

我试图在lisp语言中重复大约3个命令,但我不确定如何做到这一点。是否像AutoCad帮助文件中所示那样简单?
 

(repeat # [command])

alanjt 发表于 2022-7-6 10:53:34

根据你提供的信息,是的。
 
如。
(defun foo nil (entmakex (list '(0 . "LINE") '(10 0. 0. 0.) '(11 1. 1. 1.))))

(repeat 5 foo)

ksperopoulos 发表于 2022-7-6 10:54:24

我知道我遇到过这样一个问题:在图形中清除未使用的信息平均需要3次,然后这些信息才会消失。但我也注意到,当我试图清除Regapp时,也需要几次尝试才能将其全部删除。运行审核时也是如此。您是否遇到了同样的问题,或者有没有更简单的方法来清除图形文件中不需要的“垃圾”?

alanjt 发表于 2022-7-6 10:59:17

我有一个简单的程序,一次运行三次。

ksperopoulos 发表于 2022-7-6 11:02:17

这就是我刚刚做的。。。清除REGAPP、全部清除和审核3次。再次感谢您的帮助!也许有一天我会得到这些东西。

ksperopoulos 发表于 2022-7-6 11:07:48

为什么当我运行这个lisp时,它不会像我手动输入命令时那样输出所有内容?
 

(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar 'cmdecho 0)(repeat 3 (command "-purge" "r" "" "n")
    (command "audit" "y")
    (command "-purge" "a" "*" "n"))
;;; Zoom extents
    (command "zoom" "e")(setvar 'cmdecho 1)(princ))

The Buzzard 发表于 2022-7-6 11:11:36

我试过几次,见下文:
 
(defun c:scrubdwg2 ()
(setvar "cmdecho" 0)
(command "._-layer" "_s" "0" "")
(repeat 3
   (command "._-purge" "_r" "" "_n")
   (command "._audit" "_y")
   (command "._-purge" "_a" "*" "_n")
)
(command "._zoom" "_e")
(setvar "cmdecho" 1)
(princ))
 
已找到主要内容。
我将层设置为0,以防移除的对象的层设置为当前。
如果将0以外的图层设置为当前图层,并且该图层上没有实体,则无法清除该图层。
 
只是我发现了一些额外的东西。
在“cmdecho”周围添加了引号。
如果要使用命令调用,请将命令设置为语言兼容性。这是一个国际网站。
 
值得一提的是,由于没有regapps命令,这在一些旧版本的CAD上不起作用。

Tharwat 发表于 2022-7-6 11:14:40

你好
 
也可以使用以下功能设置特定层电流;
(setvar "clayer" "0")

或者这是为了回忆当时所在的同一层。

(setq lay(getvar "clayer"))
(setvar "clayer" "0")

; your codes are running here

(setvar "clayer" lay)

 
只是为了更多的想法。
当做
塔瓦特

ksperopoulos 发表于 2022-7-6 11:20:42

我想我已经采纳了你们的建议。这是我到目前为止得到的。当我手动运行审计时,仍然会出现很多错误,即使lisp应该审计图形文件3次。
 

(defun c:scrubdwg (/ *error* uFlag)
    (vl-load-com)

    (defun *error* (msg)
    (and uFlag (vla-EndUndoMark *doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
    (princ (strcat "\n** Error: " msg " **")))
    (princ))
    (setq *doc (cond (*doc)((vla-get-ActiveDocument
    (vlax-get-acad-object)))))
;;; Set UCS to world
    (setvar "cmdecho" 0)(command "._ucsfollow" "1")
    (command "._ucs" "_w")(command "._ucsfollow" "0")
;;; Detach all xrefs
    (command "._-xref" "_D" "*")
;;; Delete all layout tabs
    (vlax-for lay(vla-get-layouts *doc)
    (if (not (eq "MODEL" (strcase (vla-get-Name lay))))
    (vla-delete lay)))
;;; Changes all layers to thaw, on, unlock, and .25mm lineweight. Set current layer to 0.
    (command "._-layer" "_t" "*" "_on" "*" "_u" "*" "_s" "0" "_lw" "0.25" "*" "")
;;; Delete all layer filters
    (vl-catch-all-apply
    '(lambda ()
    (vla-remove
    (vla-getextensiondictionary
    (vla-get-layers
    (vla-get-activedocument (vlax-get-acad-object))
   ) ;_ end of vla-Get-Layers
   ) ;_ end of vla-GetExtensionDictionary
    "AcLyDictionary"
   ) ;_ end of vla-Remove
   ) ;_ end of lambda
   ) ;_ end of vl-Catch-All-Apply
;;; Delete all layer states
    (if (setq states (layerstate-getnames t t))
    (mapcar (function layerstate-delete) states))
;;; Delete all named views
    (command "._-view" "_s" "junk")(command "._-view" "_d" "*")
;;; Set insertion basepoint to 0,0,0
    (command "._insbase" "0,0,0")
;;; Set overall, modelspace, and paperspace linetype scales to 1
    (command "._ltscale" 1)(command "._msltscale" 1)(command "._psltscale" 1)
;;; Set annotation scale to 1/4" = 1'-0"
    (command "._cannoscale" "1/4\042 = 1'-0\042")
;;; Delete unused scales
    (command "._-scalelistedit" "_d" "*" "_e")
;;; Delete all dimensions
    (if (setq ss (ssget "_x" (list (cons 0 "*dimension"))))
      (command "_erase" ss "")
    )
;;; Set all object colors to bylayer
    (command "._setbylayermode" "1")
    (command "._setbylayer" "_all" "" "_y" "_y")
;;; Erase x data
    (command "._erase" (ssget"x") "r")(setvar 'cmdecho 1)(princ))
;---------------------------------------------------------------------------------------------------------
(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar "cmdecho" 0)
    (command "._-layer" "_s" "0" "")
    (repeat 3
       (command "._-purge" "_r" "" "_n")
       (command "._audit" "_y")
       (command "._-purge" "_a" "*" "_n")
    )
;;; Zoom extents
    (command "._zoom" "_e")
    (setvar "cmdecho" 1)
    (princ))

The Buzzard 发表于 2022-7-6 11:26:00

哇!你接到了很多命令电话。我很感激你诚实的尝试,但这个过程只会让人头疼。下面是我认为是由ASMI或Jeepmaster完成的代码,它将执行绑定、清除和审计。我将文件重命名为BPA。它工作得很好。试试看,让我们知道你的想法。我将这段代码与Lees脚本编写程序一起用于多个图形,这是一个多么节省时间的程序。如果有什么问题的话,这里可能有你的答案。注意,此代码使用系统变量bindtype。
 
以下是供您参考的帖子:http://www.cadtutor.net/forum/showthread.php?t=13141&highlight=BIND+清除+审核
 
(defun c:BPA (/ *error* oldBnType)

(vl-load-com)
(defun *error*(msg)
   (setvar "modemacro" ".")
   (setvar "bindtype" oldBnType)
   (setvar "cmdecho" 1)
   (princ "\nDetach/Audit/Bind/PurgeAll terminated")
   (princ)
   ); end of *error*

(setq oldBnType(getvar "bindtype"))
(setvar "modemacro" "Detach/Audit/Bind/PurgeAll processing......please wait......")
(prompt "\n---Detach unloaded Xref, Audit, Bind, PurgeAll---")
(prompt "\nDetaching...")
(vlax-for block (vla-get-blocks
   (vla-get-activedocument
   (vlax-get-acad-object)))
   (if (and (= :vlax-true (vla-get-isxref block))
   (= 0 (vla-get-count block))
       )
   (vla-detach block)
   )
)
(setvar "cmdecho" 0)
(prompt "...done")
(prompt "\nAuditing...")(terpri)
(command "_audit" "y")
(prompt "\nBinding all Xrefs...")
(setvar "bindtype" 1)
(command "-xref" "b" "*")
(prompt "...done")(terpri)
(prompt "\nPurging #1")(terpri)
(command "-purge" "a" "*" "N")
(prompt "\nPurging #2")(terpri)
(command "-purge" "a" "*" "N")
(prompt "\nPurging #3")(terpri)
(command "-purge" "a" "*" "N")
(prompt "\n---Detach, Audit, Bind, PurgeAll completed!---")
(setvar "modemacro" ".")
(setvar "cmdecho" 1)
(princ)
); end of c:BPA
(princ "\nBind, Purge & Audit Lisp loaded! Type BPA to start program.")
页: [1] 2
查看完整版本: 重复上一个命令