selecting all multi-lines in the drawing and get the length of them

selecting all multi-lines in the drawing and get the length of them

S_S_SS
Advocate Advocate
1,337 Views
13 Replies
Message 1 of 14

selecting all multi-lines in the drawing and get the length of them

S_S_SS
Advocate
Advocate

Hello every one ….
I need a code that select all multi-lines in the drawing and get the length of them
can some one help me about that ?? 
thanks in advance ….

0 Likes
1,338 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

Possibly THIS 

 

If you want to select ALL automatically, add "X" into this line

(setq mlines (ssget "X" '((0 . "mline")))

 

Message 3 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

Selecting them all is the easy part.  Unfortunately, the length of an MLINE is not in its entity data list, nor in its VLA properties, nor in its (getpropertyvalue) properties.  So I think it would be necessary to step through the selection set, and for each MLINE, step through its vertices and calculate the distances between them in sequence, adding them as it goes to come up with a length.  Open vs. closed ones would need to be handled a little differently, adding in the distance from the last vertex back to the beginning for only the closed ones.  It's certainly possible -- I can't work on it right now, but will later if someone else doesn't jump in.

Kent Cooper, AIA
Message 4 of 14

S_S_SS
Advocate
Advocate
thanks sir
0 Likes
Message 5 of 14

S_S_SS
Advocate
Advocate
thanks sir
waiting for your code
0 Likes
Message 6 of 14

ronjonp
Advisor
Advisor

@S_S_SS 

 

What is the correct length ? The outer edge without points is longer.

ronjonp_0-1648053431699.png

 

Message 7 of 14

S_S_SS
Advocate
Advocate
I don't make continuous mline
But what I draw is a single mline
So the outer equal to the inner
They are separate parts
Thanks sir
0 Likes
Message 8 of 14

ronjonp
Advisor
Advisor

So all of your MLINE's only consist of two points?

Message 9 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [minimally tested]:

 

(defun C:MLTL ; = MultiLine Total Length
  (/ mlss len n verts)
  (if (setq mlss (ssget "_X" '((0 . "MLINE"))))
    (progn ; then
      (setq len 0)
      (repeat (setq n (sslength mlss))
        (setq
          mldata (entget (ssname mlss (setq n (1- n))))
          verts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 11)) mldata))
        ); setq
        (if (= (logand (cdr (assoc 71 mldata)) 2) 2); closed?
          (setq verts (append verts (list (car verts)))); add first vertex again at end
        ); if
        (repeat (1- (length verts))
          (setq len (+ len (distance (car verts) (cadr verts))))
          (setq verts (cdr verts))
        ); repeat [between-vertext distances]
      ); repeat [MLINEs]
      (prompt (strcat "\nTotal Length of MultiLines: " (rtos len)))
    ); progn
  ); if
  (princ)
); defun

 

It accounts for any configuration(s), and open or closed ones.  If any are not just single-segment as it appears from later Messages that yours will be, what it measures between are the defining vertex locations [the grips when selected], which under "Zero" justification may not even lie on an element of the MLINE.

 

It reports the total length in whatever the current settings are for linear-measure units format and precision.  That can be forced to be different with some arguments added to the (rtos) function.

Kent Cooper, AIA
Message 10 of 14

S_S_SS
Advocate
Advocate
Yes sir
Start and end points
0 Likes
Message 11 of 14

ronjonp
Advisor
Advisor
Accepted solution

Here's another 😂

(defun c:foo (/ a s n)
  ;; RJP » 2022-03-23
  ;; Tallies 2 point mlines total length
  (if (setq s (ssget "X" '((0 . "mline"))))
    (progn (setq n 0)
	   (foreach ml (mapcar 'cadr (ssnamex s))
	     (setq a (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 11 (car x))) (entget ml))))
	     (if (= 2 (length a))
	       (setq n (+ n (distance (car a) (cadr a))))
	       (print "MLINE has more than 2 points...")
	     )
	   )
	   (princ (strcat "\nTotal MLINE length: " (vl-princ-to-string n)))
    )
  )
  (princ)
)
Message 12 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@ronjonp wrote:

....

....
	       (print "MLINE has more than 2 points...")
....

If the idea is to add up the lengths of only 2-vertex [single-segment] MLINEs, and if there might be some with more than 2 that should not be included, you can limit the selection so that it ignores those entirely, without needing to determine it for each one in order to decide whether to add its length to the total:

 

(if (setq mlss (ssget "_X" '((0 . "MLINE") (72 . 2))))

Kent Cooper, AIA
Message 13 of 14

Sea-Haven
Mentor
Mentor
Accepted solution

This is his dwg I have previously supplied a quantity solution but it used explode mlines and divide answer by 2.

 

Nice idea (72 . 2) as a check. The Vl getcoordinates makes length easy .

SeaHaven_0-1648082275376.png

 

This has a next requirement as its a quantity request need to workout how many are 5 6 7 long etc

 

SeaHaven_0-1648082511617.png

 

I will respond to him via email.

 

Message 14 of 14

S_S_SS
Advocate
Advocate
Thanks sir about that
0 Likes