TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: todor on August 04, 2015, 06:14:33 AM

Title: connect blocks with line
Post by: todor on August 04, 2015, 06:14:33 AM
greeting.
does anyone have a lisp that when selects blocks connects them with a line or polyline.
thank you
Title: Re: connect blocks with line
Post by: ribarm on August 04, 2015, 06:46:48 AM
You have to have some rule for making connections... Order of selected blocks can vary - you have to provide exact order for which connections should be performed... Or you just want to pick blocks one by one?
Title: Re: connect blocks with line
Post by: todor on August 04, 2015, 06:55:48 AM
You have to have some rule for making connections... Order of selected blocks can vary - you have to provide exact order for which connections should be performed... Or you just want to pick blocks one by one?

For now it is enough that the coupling is carried out one by one,  selects 1, 2,3, 4,5 ... and are binding 1-2-3-4-5-6 etc.
Th.
Title: Re: connect blocks with line
Post by: Tharwat on August 04, 2015, 08:12:06 AM
Something like this ?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ s p ss q 1p gr)
  2.   ;;    Tharwat 04.Aug.2015     ;;
  3.   (princ "\nPick on the first Block :")
  4.   (if (setq s (ssget "_+.:S:E" '((0 . "INSERT"))))
  5.     (progn
  6.       (princ "\nNext Block :")
  7.       (while (setq ss (ssget "_+.:S:E" '((0 . "INSERT"))))
  8.         (setq p (cdr (assoc 10 (entget (ssname s 0)))))
  9.         (while (and s ss (eq 5 (car (setq gr (grread t 15 0)))))
  10.           (redraw)
  11.           (setq q (cdr (assoc 10 (entget (ssname ss 0)))))
  12.           (if (or (equal (car p) (car q) 1e-4)
  13.                   (equal (cadr p) (cadr q) 1e-4)
  14.                   )
  15.             (grvecs (list -3 p q))
  16.             (if
  17.               (minusp
  18.                 (sin
  19.                   (-
  20.                     (angle
  21.                       p
  22.                       q
  23.                       )
  24.                     (angle q (cadr gr))
  25.                     )
  26.                   )
  27.                 )
  28.                (grvecs
  29.                  (list -3 p (setq 1p (list (car q) (cadr p) 0.)) 1p q)
  30.                  )
  31.                (grvecs
  32.                  (list -3 p (setq 1p (list (car p) (cadr q) 0.)) 1p q)
  33.                  )
  34.                )
  35.             )
  36.           )
  37.         (if (eq (car gr) 3)
  38.           (if (and p 1p q)
  39.             (mapcar
  40.               '(lambda (j k)
  41.                  (entmake (list '(0 . "LINE") (cons 10 j) (cons 11 k)))
  42.                  )
  43.               (list p 1p)
  44.               (list 1p q)
  45.               )
  46.             (if (not (zerop (distance p q)))
  47.               (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q)))
  48.               )
  49.             )
  50.           )
  51.         (redraw)
  52.         (setq 1p nil
  53.               s  ss
  54.               )
  55.         )
  56.       )
  57.     )
  58.   (princ)
  59.   )
Title: Re: connect blocks with line
Post by: todor on August 04, 2015, 08:17:09 AM
Yes, work.
But line two blocks should be connected with a line or polyline at the shortest distance
Th.
Title: Re: connect blocks with line
Post by: Tharwat on August 04, 2015, 08:21:24 AM
Yes, work.
But line two blocks should be connected with a line or polyline at the shortest distance
Th.

Sorry , not clear enough to me .

Explain a bit further .
Title: Re: connect blocks with line
Post by: andy_lee on August 04, 2015, 08:25:40 AM
Tharwat ,good man !

Here is a way ,code by Alan
Code - Auto/Visual Lisp: [Select]
  1. ; http://www.theswamp.org/index.php?topic=33469.0
  2. (defun c:OC (/ _sel lst pt)
  3.   ;; Connect objects (by insertion point)
  4.   ;; Alan J. Thompson, 05.22.10
  5.   (defun _sel (pnt msg / gr e pt)
  6.     (while (and (setq gr (grread T 15 2))
  7.                 (/= (car gr) 25)
  8.                 (not (vl-position (cadr gr) '(13 158)))
  9.                 (not e)
  10.            )
  11.       (redraw)
  12.       (and pnt (grdraw (trans pnt 0 1) (cadr gr) 1 -1))
  13.       (princ (strcat "\r" msg))
  14.       (if (and (eq 3 (car gr))
  15.                (setq e (ssget (cadr gr)))
  16.                (setq e (entget (ssname e 0)))
  17.                (not (wcmatch (cdr (assoc 0 e)) "*LINE*,ARC,*TEXT*"))
  18.                (setq pt (cdr (assoc 10 e)))
  19.           )
  20.         pt
  21.         (setq e nil)
  22.       )
  23.     )
  24.   )
  25.  
  26.   (if (car (setq lst (list (_sel nil "Select object: "))))
  27.     (while (setq pt (_sel (car lst) "Select next object: "))
  28.       (if (equal pt (car lst))
  29.         (alert "Same object as previous!")
  30.         (progn (setq lst (cons pt lst))
  31.                (entmakex (list '(0 . "LINE") (cons 10 (cadr lst)) (cons 11 (car lst))))
  32.         )
  33.       )
  34.     )
  35.   )
  36.   (redraw)
  37.   (princ)
  38. )
  39.  
Title: Re: connect blocks with line
Post by: andy_lee on August 04, 2015, 08:42:58 AM
And some reference here:

http://www.theswamp.org/index.php?topic=30434.0
Title: Re: connect blocks with line
Post by: Tharwat on August 04, 2015, 08:59:54 AM
Tharwat ,good man !

Thank you Andy  :wink:
Title: Re: connect blocks with line
Post by: andy_lee on August 04, 2015, 09:09:23 AM
Tharwat ,good man !

Thank you Andy  :wink:

You're welcome. :-)
Title: Re: connect blocks with line
Post by: mianbaoche on August 04, 2015, 09:31:50 AM
And some reference here:

http://www.theswamp.org/index.php?topic=30434.0

 using the improved genetic algorithm。Great!
Title: Re: connect blocks with line
Post by: todor on August 05, 2015, 03:35:05 AM
Thanks.
Title: Re: connect blocks with line
Post by: tanvirme2k9 on August 10, 2015, 09:49:59 PM
andy_lee : "Here is a way ,code by Alan"

Is it possible to draw polyline instead of line?
Title: Re: connect blocks with line
Post by: tedg on August 11, 2015, 10:31:16 AM
andy_lee : "Here is a way ,code by Alan"

Is it possible to draw polyline instead of line?
Change .line to .pline ? (didn't test it, just a guess)
Title: Re: connect blocks with line
Post by: tanvirme2k9 on August 12, 2015, 12:33:26 AM
Quote
Change .line to .pline ? (didn't test it, just a guess)

Changing '. line' to '.pline' doesn't work  :-(
Title: Re: connect blocks with line
Post by: Kerry on August 12, 2015, 12:50:55 AM
I tested previously, it didn't work  :-(

Exactly what did you try ??
Title: Re: connect blocks with line
Post by: ur_naz on August 12, 2015, 04:31:24 AM
Can anyone try to do something like this?
Title: Re: connect blocks with line
Post by: roy_043 on August 12, 2015, 06:44:51 AM
@ ur_naz:
Where is the logic in the connecting lines? The left and right part of the image now have a different pattern. This seems arbitrary as the lines used on the left could also be used on the right and vice versa.
Title: Re: connect blocks with line
Post by: ur_naz on August 12, 2015, 07:21:39 AM
@ ur_naz:
Where is the logic in the connecting lines? The left and right part of the image now have a different pattern. This seems arbitrary as the lines used on the left could also be used on the right and vice versa.
Main goal is to connect blocks one by one without intersection of connection lines. If there is no way to connect blocks without intersection, previous blocks must be reconnected automaticaly or user is alerted on impossibility to continue. No matter in which order blocks are selected.