Author Topic: Mline: marvel of science or work of the devil?  (Read 187 times)

0 Members and 1 Guest are viewing this topic.


  • Bull Frog
  • Posts: 465
Mline: marvel of science or work of the devil?
« on: December 07, 2017, 03:19:49 am »
It's the first time that I look at "MLine" - relating both common usage and handling with Lisp.

I see that these objects miss a lot of features on user-side (limited editing; limited style modification and so on) and some reluctant postings of the users.
But on the other way there are some Lisps (e.g. roy_043) which do style changing, vertex adding and so on.

So what's your opinion: is MLINE a marvel of science or work of the devil?

Background of my question:
I'm thinking about a (small) routine where mlines are used to draw walls on flor planes. And this is why I need some editing, also a "break" command and all that stuff ....

AutoCAD 2016 - 2018 German (so some technical terms will be badly retranslated to English)
Civil 3D 2017 - 2018


  • Water Moccasin
  • Posts: 1710
  • Marko Ribar, architect
Re: Mline: marvel of science or work of the devil?
« Reply #1 on: December 07, 2017, 07:15:58 am »
I personally avoid using MLines... Instead for drawing walls - if they are simple - constant width, I simply use LWPOLYLINEs with global width set to some value defining wall width... Then I can easily trim stretch or do common things, and at the end when drawing is finished I just add region outlines after which I can erase LWPOLYLINEs or leave them but make them somewhat transparent and put region outline to some other color - red and bring it to front (draworder)... This is what I use to convert constant width LWPOLYLINEs to union outline region...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:globalwidthlws2outlines ( / *error* adoc sss el ss i lw gw lw1 lw2 li1 li2 regs )
  4.  (defun *error* ( m )
  5.    (if adoc
  6.      (vla-endundomark adoc)
  7.    )
  8.    (if m
  9.      (prompt m)
  10.    )
  11.    (princ)
  12.  )
  14.  (setq sss (ssadd) el (entlast))
  15.  (prompt "\nSelect open or closed LWPOLYLINES with global widths...")
  16.  (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . ">") (43 . 0.0))))
  17.    (progn
  18.      (repeat (setq i (sslength ss))
  19.        (setq lw (ssname ss (setq i (1- i))))
  20.        (setq gw (cdr (assoc 43 (entget lw))))
  21.        (if (= 1 (logand 1 (cdr (assoc 70 (entget lw)))))
  22.          (progn
  23.            (setq lw1 (vlax-vla-object->ename (car (safearray-value (variant-value (vla-offset (vlax-ename->vla-object lw) (/ gw 2.0)))))))
  24.            (setq lw2 (vlax-vla-object->ename (car (safearray-value (variant-value (vla-offset (vlax-ename->vla-object lw) (/ gw -2.0)))))))
  25.            (if (> (vlax-curve-getarea lw1) (vlax-curve-getarea lw2))
  26.              (progn
  27.                (vla-boolean (car (vlax-invoke (vla-get-block (vla-get-activelayout adoc)) 'addregion (list (vlax-ename->vla-object lw1)))) acsubtraction (car (vlax-invoke (vla-get-block (vla-get-activelayout adoc)) 'addregion (list (vlax-ename->vla-object lw2)))))
  28.                (ssadd (entlast) sss)
  29.              )
  30.              (progn
  31.                (vla-boolean (car (vlax-invoke (vla-get-block (vla-get-activelayout adoc)) 'addregion (list (vlax-ename->vla-object lw2)))) acsubtraction (car (vlax-invoke (vla-get-block (vla-get-activelayout adoc)) 'addregion (list (vlax-ename->vla-object lw1)))))
  32.                (ssadd (entlast) sss)
  33.              )
  34.            )
  35.            (entdel lw1)
  36.            (entdel lw2)
  37.          )
  38.          (progn
  39.            (setq lw1 (vlax-vla-object->ename (car (safearray-value (variant-value (vla-offset (vlax-ename->vla-object lw) (- (/ gw 2.0) 1e-11)))))))
  40.            (setq lw2 (vlax-vla-object->ename (car (safearray-value (variant-value (vla-offset (vlax-ename->vla-object lw) (+ (/ gw -2.0) 1e-11)))))))
  41.            (setq li1 (entmakex (list '(0 . "LINE") (cons 10 (vlax-curve-getstartpoint lw1)) (cons 11 (vlax-curve-getstartpoint lw2)))))
  42.            (setq li2 (entmakex (list '(0 . "LINE") (cons 10 (vlax-curve-getendpoint lw1)) (cons 11 (vlax-curve-getendpoint lw2)))))
  43.            (ssadd (vlax-vla-object->ename (car (vlax-invoke (vla-get-block (vla-get-activelayout adoc)) 'addregion (list (vlax-ename->vla-object lw1) (vlax-ename->vla-object lw2) (vlax-ename->vla-object li1) (vlax-ename->vla-object li2))))) sss)
  44.            (entdel lw1)
  45.            (entdel lw2)
  46.            (entdel li1)
  47.            (entdel li2)
  48.          )
  49.        )
  50.      )
  51.      (setq regs (vl-remove-if 'listp (mapcar 'cadr (ssnamex sss))))
  52.      (while (and (cadr regs) (not (vlax-erased-p (cadr regs))))
  53.        (vla-boolean (vlax-ename->vla-object (car regs)) acunion (vlax-ename->vla-object (cadr regs)))
  54.        (setq regs (cons (car regs) (cddr regs)))
  55.      )
  56.    )
  57.  )
  58.  (if (not (eq el (entlast)))
  59.    (sssetfirst nil (ssadd (entlast)))
  60.  )
  61.  (*error* nil)
  62. )

Of course this is just my quick approach to solving that issue and I think it's much quicker - no need for messing with styles, just create LWPOLYLINEs with different constant (global) widths and that's all the story... Drawing of walls is finished in quick and acceptable time and manner... But that's just me, we'll see if someone else have something to say to this task...

Marko Ribar, d.i.a. (graduated engineer of architecture)


M.R. on Youtube


  • Bull Frog
  • Posts: 453
Re: Mline: marvel of science or work of the devil?
« Reply #2 on: December 07, 2017, 09:04:47 am »
Same as Marko here.
I'm using LWPolylines instead - since they are alot more flexible in editing (and like you pointed mline has limited....).

Also when using mlines and you have to send your dwg for consultation, the architect/engineer/colleague guy might ask how to explode that geometry, beacause he can't work with such objects.
I've had situations where I had to explode/burst blocks, ungroup groups and resend the dwg, because the other guy had limited CAD knowledge and just doesn't listen to "Hey just use EXPLODE and UNGROUP commands".

So for walls I use a bunch of curve/geometry manipulation functions and techniques (to be more comfortable):
Multiple offseting, and capping or just something like this. Drawing some rectangles that partially overlap, then use Lee's outline routine.
Maybe the only useful thing for mlines would be to draw roads with sidewalks for urban planning, in the end use something like this and fillet the curves at the mline's intersections.
On the other hand I won't mind exploring MLines with lisp.  :nerdystraight:


  • Water Moccasin
  • Posts: 2254
Re: Mline: marvel of science or work of the devil?
« Reply #3 on: December 07, 2017, 10:12:27 am »
If I'm drawing a wall or other object, then I'm usually drawing it in 3D.  If I have to do something "multiline" in 2D, then I'm probably using something that has an actual "wall" or other object, whether it's a vertical, third-party, or in-house product.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)

Lee Mac

  • Seagull
  • Posts: 11854
  • AutoCAD 2015 Windows 7 London, England
Re: Mline: marvel of science or work of the devil?
« Reply #4 on: December 08, 2017, 12:53:36 pm »
Personally, I've always liked the visual effect displayed when constructing an MLine, but then disliked the limited flexibility and ability to modify the resulting MLine when compared to a polyline, therefore I created this simple program some time ago to get the best of both.


  • Newt
  • Posts: 102
  • 30 + years of using Autocad
Re: Mline: marvel of science or work of the devil?
« Reply #5 on: December 09, 2017, 12:46:40 am »
I have two versions of draw lines a 2 line or 4 line, it follows very much like drawing a pline but 4 lines at a time. The offsets are not fixed but rather user defined as part of a set up for use in a session. You can drag over the 4 existing lines and this sets the offsets v's a manual entry.

Other options like inside outside offset etc.

Now the bad news its copyrited so no code. Not written by me one day I will have a look at how it works.

Written prior to Autocad Architecture.
A man who never made a mistake never made anything