Move Blocks to insertion point of another Block

Move Blocks to insertion point of another Block

Designer_1E
Enthusiast Enthusiast
1,877 Views
5 Replies
Message 1 of 6

Move Blocks to insertion point of another Block

Designer_1E
Enthusiast
Enthusiast

Hello,

 

Does anyone have a LISP that can move a selection of blocks so that they all meet together at their insertion points, or a given coordinate?

I am cleaning up my cooworkers drawings and they don't bother placing their blocks neatly.   For example: I've got 5 blocks in a cluster that should all be inserted at the same point, but they are scattered about.  I've got endless clusters to clean.

0 Likes
Accepted solutions (1)
1,878 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor

Try this

 

(rh:get_blks ( / ss)
  (prompt "\nSelect Blocks to align : ")
  (setq ss (ssget '((0 . "INSERT"))))
);end_defun

(defun c:ab ( / osm ss a_pt cnt ent i_pt)

  (setq osm (getvar 'osmode))
  
  (while (setq ss (rh:get_blks))
    (setvar 'osmode 64)
    (setq a_pt (getpoint "\nSelect Alignment Point : "))
    (repeat (setq cnt (sslength ss))
      (setq ent (ssname ss (setq cnt (1- cnt)))
            i_pt (cdr (assoc 10 (entget ent)))
      );end_setq
      (setvar 'osmode 0)
      (vl-cmdf "move" ent i_pt a_pt)
      (setvar 'osmode 64)
);end_repeat (setq ss nil)
(gc)
);end_while (setvar 'osmode osm) (princ) );end_defun

No error checking. Everything happens in a while loop, so you can process multiple groups without restarting the lisp. Too quit press return when asked to select blocks. Only select blocks in groups required.

 

OSMODE is set to (insertion) when asked to select the alignment point then off when the blocks are moved.

 

Its not ideal but should speed things up.

 

I am not one of the robots you're looking for

0 Likes
Message 3 of 6

dlanorh
Advisor
Advisor
Accepted solution

Sorry, code didn't update properly. Try This

 

(defun rh:get_blks ( / ss)
  (prompt "\nSelect Blocks to align : ")
  (setq ss (ssget '((0 . "INSERT"))))
);end_defun

(defun c:ab ( / osm ss a_pt cnt ent i_pt)

  (setq osm (getvar 'osmode))
  
  (while (setq ss (rh:get_blks))
    (setvar 'osmode 64)
    (setq a_pt (getpoint "\nSelect Alignment Point : "))
    (repeat (setq cnt (sslength ss))
      (setq ent (ssname ss (setq cnt (1- cnt)))
            i_pt (cdr (assoc 10 (entget ent)))
      );end_setq
      (setvar 'osmode 0)
      (vl-cmdf "move" ent "" i_pt a_pt)
      (setvar 'osmode 64)
    );end_repeat
    (setq ss nil)
    (gc)
  );end_while
  (setvar 'osmode osm)
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes
Message 4 of 6

Designer_1E
Enthusiast
Enthusiast

This is really close.  It does group the blocks together, but not at the point selected.  For some reason they are moved to  -70',-70' from the selected point?

0 Likes
Message 5 of 6

Designer_1E
Enthusiast
Enthusiast

ok, I think it is because I changed the origin in that file... Now I need to figure out how to reset the origin.

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

Kent Cooper, AIA
0 Likes