Author Topic: Multiline Edit  (Read 3299 times)

0 Members and 1 Guest are viewing this topic.

udaaf

  • Guest
Multiline Edit
« on: March 12, 2013, 05:36:58 AM »
Could some one explain me about algorithm for find open tee, open cross or corner joint to edit multiline using AutoLISP.
Sample drawing is attached.

Thanks,

udaaf

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Multiline Edit
« Reply #1 on: March 12, 2013, 06:20:22 AM »
What do you mean when you say 'Multiline'? There appear to be no multiline entities in the drawing.

ScottBolton

  • Guest
Re: Multiline Edit
« Reply #2 on: March 12, 2013, 06:32:47 AM »
If I understand you correctly, you want to identify how two elements intersect, perhaps to insert a particular block / symbol.

You could manually select the two elements or you could get your routine to loop through each line and compare it to the others. Use (vla-IntersectWith to determine the intersection coords then see if that coincides with a start or end point. If none then it's a crossing; if one then it's a T; if two it's a corner. Get the bearing of each line and compare to determine if it's an outie or an innie.

If this is what you're after then this flow should get you started...

S

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Multiline Edit
« Reply #3 on: March 12, 2013, 07:51:40 AM »
Yes, Scott's explanation should get you pointed in the correct direction. The easiest way is to use the ActiveX IntersectWith method as he's explaned, that is if you want to also allow for other entity types than only lines (e.g. polylines as well). If all your entity types are always lines, you could do similar using only the DWF data from entget - comparing each line's start (code 10) and end (code 11) with to other lines' starts and ends through the inters function.

The idea behind such code as per the attached flow diagram.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Multiline Edit
« Reply #4 on: March 12, 2013, 08:30:05 AM »
Great flow chart Irné!  8-)

