Change Offset with lisp - Increase the space between multiple lines

Change Offset with lisp - Increase the space between multiple lines

Emi_Riv
Contributor Contributor
617 Views
7 Replies
Message 1 of 8

Change Offset with lisp - Increase the space between multiple lines

Emi_Riv
Contributor
Contributor

Hello everyone

 

I came across this, but it doesn't seem to work with AutoCAD 2018.

https://www.cadtutor.net/forum/topic/65407-increase-the-space-between-multiple-lines/

Beispiel.gif

Does anyone have an alternative solution?

I've been searching for hours, but haven't found anything. =/

 

Thank you in advance for your assistance!

Best regards

0 Likes
Accepted solutions (1)
618 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

Did you check the Exceed link also. Note the comments about removing the BBC color coding from the older code.

 

Arrange the wires with a constant offset - AutoLISP, Visual LISP & DCL - AutoCAD Forums (cadtutor.ne...

0 Likes
Message 3 of 8

Emi_Riv
Contributor
Contributor

Hi Sea

Thank you for your feedback.

Yes i saw it and tried it but doesn't work aswell. 😕

Also removed the BBC color from the first code which also didn't work.

0 Likes
Message 4 of 8

Emi_Riv
Contributor
Contributor

Doesn't anyone have an idea? Is Lisp working for anyone? I always need a lot of time for this process and would be happy if someone could help me with it.

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

Try this one. It's the code from there with minor adjustments. It should work in 2018.

 

;; https://www.cadtutor.net/forum/topic/65407-increase-the-space-between-multiple-lines/?do=findComment&comment=539014

(defun c:test ( / foo s l i d e ) ; Increase the space between multiple vertical lines[/color]
  
  
  (defun foo (l n / i ls)
    (cons	(setq i (car l))
      (progn (repeat (1- (length l))
	       (setq ls (cons	(setq i	(if (> (cadr l) (+ n i))
					  (cadr l)
					  (+ n i)))
				ls))
	       (setq l (cdr l)))
	(reverse ls))))
  
  
  ;hanhphuc 19.06.2018
  (initget 7)
  (and
    (setq d (getdist "\nSpecify space distance : "))
    (setq s (ssget ":L" '((0 . "LWPOLYLINE"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    l  (cons (cons e (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget e)))) l)))  
    (setq l (vl-sort l ''((a b) (< (caaddr a) (caaddr b)))))
    (foreach x (mapcar '(lambda (a b) (foreach x '(2 3) (setq a (subst (list b (cadr (nth x a))) (nth x a) a))) a) l (foo (mapcar 'caaddr l) d))
      (entmod (append (vl-remove-if '(lambda (x) (= (car x) 10)) (entget (car x)))
		      (mapcar '(lambda (x) (cons 10 x)) (cdr x))))))
  (princ)
  )

 

Message 6 of 8

Emi_Riv
Contributor
Contributor

Wow, it works, a thousand thanks. Is it possible to align not only vertical but also horizontal lines? And perhaps, can the spacing also be reduced? Currently, if the gap between two lines is 150, it cannot be reduced to 100. Of course, only if it's not too much trouble; I'm already happy to have this option now.

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

This should do the trick. Any angle, any distance, can specify a no-move line.

 

(vl-load-com)

(defun c:LineSpacing ( / *error* doc s x p l f i a d q o)
  
  (or *pls-c* (setq *pls-c* 10)) ; default
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if doc (vla-endundomark doc))
    (princ))
  
  (and (princ "\nSelect polylines at segments to space, ")
       (setq s (ssget "_:L" '((0 . "LWPOLYLINE"))))
       (>= (sslength s) 2)
       (setq *pls-c* (cond ((getdist (strcat "\nSpecify offset <" (rtos *pls-c*) ">: "))) (*pls-c*)))
       (or (setq f (car (entsel "\nSpecify fix line : "))) t)
       (setq x (ssnamex s))
       (setq p (cond ((assoc 1 x) 		(cadr (last (assoc 1 x))))   		; last pointed selection
		     ((assoc 4 x)		(cadr (last (assoc 4 x)))) 		; first point of fence
		     ((minusp (car (last x)))	(mapcar '/ (apply 'mapcar (cons '+ (mapcar 'cadr (cdr (last x))))) '(4 4)))))
       (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
       (setq l (mapcar '(lambda (x) (list x (vlax-curve-getclosestpointto x p))) l))
       (setq l (vl-sort l '(lambda (x1 x2) (< (caadr x1) (caadr x2)))))
       (setq l (vl-sort l '(lambda (x1 x2) (< (cadadr x1) (cadadr x2)))))
       (setq f (cond (f) ((caar l))))
       (setq i (vl-position f (mapcar 'car l)))
       (setq l (mapcar '(lambda (x) (cons (- (vl-position x l) i) x)) l))
       (setq o (cdr (assoc 0 l)))
       (setq r (vlax-curve-getparamatpoint (car o) (cadr o)))
       (setq o (list (vlax-curve-getpointatparam (car o) (fix r)) (vlax-curve-getpointatparam (car o) (1+ (fix r)))))
       (not (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
       (foreach j l
	 (and (mapcar 'set '(i e p) j)
	      (setq r (vlax-curve-getparamatpoint e p))
	      (setq a (+ (/ pi 2) (angle '(0 0 0) (vlax-curve-getFirstDeriv e r))))
	      (setq a (rem a (* 2 pi)))
	      (setq a (if (< (* 0.75 pi) a (* 1.75 pi)) (+ pi a) a))
	      (setq d (entget e))
	      (setq q (reverse (cdr (reverse (vlax-curve-getpointatparam e (fix r))))))
	      (setq d (subst (cons 10 (polar (inters (car o) (cadr o) q (polar q a 1) nil) a (* i *pls-c*))) (cons 10 q) d))
	      (setq q (reverse (cdr (reverse (vlax-curve-getpointatparam e (1+ (fix r)))))))
	      (setq d (subst (cons 10 (polar (inters (car o) (cadr o) q (polar q a 1) nil) a (* i *pls-c*))) (cons 10 q) d))
	      (entmod d)))
       )
  (*error* "end")
  )
Message 8 of 8

Emi_Riv
Contributor
Contributor

This is a dream. A thousand thanks.

Really very beautiful.😀😊

0 Likes