乐筑天下

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

[编程交流] 组命令例程

[复制链接]

2

主题

7

帖子

5

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 09:29:25 | 显示全部楼层 |阅读模式
这是一个我一直在寻找很长时间。多年来,我们一直使用AutoCAD LT,然后转向了完整的AutoCAD。LT中的组命令远优于全自动CAD。只需单击一个按钮,拾取对象,然后对其进行分组。单击另一个按钮,它们将被取消分组。然后,使用“pickstyle”选项,您可以暂时挂起组进行编辑。这就是它在其他图形程序(例如CorelDraw、Illustrator、Xara等)中的工作原理。出现了一个对话框,这样我可以“命名”一个组,然后选择对象的整个想法似乎很疯狂。这真的打断了工作流程。如果我想那样做,我会制造障碍。
 
有没有人知道如何使用lisp或其他定制来实现这一点?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 09:36:04 | 显示全部楼层
也许使用匿名组?
 
  1. (defun c:grp ( / l )
  2. (vl-load-com)
  3. ;; © Lee Mac 2010
  4. (if (setq l (LM:SS->VLA (ssget)))
  5.    (vla-AppendItems
  6.      (vla-Add
  7.        (vla-get-Groups
  8.          (vla-get-ActiveDocument
  9.            (vlax-get-acad-object)
  10.          )
  11.        )
  12.        "*"
  13.      )
  14.      (LM:ObjectVariant l)
  15.    )
  16. )
  17. (princ)
  18. )
  19. ;;------------------=={ Safearray Variant }==-----------------;;
  20. ;;                                                            ;;
  21. ;;  Creates a populated Safearray Variant of a specified      ;;
  22. ;;  data type                                                 ;;
  23. ;;------------------------------------------------------------;;
  24. ;;  Author: Lee McDonnell, 2010                               ;;
  25. ;;                                                            ;;
  26. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  27. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  28. ;;------------------------------------------------------------;;
  29. ;;  Arguments:                                                ;;
  30. ;;  datatype - variant type enum (eg vlax-vbDouble)           ;;
  31. ;;  data     - list of static type data                       ;;
  32. ;;------------------------------------------------------------;;
  33. ;;  Returns:  VLA Variant Object of type specified            ;;
  34. ;;------------------------------------------------------------;;
  35. (defun LM:SafearrayVariant ( datatype data )
  36. ;; © Lee Mac 2010
  37. (vlax-make-variant
  38.    (vlax-safearray-fill
  39.      (vlax-make-safearray datatype
  40.        (cons 0 (1- (length data)))
  41.      )
  42.      data
  43.    )   
  44. )
  45. )
  46. ;;-------------------=={ Object Variant }==-------------------;;
  47. ;;                                                            ;;
  48. ;;  Creates a populated Object Variant                        ;;
  49. ;;------------------------------------------------------------;;
  50. ;;  Author: Lee McDonnell, 2010                               ;;
  51. ;;                                                            ;;
  52. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  53. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  54. ;;------------------------------------------------------------;;
  55. ;;  Arguments:                                                ;;
  56. ;;  lst - list of VLA Objects to populate the Variant.        ;;
  57. ;;------------------------------------------------------------;;
  58. ;;  Returns:  VLA Object Variant                              ;;
  59. ;;------------------------------------------------------------;;
  60. (defun LM:ObjectVariant ( lst )
  61. ;; © Lee Mac 2010
  62. (LM:SafearrayVariant vlax-vbobject lst)
  63. )
  64. ;;-----------------=={ SelectionSet -> VLA }==----------------;;
  65. ;;                                                            ;;
  66. ;;  Converts a SelectionSet to a list of VLA Objects          ;;
  67. ;;------------------------------------------------------------;;
  68. ;;  Author: Lee McDonnell, 2010                               ;;
  69. ;;                                                            ;;
  70. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  71. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  72. ;;------------------------------------------------------------;;
  73. ;;  Arguments:                                                ;;
  74. ;;  ss - Valid SelectionSet (Pickset)                         ;;
  75. ;;------------------------------------------------------------;;
  76. ;;  Returns:  List of VLA Objects                             ;;
  77. ;;------------------------------------------------------------;;
  78. (defun LM:ss->vla ( ss )
  79. ;; © Lee Mac 2010
  80. (if ss
  81.    (
  82.      (lambda ( i / e l )
  83.        (while (setq e (ssname ss (setq i (1+ i))))
  84.          (setq l (cons (vlax-ename->vla-object e) l))
  85.        )
  86.        l
  87.      )
  88.      -1
  89.    )
  90. )
  91. )