Implementing Irné's logic in code, here is a short example that you can build on:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / e1 e2 i1 i2 il ip p1 p2 p3 p4 ss )
  2.     (if (setq ss (ssget '((0 . "LINE"))))
  3.         (progn
  4.             (repeat (setq i1 (sslength ss))
  5.                 (setq e1 (entget (ssname ss (setq i1 (1- i1))))
  6.                       p1 (cdr (assoc 10 e1))
  7.                       p2 (cdr (assoc 11 e1))
  8.                 )
  9.                 (repeat (setq i2 i1)
  10.                     (setq e2 (entget (ssname ss (setq i2 (1- i2))))
  11.                           p3 (cdr (assoc 10 e2))
  12.                           p4 (cdr (assoc 11 e2))
  13.                     )
  14.                     (if (setq ip (inters p1 p2 p3 p4))
  15.                         (cond
  16.                             (   (and
  17.                                     (or (equal ip p1 1e-8) (equal ip p2 1e-8))
  18.                                     (or (equal ip p3 1e-8) (equal ip p4 1e-8))
  19.                                 )
  20.                                 (setq il (cons (list "CORNER" ip) il))
  21.                             )
  22.                             (   (or (equal ip p1 1e-8) (equal ip p2 1e-8)
  23.                                     (equal ip p3 1e-8) (equal ip p4 1e-8)
  24.                                 )
  25.                                 (setq il (cons (list "TEE" ip) il))
  26.                             )
  27.                             (   (setq il (cons (list "CROSS" ip) il)))
  28.                         )
  29.                     )
  30.                 )
  31.             )
  32.             (mapcar 'print il)
  33.         )
  34.     )
  35.     (princ)
  36. )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Multiline Edit
« Reply #5 on: March 12, 2013, 08:43:20 AM »
Thanks Lee, though your code is a bit more optimal than my chart: The nested loop is only looping over the lines not already completed in the containing loop. So no need to check if Line1 /= Line2.

And perhaps a miniscule bit slower: You're combining that huge set of nested ifs into a single cond - though it might then check the same thing twice where it wouldn't if using nested ifs. But of course it's a whole lot more concise your way!  :kewl:
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Multiline Edit
« Reply #6 on: March 12, 2013, 08:47:41 AM »
Thanks Irné  8-)

I guess this would be a more efficient approach in that respect:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / e1 e2 f1 f2 i1 i2 il ip p1 p2 p3 p4 ss )
  2.     (if (setq ss (ssget '((0 . "LINE"))))
  3.         (progn
  4.             (repeat (setq i1 (sslength ss))
  5.                 (setq e1 (entget (ssname ss (setq i1 (1- i1))))
  6.                       p1 (cdr (assoc 10 e1))
  7.                       p2 (cdr (assoc 11 e1))
  8.                 )
  9.                 (repeat (setq i2 i1)
  10.                     (setq e2 (entget (ssname ss (setq i2 (1- i2))))
  11.                           p3 (cdr (assoc 10 e2))
  12.                           p4 (cdr (assoc 11 e2))
  13.                     )
  14.                     (if (setq ip (inters p1 p2 p3 p4))
  15.                         (progn
  16.                             (setq f1 (or (equal ip p1 1e-8) (equal ip p2 1e-8))
  17.                                   f2 (or (equal ip p3 1e-8) (equal ip p4 1e-8))
  18.                             )
  19.                             (cond
  20.                                 (   (and f1 f2) (setq il (cons (list "CORNER" ip) il)))
  21.                                 (   (or  f1 f2) (setq il (cons (list "TEE"    ip) il)))
  22.                                 (   (setq il (cons (list "CROSS" ip) il)))
  23.                             )
  24.                         )
  25.                     )
  26.                 )
  27.             )
  28.             (mapcar 'print il)
  29.         )
  30.     )
  31.     (princ)
  32. )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Multiline Edit
« Reply #7 on: March 12, 2013, 09:03:42 AM »
Yeah, but only fractionally  ;)

The actual reason I was thinking of using the nested ifs is because of thinking ahead: The general principle of this type of scenario is to create multilines (like walls on a plan intersecting with each other). With the nested ifs it's then possible to add not only the intersection point but also the entities and their relation in case of a T junction (i.e. which is the stem and which is the head) - which makes it a bit simpler to perform the cleanup routine.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

udaaf

  • Guest
Re: Multiline Edit
« Reply #8 on: March 12, 2013, 10:18:00 AM »
Ups sorry. Here's the file with multiline

udaaf

  • Guest
Re: Multiline Edit
« Reply #9 on: March 12, 2013, 10:21:13 AM »
ScottBolton, irneb , Lee Mac thanks for your explanation. I'll try.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Multiline Edit
« Reply #10 on: March 12, 2013, 01:57:55 PM »
Try this quickly written code udaaf:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:mlfix ( / cm e1 e2 i1 i2 il m1 m2 o1 o2 p1 ss )
  2.     (if (setq ss (ssget "_:L" '((0 . "MLINE"))))
  3.         (progn
  4.             (setq cm (getvar 'cmdecho))
  5.             (setvar 'cmdecho 0)
  6.             (repeat (setq i1 (sslength ss))
  7.                 (setq e1 (ssname ss (setq i1 (1- i1)))
  8.                       o1 (vlax-ename->vla-object e1)
  9.                 )
  10.                 (repeat (setq i2 i1)
  11.                     (setq e2 (ssname ss (setq i2 (1- i2)))
  12.                           o2 (vlax-ename->vla-object e2)
  13.                           il (group3 (vlax-invoke o1 'intersectwith o2 acextendnone))
  14.                     )
  15.                     (cond
  16.                         (   (= 1 (length il))
  17.                             (command "_.-mledit" "_CJ" (list e1 (car il)) (list e2 (car il)) "")
  18.                         )
  19.                         (   (= 4 (length il))
  20.                             (command "_.-mledit" "_OC" (list e1 (car il)) (list e2 (cadr il)) "")
  21.                         )
  22.                         (   (= 2 (length il))
  23.                             (setq p1 (car il)
  24.                                   m1 (group3 (vlax-get o1 'coordinates))
  25.                                   m2 (group3 (vlax-get o2 'coordinates))
  26.                             )
  27.                             (if (<  (min (distance p1 (car m1)) (distance p1 (last m1)))
  28.                                     (min (distance p1 (car m2)) (distance p1 (last m2)))
  29.                                 )
  30.                                 (command "_.-mledit" "_OT" (list e1 (car il)) (list e2 (cadr il)) "")
  31.                                 (command "_.-mledit" "_OT" (list e2 (car il)) (list e1 (cadr il)) "")
  32.                             )
  33.                         )
  34.                     )
  35.                 )
  36.             )
  37.             (setvar 'cmdecho cm)
  38.         )
  39.     )
  40.     (princ)
  41. )
  42.  
  43. (defun group3 ( l / r )
  44.     (repeat (/ (length l) 3)
  45.         (setq r (cons (list (car l) (cadr l) (caddr l)) r)
  46.               l (cdddr l)
  47.         )
  48.     )
  49.     (reverse r)
  50. )

edit: added cmdecho expression
« Last Edit: March 12, 2013, 02:05:20 PM by Lee Mac »

udaaf

  • Guest
Re: Multiline Edit
« Reply #11 on: March 12, 2013, 06:44:58 PM »
Try this quickly written code udaaf:

Hi Lee, thanks a lot. This code it's work and awesome.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Multiline Edit
« Reply #12 on: March 12, 2013, 06:48:39 PM »
Try this quickly written code udaaf:

Hi Lee, thanks a lot. This code it's work and awesome.

You're very welcome udaaf, I'm glad you like the program  :-)