Jump to content
acad1985

Increase the space between multiple lines

Recommended Posts

acad1985

Hello Everyone

I have a electrical schematic drawing..but the lines are very close to each other. I want to increase the space between the lines..(stretch or something like that)... Is any possible to do that by lisp. Or please suggest me any possible ways.

 

 

Thanks in advance

Share this post


Link to post
Share on other sites
Emmanuel Delay

Can you send a sample (upload a small dwg ...)?

I once tried something like that to detect and alter windows (architecture plans).

By looking for lines that are parallel, of which the endpoints are close together (left endpoint of line 1 is close to left endpoint of line 2, ...).

Share this post


Link to post
Share on other sites
hanhphuc
Posted (edited)
Hello Everyone

I have a electrical schematic drawing..but the lines are very close to each other. I want to increase the space between the lines..(stretch or something like that)... Is any possible to do that by lisp. Or please suggest me any possible ways.

 

 

Thanks in advance

 

 

(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)
       )
)
 ) ;_ end of defun

[color="green"];test
;(setq ls '(1 2 3  5  11 18 25 31 40 65 80) ) ; assume list is X or Y coordinates ?
;(setq lst ([color="blue"]foo[/color] ls 5))  ; 5= minimum spacing
;'(1 6 11 16 21 26 31 36 41 65 80) ; rearranged ?[/color]

[color="green"];foreach n , or mapcar 
; (list x [color="red"]n[/color]); x datum, i.e: increment at y direction 
; (list [color="red"]n[/color] y); y datum, i.e: increment at x direction [/color]


Edited by hanhphuc
examples commented as OP reported error perhaps doesn't know about coding

Share this post


Link to post
Share on other sites
acad1985

Hi All

Thanks for your Reply,

I have tested your code, but i got error like "Extra right paren input".

 

Please see the attached file.

 

1344465490.dwg

 

Thanks

Share this post


Link to post
Share on other sites
dlanorh
[color=green];test[/color] 

;(setq ls '(1 2 3  5  11 18 25 31 40 65 80) )
[color=green]; assume list is X or Y coordinates ?[/color] 

;(setq lst ([color=blue]foo[/color] ls 5))  [color=green]; 5= minimum spacing 
[/color]
; '(1 6 11 16 21 26 31 36[color=red] 41[/color] 65 80)
[color=green]; rearranged ?[/color]  

[color=green];foreach n , or mapcar  [/color] 

; (list x [color=red]n[/color])[color=green]; x datum, i.e: increment at y direction[/color]
;(list [color=red]n[/color] y) [color=green]; y datum, i.e: increment at x direction [/color]

Everything from ;test downwards should be commented out as they are examples of how to use the defun code (see above). This should get rid of the "Extra right paren..on input" error.

Share this post


Link to post
Share on other sites
hanhphuc
[color=green];test[/color] 

 

Everything from ;test downwards should be commented out as they are examples of how to use the defun code (see above). This should get rid of the "Extra right paren..on input" error.

 

Thanks for assist :)

 

@OP, sorry i'm not electrical guy, the previous code was a theory for minimum space but was unsure next action before & after etc.. :unsure:

BTW which lines are too closed each other?

Share this post


Link to post
Share on other sites
dlanorh
Thanks for assist :)

No problem :thumbsup:

Share this post


Link to post
Share on other sites
acad1985

Hi I have Tested again your code.. but i got same error .

 

 

@Emmanuel, Please see the another attached.

Sample.dwg

 

 

Thanks

Share this post


Link to post
Share on other sites
hanhphuc
Hi I have Tested again your code.. but i got same error .

 

That was typo error but you just copy&paste without understanding :ouch:

solutions: add missing or delete extra parentheses

example"

[color="red"][b]([/b][/color] princ "Hello" [color="green"];missing parentheses [/color]
[color="green"]; error: malformed list on input[/color]
[color="red"][b]([/b][/color] princ "Hello" [color="red"][b])[/b][/color] [color="blue"][b]) [/b][/color] [color="green"];extra parentheses[/color]
[color="green"]; error: extra right paren on input[/color]

anything after the commenting semicolon ';' not evaluated in lisp interpreter.

 

The code was not executable as mentioned it was just spacing theory / algorithm based on your 'post title' we could just assume something, because didn't know your actually outcome.

 

you could post dwg before & after spacing (done manually),

then let's try if it can be automated?

This forum mainly for discussions not always end with solutions :)

Share this post


Link to post
Share on other sites
Emmanuel Delay

elec2.dwg

 

I wrote something. It doesn't solve everything, but it can be a help to the file that you posted.

 

I'll provide my own simplified dwg.

 

Command: OL (offset lines)

- then type an offset distance (for my dwg pick 25, for your dwg 0.16)

- in a while loop, select each polyline.

* The first pline sets the base x-value

* The Each next vertical line will be "offset distance" to the right of the previous vertical line

 

This script expects polylines that first go horizontal, then vertical, then horizontal again (this last line is not required). So point 0 is the start, point 1 & point 2 are on the same x-value.

 

