Lisp to copy mtext to clipboard in one step

Lisp to copy mtext to clipboard in one step

mpa-la
Advocate Advocate
13,630 Views
41 Replies
Message 1 of 42

Lisp to copy mtext to clipboard in one step

mpa-la
Advocate
Advocate

Can anyone direct me to a lisp that will copy all the text inside an mtext entity by clicking on the entity, so that I can paste it into excel?  I grow tired of double clicking the text, ctrl A, ctrl C, then ctrl V into Excel.  Just want to cut down the number of keystrokes for something I have to do a lot.  Thanks!

0 Likes
Accepted solutions (2)
13,631 Views
41 Replies
Replies (41)
Message 41 of 42

mhy3sx
Enthusiast
Enthusiast

Hi Sea-Haven. I use this code to copy a part of mtext and paste it inside other mtext so Stripmtext will not Help.

 

Is it possible to combine  Stripmtext command with this

 

(defun c:foo( / en tx html) 
  
  (and (setq en (ssget ":S" '((0 . "*MTEXT"))))
       (setq en (ssname en 0))
       (setq en (vlax-ename->vla-object en))
       (vlax-property-available-p en 'textstring)
       (setq tx (vla-get-textstring en))
	    (setq tx (substr tx 1 (1- (vl-string-search "=" tx))))
       (vlax-invoke (vlax-get (vlax-get (setq html (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" tx)
       (vlax-release-object html)
       )
  
  (princ)
)

 

and the paste text be clear from all formatting?

 

Thanks

0 Likes
Message 42 of 42

Sea-Haven
Mentor
Mentor

Look at  UnFormat String | Lee Mac Programming (lee-mac.com)

You have 

(setq tx (vla-get-textstring en))

 So 

(setq tx (LM:UnFormat tx T))

At start of code 

(if (not LM:UnFormat)(load "Lee-Mac-unformat"))

You need to save the lisp into a support directory with a name as suggested.

0 Likes