Jump to content

Increase the space between multiple lines


acad1985

Recommended Posts

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

Link to comment
Share on other sites

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, ...).

Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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.

Link to comment
Share on other sites

[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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

[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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 5 years later...
On 6/19/2018 at 8:54 AM, hanhphuc said:

 

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

 

 

hello, can you share the lisp complete, please? 

Link to comment
Share on other sites

Thank you Bigal, i got it with you recomendation, but, could you modify the lisp please for increase or decreace the distance between: x, y or x+y segments please, the actualy lisp only increase in y sergements axis. 

this lips can solve the overlap pline of this rutine and see the parallals pline that correspond for each equitpment

image.thumb.png.cd135b02236af6af2160cf422ac88f40.png

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...