本帖最后由 yjtdkj 于 2021-8-5 14:59 编辑
先上原帖地址https://www.theswamp.org/index.php?topic=49214.msg543280#msg543280
打不开地址的话,就看下面的代码(08.05更新,原代码有个小错误,少了330组码)- ;; Group Entities - Lee Mac;; Creates a Group with a given name containing all entities in the supplied list
- ;; grp - [str] Group name (use "*" for an anonymous group)
- ;; lst - [lst] List of entities to add to group
- ;; sel - [bol] If T, group is selectable
- (defun LM:groupentities ( grp lst sel / dic enx gde gdx tmp )
- (if (setq dic (cdr (assoc -1 (dictsearch (namedobjdict) "acad_group"))))
- (if (setq gdx (dictsearch dic grp)
- gde (cdr (assoc -1 gdx))
- )
- (progn
- (entmod (append gdx (mapcar '(lambda ( x ) (cons 340 x)) lst)))
- (foreach ent lst
- (setq enx (entget ent)
- tmp (member '(102 . "{ACAD_REACTORS") enx)
- )
- (if tmp
- (setq tmp
- (vl-list*
- (car tmp)
- (cons 330 gde)
- (cdr tmp)
- )
- )
- (setq tmp
- (vl-list*
- '(102 . "{ACAD_REACTORS")
- (cons 330 gde)
- '(102 . "}")
- (cdr (member (assoc 5 enx) enx))
- )
- )
- )
- (entmod (append (reverse (member (assoc 5 enx) (reverse enx))) tmp))
- )
- grp
- )
- (if
- (and
- (setq gde
- (entmakex
- (list
- '(000 . "GROUP")
- '(102 . "{ACAD_REACTORS")
- (cons 330 dic)
- '(102 . "}")
- (cons 330 dic)
- '(100 . "AcDbGroup")
- (if (wcmatch grp "`*") '(070 . 1) '(070 . 0))
- (if sel '(071 . 1) '(071 . 0))
- )
- )
- )
- (if (wcmatch grp "`*")
- (if (entmod (append (entget dic) (list '(3 . "*") (cons 350 gde)))) ;; thanks vk/rjp
- (setq grp
- (cdadr
- (member
- (cons 350 gde)
- (reverse (entget dic))
- )
- )
- )
- )
- (dictadd dic grp gde)
- )
- )
- (LM:groupentities grp lst sel)
- )
- )
- )
- )
- (defun c:test ( / grp idx lst sel )
- (while
- (not
- (or (wcmatch (setq grp (getstring t "Specify group name: ")) "`*,")
- (snvalid grp)
- )
- )
- (princ "\nGroup name invalid.")
- )
- (if (and (/= "" grp) (setq sel (ssget )))
- (progn
- (repeat (setq idx (sslength sel))
- (setq lst (cons (ssname sel (setq idx (1- idx))) lst))
- )
- (LM:groupentities grp lst t)
- )
- )
- )
主要功能是创建组,但还有一些额外功能,如下:
1.如果已经存在同名的组,则以上将添加提供的实体到现有组。
2.以上将允许创建嵌套组 - 即包含已包含在其他组中的对象的组。
3.输入*号则可以创建匿名组
|