Author Topic: connect blocks with line  (Read 5744 times)

0 Members and 1 Guest are viewing this topic.

todor

  • Mosquito
  • Posts: 19
connect blocks with line
« 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

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: connect blocks with line
« Reply #1 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?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

todor

  • Mosquito
  • Posts: 19
Re: connect blocks with line
« Reply #2 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.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: connect blocks with line
« Reply #3 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.   )

todor

  • Mosquito
  • Posts: 19
Re: connect blocks with line
« Reply #4 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.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: connect blocks with line
« Reply #5 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 .

andy_lee

  • Newt
  • Posts: 147
Re: connect blocks with line
« Reply #6 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.  
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: connect blocks with line
« Reply #7 on: August 04, 2015, 08:42:58 AM »
andy.
Best regards.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: connect blocks with line
« Reply #8 on: August 04, 2015, 08:59:54 AM »
Tharwat ,good man !

Thank you Andy  :wink:

andy_lee

  • Newt
  • Posts: 147
Re: connect blocks with line
« Reply #9 on: August 04, 2015, 09:09:23 AM »
andy.
Best regards.

mianbaoche

  • Guest
Re: connect blocks with line
« Reply #10 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!

todor

  • Mosquito
  • Posts: 19
Re: connect blocks with line
« Reply #11 on: August 05, 2015, 03:35:05 AM »
Thanks.

tanvirme2k9

  • Guest
Re: connect blocks with line
« Reply #12 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?

tedg

  • Swamp Rat
  • Posts: 811
Re: connect blocks with line
« Reply #13 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)
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

tanvirme2k9

  • Guest
Re: connect blocks with line
« Reply #14 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  :-(
« Last Edit: August 12, 2015, 04:59:36 AM by tanvirme2k9 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: connect blocks with line
« Reply #15 on: August 12, 2015, 12:50:55 AM »
I tested previously, it didn't work  :-(

Exactly what did you try ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: connect blocks with line
« Reply #16 on: August 12, 2015, 04:31:24 AM »
Can anyone try to do something like this?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: connect blocks with line
« Reply #17 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.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: connect blocks with line
« Reply #18 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.