Convert (vlax-get <MLine-object> 'coordinates) to LWPoly entity vertex list

Convert (vlax-get <MLine-object> 'coordinates) to LWPoly entity vertex list

Browning_Zed
Advocate Advocate
508 Views
3 Replies
Message 1 of 4

Convert (vlax-get <MLine-object> 'coordinates) to LWPoly entity vertex list

Browning_Zed
Advocate
Advocate

The function (vlax-get <vla-obj> 'Coordinates) applied to a multiline returns a list of coordinates of the format:
'(1.0 1.0 0.0 4.0 1.0 0.0 4.0 2.0 0.0)
How can I convert it to LWPolyline entity list format:
'((1.0 1.0) (4.0 1.0) (4.0 2.0))
That is, the resulting list must contain sublists of X and Y coordinates, and Z-coordinate must be removed.
Thanks in advance.

0 Likes
Accepted solutions (2)
509 Views
3 Replies
Replies (3)
Message 2 of 4

ronjonp
Advisor
Advisor
Accepted solution

Did you do some searching for this? This question has been asked and solved many times.

 

(defun _2dlst (l / r)
  (while l (setq r (cons (mapcar '+ l '(0 0)) r)) (setq l (cdddr l)))
  (reverse r)
)
(_2dlst '(1.0 1.0 0.0 4.0 1.0 0.0 4.0 2.0 0.0))

 

 

 

Message 3 of 4

Browning_Zed
Advocate
Advocate

Thanks, this is what I need. I tried to look for a solution to this problem, but I did not find it.

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Another way, just for fun [using (repeat) instead of (while) because the number of times is known, and (append) instead of (cons) so no reversing is needed]:

 

(defun XYLfromXYZ (lst)
  (repeat (/ (length lst) 3)
    (setq
      output (append output (list (list (car lst) (cadr lst))))
      lst (cdddr lst)
    )
  )
  output
)

 

(setq lst '(1.0 1.0 0.0 4.0 1.0 0.0 4.0 2.0 0.0))

Command: (XYLfromXYZ lst)
((1.0 1.0) (4.0 1.0) (4.0 2.0))

 

And another, using the Mline's entity name without the need to extract the 'Coordinates property:

 

(mapcar
  '(lambda (x) (cdr (reverse (cdr (reverse x)))))
  (vl-remove-if-not '(lambda (y) (= (car y) 11)) (entget MlineEntityName))
)

 

 

Kent Cooper, AIA