Jump to content

Convert mleader to text


daniil

Recommended Posts

Here is the simplest way:

(defun c:ML2TXT (/ en ss)
   (if (and
          ; Mark the last entity in the drawing.
          (setq en (entlast))
          ;; Select the Multileader(s)
          (setq ss (ssget '((0 . "MULTILEADER"))))
       )
       (progn
          (command "._explode" ss);; Explodes the mleader
          ;; loops to get all new entities created after explode.
          (while (setq en (entnext en))
             ;; if a line, polyline or solid, delete it.
             (if (wcmatch (cdr (assoc 0 (entget en))) "*LINE,SOLID")(entdel en))
          )
       ) 
   )
   (princ)
)

 

Link to comment
Share on other sites

20 minutes ago, rkmcswain said:

I just tried it, on a selection set of 9 multileaders. It only operates on one of the 9 in the selection set.

@rkmcswain Thank you - I thought that it would gather all the new entities from the explode command without resetting the last entity. Wrong!

 

Here's is a new solution: Tested on multiple MLEADERS. I had to change it to iterate through the selection set and explode 1 MLEADER at a time, get the new entities and delete them.

(defun c:ML2TXT (/ en ss cnt)
   (if (and
          ; Mark the last entity in the drawing.
          (setq en (entlast))
          ;; Select the Multileader(s)
          (setq ss (ssget '((0 . "MULTILEADER"))))
       )
       (repeat (setq cnt (sslength ss))
          ;; Get 1 MLEADER from the selection set.
          (setq en (ssname ss (setq cnt (1- cnt))))
          ;; Explode the MLEADER
          (command "._explode" en)
          ;; Loop through the newly created entities.
          (while (setq en (entnext en))
             ;; if a line, polyline or solid, delete it.
             (if (wcmatch (cdr (assoc 0 (entget en))) "*LINE,SOLID")(entdel en))
          )
          (setq en (entlast))
       ) 
   )
   (princ)
)

 

Link to comment
Share on other sites

On 26/02/2021 at 20:46, pkenewell said:

@rkmcswain Thank you - I thought that it would gather all the new entities from the explode command without resetting the last entity. Wrong!

 

Here's is a new solution: Tested on multiple MLEADERS. I had to change it to iterate through the selection set and explode 1 MLEADER at a time, get the new entities and delete them.


(defun c:ML2TXT (/ en ss cnt)
   (if (and
          ; Mark the last entity in the drawing.
          (setq en (entlast))
          ;; Select the Multileader(s)
          (setq ss (ssget '((0 . "MULTILEADER"))))
       )
       (repeat (setq cnt (sslength ss))
          ;; Get 1 MLEADER from the selection set.
          (setq en (ssname ss (setq cnt (1- cnt))))
          ;; Explode the MLEADER
          (command "._explode" en)
          ;; Loop through the newly created entities.
          (while (setq en (entnext en))
             ;; if a line, polyline or solid, delete it.
             (if (wcmatch (cdr (assoc 0 (entget en))) "*LINE,SOLID")(entdel en))
          )
          (setq en (entlast))
       ) 
   )
   (princ)
)

@pkenewell It is work very strange because this lisp delete polylines too

 

Link to comment
Share on other sites

On 3/2/2021 at 3:05 AM, daniil said:

@pkenewell It is work very strange because this lisp delete polylines too

 

Oops! Here is a correction: Tested with other polylines

(defun c:ML2TXT (/ en en2 ss)
   (if (and
          ; Mark the last entity in the drawing.
          (setq en (entlast))
          ;; Select the Multileader(s)
          (setq ss (ssget '((0 . "MULTILEADER"))))
       )
       (repeat (setq cnt (sslength ss))
          ;; Get 1 MLEADER from the selection set.
          (setq en2 (ssname ss (setq cnt (1- cnt))))
          ;; Explode the MLEADER
          (command "._explode" en2)
                    ;; Loop through the newly created entities.
          (while (setq en (entnext en))
             ;; if a line, polyline or solid, delete it.
             (if (wcmatch (cdr (assoc 0 (entget en))) "*LINE,SOLID")(entdel en))
          )
          (setq en (entlast))
       ) 
   )
   (princ)
)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...