Author Topic: catch the objects of an exploded group  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 725
catch the objects of an exploded group
« on: May 24, 2021, 03:12:29 AM »
I need to catch all the objects that were member of an exploded group . . .

Does somebody know a simple way to get this ?

(defun C:K ( / ent-lst x-el x-en)
   (setq x-el (LM:entlast (entlast) ) )
   (setq x-en (entsel "\nselect GROUP to EXPLODE :") )
   (vl-cmdf "ungroup" x-en)
   (setq ent-lst (LM:entnexttoend x-el) )
)

(setq ent-lst (LM:entnexttoend x-el) ) does not work !






Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: catch the objects of an exploded group
« Reply #1 on: May 24, 2021, 04:01:14 AM »
Ungrouping is not the same action as exploding - it does not add new entities to the drawing database; you should instead examine the members of the group prior to ungrouping.

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #2 on: May 24, 2021, 04:28:02 AM »
Quote
it does not add new entities to the drawing database
I supposed that . . .

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #3 on: May 24, 2021, 07:49:20 AM »
Quote
you should instead examine the members of the group prior to ungrouping.

Does somebody know a simple way to get this ?
"simple" means not elegant, but working:whistling:


tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: catch the objects of an exploded group
« Reply #4 on: May 24, 2021, 10:25:38 AM »
Why not as Lee sugusted use code like
Code: [Select]
(setq ss(ssget))
to select the group which puts all the group entities into a selection set?

Maybe if you posted what code you're working on someone here would offer a simple elegant solution.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #5 on: May 24, 2021, 11:08:13 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun :GROUP-GET-DATA (e / l r )
  2.    (if
  3.       (and
  4.          (setq l (entget e ) )
  5.          (setq r (assoc 330 l) )
  6.          (setq r (entget (cdr r) ) )
  7.          (= (cdr (assoc 0 r ) ) "GROUP")
  8.       )
  9.       r
  10.    )
  11. )
  12.  
  13.  
  14. (defun :M-ASSOC (code l)
  15.    (mapcar
  16.       (function cdr)
  17.       (vl-remove-if-not
  18.          (function (lambda (i / code)   (= (car i) code) ) )
  19.          l
  20.       )
  21.    )
  22. )
  23.  
  24. (defun c:XG ( / grp-data grp-ss x-en )
  25.    (and
  26.       (setq x-en (entsel "\nselect GROUP to EXPLODE :") )  
  27.       (setq grp-data (:GROUP-GET-DATA (car x-en) ) )
  28.       (setq grp-ss (ssadd) )
  29.       (foreach en (:M-ASSOC 340 grp-data)  (setq grp-ss (ssadd en grp-ss) ) )
  30.       (vl-cmdf "ungroup" (car x-en) )
  31.       (vl-cmdf "select" grp-ss "")
  32.    )
  33.    grp-ss
  34. )
  35.  

it seems to work . . .

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: catch the objects of an exploded group
« Reply #6 on: May 24, 2021, 01:21:21 PM »
Only an example from tombu suggestion:
Code: [Select]
(defun C:XG2 ( / SelSet)
   (princ "\nSelect GROUP to EXPLODE: ")
   (and
     (setq SelSet (ssget))
     (vl-cmdf "_.UNGROUP" (ssname SelSet 0))
     (vl-cmdf "_.SELECT" SelSet "")
   )
)

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #7 on: May 24, 2021, 02:31:50 PM »
Quote
(defun C:XG2 ( / SelSet)
   (princ "\nSelect GROUP to EXPLODE: ")
   (and
     (setq SelSet (ssget))
     (vl-cmdf "_.UNGROUP" (ssname SelSet 0))
     (vl-cmdf "_.SELECT" SelSet "")
   )
)
8-)
e si ...

ronjonp

  • Needs a day job
  • Posts: 7529
Re: catch the objects of an exploded group
« Reply #8 on: May 24, 2021, 04:27:56 PM »
Maybe this too:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ d e s)
  2.   (if (and (setq e (car (entsel)))
  3.            (setq d (cdr (assoc 330 (entget e))))
  4.            (= "GROUP" (cdr (assoc 0 (entget d))))
  5.       )
  6.     (progn (setq s (ssadd))
  7.            (foreach x (entget d) (and (= 340 (car x)) (setq s (ssadd (cdr x) s))))
  8.            (sssetfirst nil s)
  9.            (entdel d)
  10.     )
  11.   )
  12.   (princ)
  13. )
*localized 's'
« Last Edit: May 25, 2021, 10:36:23 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #9 on: May 25, 2021, 03:11:05 AM »
Maybe this too:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ d e)
  2.   (if (and (setq e (car (entsel)))
  3.            (setq d (cdr (assoc 330 (entget e))))
  4.            (= "GROUP" (cdr (assoc 0 (entget d))))
  5.       )
  6.     (progn (setq s (ssadd))
  7.            (foreach x (entget d) (and (= 340 (car x)) (setq s (ssadd (cdr x) s))))
  8.            (sssetfirst nil s)
  9.            (entdel d)
  10.     )
  11.   )
  12.   (princ)
  13. )

very nice and interesting !

« Last Edit: May 25, 2021, 03:16:15 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: catch the objects of an exploded group
« Reply #10 on: May 26, 2021, 10:24:51 AM »
ronjonp thank you.

Maybe for somebody it is obvious, but . . .
. . .
this means that
(entdel d)
deletes the group definition
but doesn't delete the entities contained in the group !

In other words, it explodes the group.

Right ?


ronjonp

  • Needs a day job
  • Posts: 7529
Re: catch the objects of an exploded group
« Reply #11 on: May 26, 2021, 11:20:48 PM »
ronjonp thank you.

Maybe for somebody it is obvious, but . . .
. . .
this means that
(entdel d)
deletes the group definition
but doesn't delete the entities contained in the group !

In other words, it explodes the group.

Right ?
Yes  :-) .. well it deletes the group the entities are contained in.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC