Jump to content

OneMtext.lsp or Text2MTextV2-0.lsp but in alphabetical order


fefaleite

Recommended Posts

Hi, I found OneMtext.lsp and Text2MTextV2-0.lsp which are both very useful for my needs, but I wish that the contents could be set to sort by alphabetical order. Can anybody help me or point me in the direction of how to modify the lisp so I can have this result? 
Thank you

OneMtext.lsp Text2MTextV2-0.lsp

Edited by fefaleite
Link to comment
Share on other sites

(defun 1MT (break / *error* done e objlst obj wid str strllen strlist) ; <- add these 2 variable name

.......................................................
      (setq str (vla-get-TextString obj))
      ; Insert these lines below this line.
      (setq strlist (list str))
      (foreach x (cdr objlst)
        (setq str (vla-get-TextString x))
        (setq strlist (cons str strlist))
      ); foreach
      (setq strlist (vl-sort strlist '<))
      (foreach x (cdr objlst)
        (vla-delete x)
      )
      (setq str (car strlist))
      (setq strlist (cdr strlist))
      (setq strllen (length strlist))
      (repeat strllen
        (setq str (strcat str break (car strlist)))
        (setq strlist (cdr strlist))
      )
      ; up to this line
      (vla-put-TextString obj str)

 

This is a modification of 1MT.

Just add these lines in defun 1MT.

 

==================================================================================

or 

 

You can do this by creating a new command by adding the original, ascending sort, and descending sort options.

 

 

first, Add 0 one by one to the original 3 commands

and add sort, reverse sort commands

; original 
(defun C:1MT0 (); all in one paragraph -- 1 space between, no Enter
  (1MT " " 0); Space for 'break' argument in 1MT
  (princ)
)
(defun C:1MT1 (); new paragraph for each object's content -- 1 Enter
  (1MT "\\P" 0); Enter for 'break' argument in 1MT
  (princ)
)
(defun C:1MT2 (); blank line & new paragraph for each object's content -- 2 Enters
  (1MT "\\P\\P" 0); 2 Enters for 'break' argument in 1MT
  (princ)
)
; sort (Ascending)
(defun C:1MTS0 () (1MT " " 1) (princ))
(defun C:1MTS1 () (1MT "\\P" 1) (princ))
(defun C:1MTS2 () (1MT "\\P\\P" 1) (princ))
; reverse sort (descending)
(defun C:1MTRS0 () (1MT " " 2) (princ))
(defun C:1MTRS1 () (1MT "\\P" 2) (princ))
(defun C:1MTRS2 () (1MT "\\P\\P" 2) (princ))

 

then, add sortoption to argument

(defun 1MT (break sortoption / *error* done e objlst obj wid str strllen strlist)

 

 

then modify the above code by adding (cond) like this.

      (setq str (vla-get-TextString obj))
      ; Insert these lines below this line.
      (cond 
        ((= sortoption 0)
        )
        ((or (= sortoption 1) (= sortoption 2))
          (setq strlist (list str))
          (foreach x (cdr objlst)
            (setq str (vla-get-TextString x))
            (setq strlist (cons str strlist))
          ); foreach
          (cond 
            ((= sortoption 1)
              (setq strlist (vl-sort strlist '<))
            )
            ((= sortoption 2)
              (setq strlist (vl-sort strlist '>))
            )
          )
          
          (foreach x (cdr objlst)
            (vla-delete x)
          )
          (setq str (car strlist))
          (setq strlist (cdr strlist))
          (setq strllen (length strlist))
          (repeat strllen
            (setq str (strcat str break (car strlist)))
            (setq strlist (cdr strlist))
          )  
        )
        (t
        )
      )
      ; up to this line
      (vla-put-TextString obj str)

 

Edited by exceed
  • Like 2
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...