乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 29|回复: 15

[编程交流] 重复上一个命令

[复制链接]

55

主题

325

帖子

274

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
280
发表于 2022-7-6 10:46:11 | 显示全部楼层 |阅读模式
我试图在lisp语言中重复大约3个命令,但我不确定如何做到这一点。是否像AutoCad帮助文件中所示那样简单?
 
  1. (repeat [color=red]#[/color] [color=red][color=black][[/color]command[/color][color=black]])[/color]
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 10:53:34 | 显示全部楼层
根据你提供的信息,是的。
 
如。
  1. (defun foo nil (entmakex (list '(0 . "LINE") '(10 0. 0. 0.) '(11 1. 1. 1.))))
  2. (repeat 5 foo)
回复

使用道具 举报

55

主题

325

帖子

274

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

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

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 10:59:17 | 显示全部楼层
我有一个简单的程序,一次运行三次。
回复

使用道具 举报

55

主题

325

帖子

274

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
280
发表于 2022-7-6 11:02:17 | 显示全部楼层
这就是我刚刚做的。。。清除REGAPP、全部清除和审核3次。再次感谢您的帮助!也许有一天我会得到这些东西。
回复

使用道具 举报

55

主题

325

帖子

274

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
280
发表于 2022-7-6 11:07:48 | 显示全部楼层
为什么当我运行这个lisp时,它不会像我手动输入命令时那样输出所有内容?
 
  1. (defun c:scrubdwg2 ()
  2. ;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
  3.     (setvar 'cmdecho 0)(repeat 3 (command "-purge" "r" "" "n")
  4.     (command "audit" "y")
  5.     (command "-purge" "a" "*" "n"))
  6. ;;; Zoom extents
  7.     (command "zoom" "e")(setvar 'cmdecho 1)(princ))
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:11:36 | 显示全部楼层
我试过几次,见下文:
 
  1. (defun c:scrubdwg2 ()
  2. (setvar [color="Red"]"[/color]cmdecho[color="red"]"[/color] 0)
  3. [color="red"](command "._-layer" "_s" "0" "")[/color]
  4. (repeat 3
  5.    (command "[color="red"]._[/color]-purge" "[color="red"]_[/color]r" "" "[color="red"]_[/color]n")
  6.    (command "[color="red"]._[/color]audit" "[color="red"]_[/color]y")
  7.    (command "[color="red"]._[/color]-purge" "[color="red"]_[/color]a" "*" "[color="red"]_[/color]n")
  8. )
  9. (command "[color="Red"]._[/color]zoom" "[color="red"]_[/color]e")
  10. (setvar [color="red"]"[/color]cmdecho[color="red"]"[/color] 1)
  11. (princ))

 
已找到主要内容。
我将层设置为0,以防移除的对象的层设置为当前。
如果将0以外的图层设置为当前图层,并且该图层上没有实体,则无法清除该图层。
 
只是我发现了一些额外的东西。
在“cmdecho”周围添加了引号。
如果要使用命令调用,请将命令设置为语言兼容性。这是一个国际网站。
 
值得一提的是,由于没有regapps命令,这在一些旧版本的CAD上不起作用。
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 11:14:40 | 显示全部楼层
你好
 
也可以使用以下功能设置特定层电流;
  1. (setvar "clayer" "0")

或者这是为了回忆当时所在的同一层。
  1. (setq lay(getvar "clayer"))
  2. (setvar "clayer" "0")
  3. ; your codes are running here
  4. (setvar "clayer" lay)

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

使用道具 举报

55

主题

325

帖子

274

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
280
发表于 2022-7-6 11:20:42 | 显示全部楼层
我想我已经采纳了你们的建议。这是我到目前为止得到的。当我手动运行审计时,仍然会出现很多错误,即使lisp应该审计图形文件3次。
 
  1. (defun c:scrubdwg (/ *error* uFlag)
  2.     (vl-load-com)
  3.     (defun *error* (msg)
  4.     (and uFlag (vla-EndUndoMark *doc))
  5.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  6.     (princ (strcat "\n** Error: " msg " **")))
  7.     (princ))
  8.     (setq *doc (cond (*doc)((vla-get-ActiveDocument
  9.     (vlax-get-acad-object)))))
  10. ;;; Set UCS to world
  11.     (setvar "cmdecho" 0)(command "._ucsfollow" "1")
  12.     (command "._ucs" "_w")(command "._ucsfollow" "0")
  13. ;;; Detach all xrefs
  14.     (command "._-xref" "_D" "*")
  15. ;;; Delete all layout tabs
  16.     (vlax-for lay  (vla-get-layouts *doc)
  17.     (if (not (eq "MODEL" (strcase (vla-get-Name lay))))
  18.     (vla-delete lay)))
  19. ;;; Changes all layers to thaw, on, unlock, and .25mm lineweight. Set current layer to 0.
  20.     (command "._-layer" "_t" "*" "_on" "*" "_u" "*" "_s" "0" "_lw" "0.25" "*" "")
  21. ;;; Delete all layer filters
  22.     (vl-catch-all-apply
  23.     '(lambda ()
  24.     (vla-remove
  25.     (vla-getextensiondictionary
  26.     (vla-get-layers
  27.     (vla-get-activedocument (vlax-get-acad-object))
  28.      ) ;_ end of vla-Get-Layers
  29.      ) ;_ end of vla-GetExtensionDictionary
  30.     "AcLyDictionary"
  31.      ) ;_ end of vla-Remove
  32.      ) ;_ end of lambda
  33.      ) ;_ end of vl-Catch-All-Apply
  34. ;;; Delete all layer states
  35.     (if (setq states (layerstate-getnames t t))
  36.     (mapcar (function layerstate-delete) states))
  37. ;;; Delete all named views
  38.     (command "._-view" "_s" "junk")(command "._-view" "_d" "*")
  39. ;;; Set insertion basepoint to 0,0,0
  40.     (command "._insbase" "0,0,0")
  41. ;;; Set overall, modelspace, and paperspace linetype scales to 1
  42.     (command "._ltscale" 1)(command "._msltscale" 1)(command "._psltscale" 1)
  43. ;;; Set annotation scale to 1/4" = 1'-0"
  44.     (command "._cannoscale" "1/4\042 = 1'-0\042")
  45. ;;; Delete unused scales
  46.     (command "._-scalelistedit" "_d" "*" "_e")
  47. ;;; Delete all dimensions
  48.     (if (setq ss (ssget "_x" (list (cons 0 "*dimension"))))
  49.         (command "_erase" ss "")
  50.     )
  51. ;;; Set all object colors to bylayer
  52.     (command "._setbylayermode" "1")
  53.     (command "._setbylayer" "_all" "" "_y" "_y")
  54. ;;; Erase x data
  55.     (command "._erase" (ssget"x") "r")(setvar 'cmdecho 1)(princ))
  56. ;---------------------------------------------------------------------------------------------------------
  57. (defun c:scrubdwg2 ()
  58. ;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
  59.     (setvar "cmdecho" 0)
  60.     (command "._-layer" "_s" "0" "")
  61.     (repeat 3
  62.        (command "._-purge" "_r" "" "_n")
  63.        (command "._audit" "_y")
  64.        (command "._-purge" "_a" "*" "_n")
  65.     )
  66. ;;; Zoom extents
  67.     (command "._zoom" "_e")
  68.     (setvar "cmdecho" 1)
  69.     (princ))
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:26:00 | 显示全部楼层
哇!你接到了很多命令电话。我很感激你诚实的尝试,但这个过程只会让人头疼。下面是我认为是由ASMI或Jeepmaster完成的代码,它将执行绑定、清除和审计。我将文件重命名为BPA。它工作得很好。试试看,让我们知道你的想法。我将这段代码与Lees脚本编写程序一起用于多个图形,这是一个多么节省时间的程序。如果有什么问题的话,这里可能有你的答案。注意,此代码使用系统变量bindtype。
 
以下是供您参考的帖子:http://www.cadtutor.net/forum/showthread.php?t=13141&highlight=BIND+清除+审核
 
  1. (defun c:BPA (/ *error* oldBnType)
  2. (vl-load-com)
  3. (defun *error*(msg)
  4.    (setvar "modemacro" ".")
  5.    (setvar "bindtype" oldBnType)
  6.    (setvar "cmdecho" 1)
  7.    (princ "\nDetach/Audit/Bind/PurgeAll terminated  ")
  8.    (princ)
  9.    ); end of *error*
  10. (setq oldBnType(getvar "bindtype"))
  11. (setvar "modemacro" "Detach/Audit/Bind/PurgeAll processing......please wait......")
  12. (prompt "\n---Detach unloaded Xref, Audit, Bind, PurgeAll---")
  13. (prompt "\nDetaching...")
  14. (vlax-for block (vla-get-blocks
  15.    (vla-get-activedocument
  16.    (vlax-get-acad-object)))
  17.      (if (and (= :vlax-true (vla-get-isxref block))
  18.      (= 0 (vla-get-count block))
  19.        )
  20.      (vla-detach block)
  21.      )
  22. )
  23. (setvar "cmdecho" 0)
  24. (prompt "...done")
  25. (prompt "\nAuditing...")(terpri)
  26. (command "_audit" "y")
  27. (prompt "\nBinding all Xrefs...")
  28. (setvar "bindtype" 1)
  29. (command "-xref" "b" "*")
  30. (prompt "...done")(terpri)
  31. (prompt "\nPurging #1")(terpri)
  32. (command "-purge" "a" "*" "N")
  33. (prompt "\nPurging #2")(terpri)
  34. (command "-purge" "a" "*" "N")
  35. (prompt "\nPurging #3")(terpri)
  36. (command "-purge" "a" "*" "N")
  37. (prompt "\n---Detach, Audit, Bind, PurgeAll completed!---")
  38. (setvar "modemacro" ".")
  39. (setvar "cmdecho" 1)
  40. (princ)
  41. ); end of c:BPA
  42. (princ "\nBind, Purge & Audit Lisp loaded! Type BPA to start program.")
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 17:01 , Processed in 0.477001 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表