* notice: if the vertical lines are not exactly vertical *, this script will straighten them out.

 

(* coworkers who haven't found the ortho button, they exist)

 

;; @see https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/modifing-lwpolyline-coordinate/td-p/2438819

;; Subst-i
;; Replaces the item at specified index by a new one
(defun subst-i (new ind lst)
 (if (or (zerop ind) (null lst))
   (cons new (cdr lst))
   (cons (car lst) (subst-i new (1- ind) (cdr lst)))
 )
)

;;; 2d-coord->pt-lst
;; Converts a 2d coordinates flat list into a 2d point list
;;; (2d-coord->pt-lst '(1.0 2.0 3.0 4.0)) -> ((1.0 2.0) (3.0 4.0))
(defun 2d-coord->pt-lst (lst)
 (if lst
   (cons (list (car lst) (cadr lst))
     (2d-coord->pt-lst (cddr lst))
   )
 )
)

(defun nextobject ( / )
 (vlax-ename->vla-object (car (entsel)))
)

(defun c:ol ( / needle pl p1 p2 offsetdist)
 ;; feel free to swap the method of setting the distance (by clicking 2 points or typing)
 ;;(setq offsetdist (distance (getpoint "p1: ") (getpoint "p2: ")))
 (setq offsetdist (getreal "\nSet the offset distance: "))
 
 (setq needle nil)
 (while (setq pl (nextobject))
   (setq pts (2d-coord->pt-lst (vlax-get pl 'coordinates)))
   ;; we will keep the most left vertical line.  All other verticallines will use this x-value as base
   (if (= needle nil)
     (setq needle (nth 0 (nth 1 pts)))
   )
   ;; replace the x-value of point 1 & 2 of the polyline
   (setq p1 (list 
      needle 
      (nth 1 (nth 1 pts))
   ))
   (setq p2 (list 
      needle 
      (nth 1 (nth 2 pts))
   ))
     ;; substitute p1 & p2 by the new point in the pointlist
   (setq pts (subst-i (list (car p1) (cadr p1)) 1 pts))
   (setq pts (subst-i (list (car p2) (cadr p2)) 2 pts))
     ;; this actually executes the replacement on the object
   (vlax-put pl 'Coordinates (apply 'append pts))
   (setq needle (+ needle offsetdist))
 ) 
)

So now you have to choose which polyline comes next.

It is possible instead to let the client select polylines, then sort the lines according to how left the vertical line is, if you need this, let me know.

Share this post


Link to post
Share on other sites
hanhphuc
Posted (edited)
[ATTACH]64046[/ATTACH]

 

I wrote something. It doesn't solve everything, but it can be a help to the file that you posted.

 

I'll provide my own simplified dwg.

 

 

hi, Thanks your example, now i figure out a bit electrical job :)

 

 

using previous sub function foo

This example will increase the space only, based on OP's title 'Increase the space between multiple lines'


(defun c:test ( / s l i d e )[color="green"] ; Increase the space between multiple vertical lines[/color]
;hanhphuc 19.06.2018
(initget 7)
(and
(setq d (getdist "\nSpecify space distance : "))
(setq s (ssget ":L" '((0 . "LWPOLYLINE") (-4 . "=") (70 . 0) (90 . 4)))
     )
(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
	   ([color="blue"]foo[/color] (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)
)

 

 

RhKlFZ8.gif

Edited by hanhphuc
quotes to lambda

Share this post


Link to post
Share on other sites
Emmanuel Delay

cool, that is useful

Share this post


Link to post
Share on other sites
acad1985

Thank you so much hanhphuc and Emmanuel for your Code.

I have tested your code with Sample file which is posted by Emmanuel, (elec.dwg)...it was working Perfectly.

But when i tried in mu DWG, i can't select the Line. Actually My file have some Blocks.

 

Please see Attached.

 

Test.dwg

Share this post


Link to post
Share on other sites
Emmanuel Delay

The problem with that latest dwg is the 5 point polylines, because of the diagonal lines that go to the J blocks .

Both our scripts look only for 3-line (4 point) polylines, and we fix the middle one.

Well, my script fixes the second line, so you can add lines to the polyline as long as the vertical line is drawn as the second line.

 

---

 

What you should do:

- first make some room: with a stretch command you put the blocks a little farther apart. This gives our script some room to maneuver. Stretch them back at the end.

- trim everything to the right of those dashed line (unless we fix our script to also include this type of plans), I put the diagonal lines back in red; all detached from the polylines (see attachment).

 

Then both scripts work.

 

Test_2.dwg

Share this post


Link to post
Share on other sites
acad1985

Yes...I got it..

Thank you so much for your Help.

 

and Thank you hanhphuc.

:D

Share this post


Link to post
Share on other sites
hanhphuc
Yes...I got it..

Thank you so much for your Help.

 

and Thank you hanhphuc.

:D

you are welcome :)

 

p/s: naming foo - global function as unique as possible

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×