Anyone know of a way to group objects/blocks after they've been inserted?

Anyone know of a way to group objects/blocks after they've been inserted?

Anonymous
Not applicable
1,787 Views
3 Replies
Message 1 of 4

Anyone know of a way to group objects/blocks after they've been inserted?

Anonymous
Not applicable

I've written a small amount of code that allows me to insert a multi-line and then 2 blocks into my CAD however I'm now trying to work out how to group the three objects after they've been inserted automatically. Any help appreciated.

0 Likes
Accepted solutions (1)
1,788 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

You can start with the setting of a variable that holds an initially-empty selection set:

(setq ss (ssadd))

 

Then, after each element of the other stuff is drawn, do this to put it into the set:

 

(ssadd (entlast) ss)

 

That ss variable will then be a selection set with all those elements in it.  You can use ss for the selection in a Group [or Block?] command.

Kent Cooper, AIA
0 Likes
Message 3 of 4

Moshe-A
Mentor
Mentor

Daniel Hi,

 

post your code and sample dwg

 

moshe

 

0 Likes
Message 4 of 4

hak_vz
Advisor
Advisor

A make_group function to create group of objects from a selection set. It uses @Kent1Cooper 's random hex number generator for naming different groups (other simpler solutions are applicable). 

(defun make_group ( ss / )
(defun rnd (/ modulus multiplier increment random)
  (if (not seed)
    (setq seed (getvar "DATE"))
  )
  (setq modulus    65536
        multiplier 25173
        increment  13849
        seed  (rem (+ (* multiplier seed) increment) modulus)
        random     (/ seed modulus)
  )
)
;; int2hex.lsp
;; Base-10 Integer to Hexadecimal converter.
;; Accepts positive or negative integer argument, including 0.
;; Rejects non-integer argument with Alert.
;; Kent Cooper, January 2011

(defun int2hex (int / power neg int result div remain posval)
  (if (/= (type int) 'INT)
    (progn
      (alert "Requires integer argument.")
      (quit)
    ); end progn
  ); end if
  (setq
    power 1
    neg (minusp int)
    int (abs int)
    result ""
  ); end setq
  (while (> int 0)
    (setq
      div (expt 16 power)
      remain (rem int div)
      posval (/ remain (expt 16 (1- power))); POSition VALue
      int (- int remain)
      result
        (strcat
          (if (< posval 10)
            (itoa posval)
            (chr (+ 55 posval))
          ); end if
          result
        ); end strcat & result
      power (1+ power)
    ); end setq
  ); end while
  (strcat
    (if neg "-" "")
    (if (= result "") "0" result)
  ); end strcat
); end defun - int2hex

(defun randomhex () (int2hex(atoi(rtos (* (rnd) 1e7) 2 0))))
(setvar "cmdecho" 0)
(command "_.group" "c" (randomHEX) "group_desc" ss "")
(setvar "cmdecho" 1)
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes