Tamim Posted yesterday at 02:15 PM Posted yesterday at 02:15 PM HI, I’m working on a CAD drawing that has several parallel polylines, and I’d like to space them out evenly by a fixed distance, but only from their start points. For example, all the lines begin from point No. 1, and I want to distribute only between line 1 and line 2, keeping the rest aligned. The goal is to spread them equally on the opposite side, similar to how the “Distribute” option works in TEXTALIGN, but for polylines instead of text. It would be great if the spacing value (for example, 0.2 ft or 0.5 ft) could be entered by the user. Does anyone know if there’s an existing LISP routine for this, or something close? Any tips or examples would be really helpful. line shifting.dwg Quote
Saxlle Posted 4 hours ago Posted 4 hours ago Hi @Tamim Try this code and see if it fulfil your needs: ; ******************************************************** ; Functions : ESP (Evenly Spacing the Polylines) ; Description : Evenly Spacing Polylines ; Author : SAXLLE ; Date : October 29, 2025 ; ******************************************************** (prompt "\nTo run a LISP type: ESP (Evenly Spacing the Polylines)") (princ) (defun c:ESP ( / myerr olderr old_osmode flag ss len lst i spacing side base_point inc ent dist_lst npt answ) (setq old_osmode (getvar 'osmode)) (defun myerr (errmsg) (setq *error* olderr) (if (not (member errmsg '("console break" "Function Cancelled")) ) (princ (strcat "\nError: " errmsg ".\nThe application has finished working...")) ) (setvar 'osmode old_osmode) (princ) ) (setq olderr *error* *error* myerr ) (setq flag T) (while (not (equal flag nil)) (setvar 'osmode old_osmode) (prompt "\nSelect Polylines:") (princ) (setq ss (ssget (list (cons 0 "*POLYLINE"))) len (sslength ss) lst (list) i 0 ) (repeat len (setq lst (cons (list (ssname ss i) (getpropertyvalue (ssname ss i) "Length")) lst) i (1+ i) ) ) (initget 1 "Left Right") (setq lst (vl-sort lst (function (lambda (a b) (< (cadr a) (cadr b))))) side (getkword "\nChoose the side? [Left/Right]") spacing (getreal "\nEnter the spacing value:") base_point (getpoint "\nPick the Base Point for spacing:\n") inc spacing i 0 ) (setvar 'osmode 0) (command-s "_UNDO" "begin") (while (< i (length lst)) (setq ent (car (nth i lst)) dist_lst (list) dist_lst (mapcar (function (lambda (x) (distance (car x) (cadr x)))) (mapcar 'list (setq pt_list (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= (car x) 10))) (entget (car (nth i lst)))))) (cdr pt_list))) ) (if (= side "Left") (progn (setq npt (list (- (car base_point) inc) (cadr base_point) (caddr base_point))) ;; to the Left, using "-" sign (command-s "_pline" npt (strcat "@" (rtos (car dist_lst) 2 2) "<90") (strcat "@" (rtos (- (cadr dist_lst) inc) 2 2) "<180") (strcat "@" (rtos (caddr dist_lst) 2 2) "<270") "") ) (progn (setq npt (list (+ (car base_point) inc) (cadr base_point) (caddr base_point))) ;; to the Right, using "+" sign (command-s "_pline" npt (strcat "@" (rtos (car dist_lst) 2 2) "<90") (strcat "@" (rtos (- (cadr dist_lst) inc) 2 2) "<0") (strcat "@" (rtos (caddr dist_lst) 2 2) "<270") "") ) ) (entdel (car (nth i lst))) (setq inc (+ inc spacing) i (1+ i) ) ) (command-s "_UNDO" "end") (initget 1 "Yes No Undo") (setq answ (getkword "\Do you want to continue? [Yes/No/Undo]")) (cond ((equal answ "No") (setvar 'osmode old_osmode) (setq flag nil) ) ((equal answ "Undo") (command-s "_UNDO" "") ) ) ) (prompt "\The polylines are evenly spaced!") (princ) ) Also, you can see the short video of how does lisp are working. EvenlySpacingPolyline.mp4 Best regards. 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.