回复

使用道具 举报

13

主题

146

帖子

136

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
62
发表于 2022-7-6 09:40:36 | 显示全部楼层
这一个是匿名块。
我不是这个节目的作者。
我在网上搜索时找到了它,效果很好。
 
史蒂夫J
 
  1. (princ "\n This code is provided Unscramnbled - for free - given that it is not altered")
  2. (princ "\n Thanks for your understanding, www.xordesign.com ")
  3. (princ "\n Type TBLOCK to start ")
  4. (defun c:TBLOCK (/ sset tell ent ent_get entu ent_getu blk)
  5.        (princ "\n Select objects to group into anonymous Block: ")
  6.        (setq sset (ssget))
  7.        (if sset (progn
  8.             (entmake (list
  9.                       '(0 . "BLOCK")
  10.                       '(2 . "*U")
  11.                       '(70 . 1)
  12.                       '(10  0.0 0.0 0.0)))
  13.             (setq tell 0)
  14.             (setq ent (ssname sset tell))
  15.             (while ent
  16.               (setq ent_get (entget ent))
  17.               (if (/= (cdr (assoc 0 ent_get)) "POLYLINE")(progn
  18.                      (setq ent_getu (cdr ent_get))
  19.                      (entdel ent)
  20.                      (entmake ent_getu))
  21.                   (progn
  22.                     (setq entu ent
  23.                           ent_getu (cdr ent_get))
  24.                     (while (/= (cdr (assoc 0 ent_getu)) "SEQEND")
  25.                      (setq ent_getu (cdr (entget entu)))
  26.                      (entmake ent_getu)
  27.                      (setq entu (entnext entu))
  28.                      );while
  29.                      (entdel ent)                  
  30.                   )
  31.               );if
  32.               (setq tell (+ tell 1))
  33.               (setq ent (ssname sset tell))
  34.             )      
  35.             (setq blk (entmake (list '(0 . "ENDBLK"))))
  36.             (entmake (list '(0 . "INSERT")
  37.                             (cons 2 blk)
  38.                             '(10 0.0 0.0 0.0)))  
  39.          );progn
  40.        );if
  41.      (princ "\n Anonymous block created. Explode to ungroup")
  42.        (princ)
  43. )                    
  44. (princ)

 
 
编辑:李。我一直在尝试你的匿名群组惯例,在我尝试引爆群组之前一切都很好。
不会爆炸。我想你应该知道。
再想一想,我现在可以和同事们玩得无穷无尽了。
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 09:40:51 | 显示全部楼层
这为您提供了匿名或命名块以及基点输入的选项:
  1. ;=======================================================================
  2. ;    GroupNew.Lsp                                    Jan 03, 2008
  3. ;    New Group Into Block Anon or Named
  4. ;================== Start Program ======================================
  5. (princ "\nCopyright (C) 1990-2008, Fabricated Designs, Inc.")
  6. (princ "\nLoading GroupNew v1.0 ")
  7. (setq gra_ nil lsp_file "GroupNew")
  8. ;================== Macros =============================================
  9. (defun PDot ()(princ "."))
  10. (PDot);++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
  11. (defun gra_smd ()
  12. (SetUndo)
  13. (setq oldlay (getvar "CLAYER")
  14.       olderr *error*
  15.      *error* (lambda (e)
  16.                (while (> (getvar "CMDACTIVE") 0)
  17.                       (command))
  18.                (and (/= e "quit / exit abort")
  19.                     (princ (strcat "\nError: *** " e " *** ")))
  20.                (and (= (logand (getvar "UNDOCTL")  8)
  21.                     (command "_.UNDO" "_END" "_.U"))
  22.                (gra_rmd))
  23.       gra_var '(("CMDECHO"   . 0) ("MENUECHO"   . 0)
  24.                ("MENUCTL"   . 0) ("MACROTRACE" . 0)
  25.                ("OSMODE"    . 0) ("SORTENTS"   . 119)
  26.                ("LUPREC"    . 2) ("MODEMACRO" . ".")
  27.                ("BLIPMODE"  . 0) ("EXPERT"     . 0)
  28.                ("SNAPMODE"  . 1) ("PLINEWID"   . 0)
  29.                ("ORTHOMODE" . 1) ("GRIDMODE"   . 0)
  30.                ("ELEVATION" . 0) ("THICKNESS"  . 0)
  31.                ("FILEDIA"   . 0) ("FILLMODE"   . 0)
  32.                ("SPLFRAME"  . 0) ("UNITMODE"   . 0)
  33.                ("TEXTEVAL"  . 0) ("ATTDIA"     . 0)
  34.                ("AFLAGS"    . 0) ("ATTREQ"     . 1)
  35.                ("ATTMODE"   . 1) ("UCSICON"    . 1)
  36.                ("HIGHLIGHT" . 1) ("REGENMODE"  . 1)
  37.                ("COORDS"    . 2) ("DRAGMODE"   . 2)
  38.                ("DIMZIN"    . 1) ("PDMODE"     . 0)
  39.                ("CECOLOR"   . "BYLAYER")
  40.                ("CELTYPE"   . "BYLAYER")))
  41. (foreach v gra_var
  42.   (and (getvar (car v))
  43.        (setq gra_rst (cons (cons (car v) (getvar (car v))) gra_rst))
  44.        (setvar (car v) (cdr v))))
  45. (princ (strcat (getvar "PLATFORM") " Release " (ver)))
  46. (princ))
  47. (PDot);++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
  48. (defun gra_rmd ()
  49. (SetLayer oldlay)
  50. (setq *error* olderr)
  51. (foreach v gra_rst (setvar (car v) (cdr v)))
  52. (command "_.UNDO" "_END")
  53. (prin1))
  54. (PDot);++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
  55. (defun SetUndo ()
  56. (and (zerop (getvar "UNDOCTL"))
  57.      (command "_.UNDO" "_ALL"))
  58. (and (= (logand (getvar "UNDOCTL") 2) 2)
  59.      (command "_.UNDO" "_CONTROL" "_ALL"))
  60. (and (= (logand (getvar "UNDOCTL")  8)
  61.      (command "_.UNDO" "_END"))
  62. (command "_.UNDO" "_GROUP"))
  63. (PDot);++++++++++++ Make Layer Current +++++++++++++++++++++++++++++++++
  64. (defun SetLayer (name / ldef flag)
  65. (cond ((or (not name)
  66.             (not (snvalid name)))
  67.         (princ "\nBad Aurgment Passed To SetLayer - ")
  68.         (prin1 name)
  69.         (exit)))
  70. (command "_.LAYER")
  71. (if (not (tblsearch "LAYER" name))
  72.      (command "_Make" name)
  73.      (progn
  74.        (setq ldef (tblsearch "LAYER" name)
  75.              flag (cdr (assoc 70 ldef)))
  76.        (and (= (logand flag  1)  1)
  77.             (command "_Thaw" name))
  78.        (and (minusp (cdr (assoc 62 ldef)))
  79.             (command "_On" name))
  80.        (and (= (logand flag  4)  4)
  81.             (command "_Unlock" name))
  82.        (and (= (logand flag 16) 16)
  83.             (princ "\nCannot Set To XRef Dependent Layer")
  84.             (quit))
  85.        (command "_Set" name)))
  86. (command "")
  87. name)
  88. (PDot);************ Main Program ***************************************
  89. (defun gra_ (/ olderr oldlay gra_var gra_rst
  90.             bt ss i en ed pt sn sd)
  91. (gra_smd)
  92. (initget "Named Anonymous")
  93. (setq bt (getkword "\nBlock Type - Named/Anonymous <A>:   "))
  94. (if (not bt)
  95.      (setq bt "Anonymous")
  96.      (progn
  97.        (setq bn "TEMP1" bc 1)
  98.        (while (tblsearch "BLOCK" bn)
  99.               (setq bc (1+ bc) bn (strcat "TEMP" (itoa bc))))))
  100. (command "_.SNAP" 1.00)
  101. (initget 1)
  102. (setq pt (getpoint "\nSpecify Base Point: "))
  103. (princ "\nSelect Entities To Block:   ")
  104. (and (setq i -1
  105.            ss (ssget '((0 . "~VIEWPORT"))))
  106.       (entmake (list (cons 0 "BLOCK")
  107.                      (cons 2 (if (= bt "Named") bn "*U"))
  108.                      (cons 10 pt)
  109.                      (cons 70 (if (= bt "Named") 0 1))))
  110.       (while (setq en (ssname ss (setq i (1+ i))))
  111.             (setq ed (entget en))
  112.             (entmake ed)
  113.             (and (= 1 (cdr (assoc 66 ed)))
  114.                  (setq sn en)
  115.                  (while (/= "SEQEND" (cdr (assoc 0 (entget (entnext sn)))))
  116.                         (setq sn (entnext sn)
  117.                               sd (entget sn))
  118.                         (entmake sd))
  119.                  (entmake (entget (entnext sn))))
  120.             (entdel en))
  121.       (setq in (entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))
  122.       (entmake (list (cons 0 "INSERT")(cons 2 in)(cons 8 "0")
  123.                      (cons 10 pt))))
  124. (gra_rmd))
  125. (PDot);************ Load Program ***************************************
  126. (defun C:GroupNew () (gra_))
  127. (if gra_ (princ "\nGroupNew Loaded\n"))
  128. (prin1)
  129. ;|================== End Program =======================================

 
-大卫
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 09:47:34 | 显示全部楼层
 
我以为这是群体的惯常行为,不是吗?
 
您应该能够通过“组”对话框分解组
回复

使用道具 举报

13

主题

146

帖子

136

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
62
发表于 2022-7-6 09:49:59 | 显示全部楼层
 
好吧,我会被浸泡!当然,你是对的。
我已经很久没有和组一起工作了,我试着用explode命令将它们解组。我真傻。
 
史蒂夫J
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 09:54:56 | 显示全部楼层
 
不用担心SteveJ-直觉上,使用explode命令是有意义的。。。
回复

使用道具 举报

2

主题

7

帖子

5

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 09:58:07 | 显示全部楼层
李,
这真的很有效。这正是我想要的。我想我唯一的问题是。。。有没有可能也解散这些团体?
换句话说。键入grp,然后选择要分组的实体,它将创建组。然后键入ugrp并选择要溶解的组。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:02:21 | 显示全部楼层
 
我不怎么操纵组对象,但可能是这样的?
 
  1. (defun c:grp ( / l )
  2. (vl-load-com)
  3. ;; © Lee Mac 2010
  4. (or *doc (setq *doc (vla-get-ActiveDocument (vlax-get-acad-object))))
  5. (if (setq l (LM:SS->VLA (ssget)))
  6.    (vla-AppendItems
  7.      (vla-Add (vla-get-Groups *doc) "*")
  8.      (LM:ObjectVariant l)
  9.    )
  10. )
  11. (princ)
  12. )
  13. (defun c:ugrp ( / group g h lst )
  14. (vl-load-com)
  15. ;; © Lee Mac 2010
  16. (or *doc (setq *doc (vla-get-ActiveDocument (vlax-get-acad-object))))
  17. (vlax-for group (vla-get-Groups *doc)
  18.    (vlax-for object group
  19.      (setq g (cons (vla-get-Handle object) g))
  20.    )
  21.    (setq lst (cons (cons group g) lst) g nil)
  22. )
  23. (if lst
  24.    (while
  25.      (progn
  26.        (setq e (car (entsel "\nSelect Object to Remove Grouping: ")))
  27.        (cond
  28.          (
  29.            (eq 'ENAME (type e)) (setq h (vla-get-Handle (vlax-ename->vla-object e)))
  30.            (if
  31.              (setq group
  32.                (vl-some
  33.                  (function
  34.                    (lambda ( g )
  35.                      (if (vl-position h (cdr g)) g)
  36.                    )
  37.                  )
  38.                  lst
  39.                )
  40.              )
  41.              (progn
  42.                (vla-delete (car group))
  43.                (setq lst (vl-remove group lst))
  44.                (princ "\n** Group Deleted **")
  45.              )
  46.              (princ "\n** Object is not a member of a group **")
  47.            )
  48.          )
  49.        )
  50.      )
  51.    )
  52.    (princ "\n** No Groups in Drawing **")
  53. )
  54. (princ)
  55. )  
  56. ;;------------------=={ Safearray Variant }==-----------------;;
  57. ;;                                                            ;;
  58. ;;  Creates a populated Safearray Variant of a specified      ;;
  59. ;;  data type                                                 ;;
  60. ;;------------------------------------------------------------;;
  61. ;;  Author: Lee McDonnell, 2010                               ;;
  62. ;;                                                            ;;
  63. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  64. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  65. ;;------------------------------------------------------------;;
  66. ;;  Arguments:                                                ;;
  67. ;;  datatype - variant type enum (eg vlax-vbDouble)           ;;
  68. ;;  data     - list of static type data                       ;;
  69. ;;------------------------------------------------------------;;
  70. ;;  Returns:  VLA Variant Object of type specified            ;;
  71. ;;------------------------------------------------------------;;
  72. (defun LM:SafearrayVariant ( datatype data )
  73. ;; © Lee Mac 2010
  74. (vlax-make-variant
  75.    (vlax-safearray-fill
  76.      (vlax-make-safearray datatype
  77.        (cons 0 (1- (length data)))
  78.      )
  79.      data
  80.    )   
  81. )
  82. )
  83. ;;-------------------=={ Object Variant }==-------------------;;
  84. ;;                                                            ;;
  85. ;;  Creates a populated Object Variant                        ;;
  86. ;;------------------------------------------------------------;;
  87. ;;  Author: Lee McDonnell, 2010                               ;;
  88. ;;                                                            ;;
  89. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  90. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  91. ;;------------------------------------------------------------;;
  92. ;;  Arguments:                                                ;;
  93. ;;  lst - list of VLA Objects to populate the Variant.        ;;
  94. ;;------------------------------------------------------------;;
  95. ;;  Returns:  VLA Object Variant                              ;;
  96. ;;------------------------------------------------------------;;
  97. (defun LM:ObjectVariant ( lst )
  98. ;; © Lee Mac 2010
  99. (LM:SafearrayVariant vlax-vbobject lst)
  100. )
  101. ;;-----------------=={ SelectionSet -> VLA }==----------------;;
  102. ;;                                                            ;;
  103. ;;  Converts a SelectionSet to a list of VLA Objects          ;;
  104. ;;------------------------------------------------------------;;
  105. ;;  Author: Lee McDonnell, 2010                               ;;
  106. ;;                                                            ;;
  107. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  108. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  109. ;;------------------------------------------------------------;;
  110. ;;  Arguments:                                                ;;
  111. ;;  ss - Valid SelectionSet (Pickset)                         ;;
  112. ;;------------------------------------------------------------;;
  113. ;;  Returns:  List of VLA Objects                             ;;
  114. ;;------------------------------------------------------------;;
  115. (defun LM:ss->vla ( ss )
  116. ;; © Lee Mac 2010
  117. (if ss
  118.    (
  119.      (lambda ( i / e l )
  120.        (while (setq e (ssname ss (setq i (1+ i))))
  121.          (setq l (cons (vlax-ename->vla-object e) l))
  122.        )
  123.        l
  124.      )
  125.      -1
  126.    )
  127. )
  128. )
回复

使用道具 举报

2

主题

7

帖子

5

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 10:06:09 | 显示全部楼层
李,
 
很酷!!它工作得很好。非常感谢。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-7 03:07 , Processed in 0.370331 second(s), 72 queries .

© 2020-2025 乐筑天下

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