Tamim Posted 6 hours ago Posted 6 hours ago I need help with adjusting the X-direction spacing of multiple blocks (row-wise) in AutoCAD. The Y-position should remain unchanged. For example, the current spacing between blocks is 27 ft, but once I select all the blocks and input a new value like 23 or 24, the blocks should automatically update to the new spacing as per my requirement. BLK Sample.dwg Quote
Saxlle Posted 3 hours ago Posted 3 hours ago Hi @Tamim, Try with this: (prompt "\nTo run a LISP type: reara") (princ) (defun c:reara ( / old_osmode base_blk spacing ss base_blk_pt dist_blk_lst len i ins_pt dist n dist_n x_cord y_cord new_pt) (setq old_osmode (getvar 'osmode)) (setvar 'osmode 0) (setq base_blk (car (entsel "\nPick the base block:\n")) spacing (getreal "\nEnter the spacing:\n") ) (prompt "\nSelect BLOCK's:") (setq ss (ssget (list (cons 0 "INSERT"))) base_blk_pt (cdr (assoc 10 (entget base_blk))) dist_blk_lst (list) ) (if (ssmemb base_blk ss) (ssdel base_blk ss) ) (setq len (sslength ss) i 0 ) (while (< i len) (setq ins_pt (cdr (assoc 10 (entget (ssname ss i)))) dist (distance base_blk_pt ins_pt) dist_blk_lst (cons (list dist (ssname ss i)) dist_blk_lst) i (1+ i) ) ) (setq dist_blk_lst (vl-sort dist_blk_lst (function (lambda (x1 x2) (< (car x1) (car x2))))) n 0 ) (repeat (length dist_blk_lst) (setq dist_n (- (car (nth n dist_blk_lst)) spacing (* spacing n)) x_cord (- (cadr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) dist_n) y_cord (caddr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) new_pt (list x_cord y_cord) ) (command-s "_move" (cadr (nth n dist_blk_lst)) "" (cdr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) new_pt) (setq n (1+ n)) ) (setvar 'osmode old_osmode) (prompt (strcat "\nThe " (itoa (length dist_blk_lst)) " are rearanged!")) (princ) ) See the following video how it works. Rearange blocks.mp4 Best regards. Quote
Tamim Posted 3 hours ago Author Posted 3 hours ago 6 minutes ago, Saxlle said: Hi @Tamim, Try with this: (prompt "\nTo run a LISP type: reara") (princ) (defun c:reara ( / old_osmode base_blk spacing ss base_blk_pt dist_blk_lst len i ins_pt dist n dist_n x_cord y_cord new_pt) (setq old_osmode (getvar 'osmode)) (setvar 'osmode 0) (setq base_blk (car (entsel "\nPick the base block:\n")) spacing (getreal "\nEnter the spacing:\n") ) (prompt "\nSelect BLOCK's:") (setq ss (ssget (list (cons 0 "INSERT"))) base_blk_pt (cdr (assoc 10 (entget base_blk))) dist_blk_lst (list) ) (if (ssmemb base_blk ss) (ssdel base_blk ss) ) (setq len (sslength ss) i 0 ) (while (< i len) (setq ins_pt (cdr (assoc 10 (entget (ssname ss i)))) dist (distance base_blk_pt ins_pt) dist_blk_lst (cons (list dist (ssname ss i)) dist_blk_lst) i (1+ i) ) ) (setq dist_blk_lst (vl-sort dist_blk_lst (function (lambda (x1 x2) (< (car x1) (car x2))))) n 0 ) (repeat (length dist_blk_lst) (setq dist_n (- (car (nth n dist_blk_lst)) spacing (* spacing n)) x_cord (- (cadr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) dist_n) y_cord (caddr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) new_pt (list x_cord y_cord) ) (command-s "_move" (cadr (nth n dist_blk_lst)) "" (cdr (assoc 10 (entget (cadr (nth n dist_blk_lst))))) new_pt) (setq n (1+ n)) ) (setvar 'osmode old_osmode) (prompt (strcat "\nThe " (itoa (length dist_blk_lst)) " are rearanged!")) (princ) ) See the following video how it works. Rearange blocks.mp4 1.33 MB · 0 downloads Best regards. Thanks for the prog. However, this only works for a single X row. I need to select both top and bottom rows (like Y1 and Y2), and show the result below the image. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.