Paste Special

Paste Special

Anonymous
Not applicable
4,023 Views
10 Replies
Message 1 of 11

Paste Special

Anonymous
Not applicable

Has anyone go a lisp for bring in unformatted text from a Microsoft Office application?

My current procedure is as follows:

 

In the office document, highlight the text to copy, click copy


In AutoCAD 'Pastespec'


Press the 'T' ket (for paste as Text)


(The text now comes in as an MTEXT object)


Click 'Explode' to reduce the entity to plain text

 

The Action Recorder doesn't work in this instance only remembering Pastespec

 

My code below only gets as far as the Paste Special dialogue box & no further

 

 

(defun C:PSTSP()
(command "PASTESPEC" "T" "T" )
(command "EXPLODE" "")
(princ)
)

 

 

Accepted solutions (1)
4,024 Views
10 Replies
Replies (10)
Message 2 of 11

hmsilva
Mentor
Mentor

Hi sbanister,

 

the 'Pastespec' command don't have a command line version...

 

Perhaps something like this will do the trick (untested)...

 

(defun c:demo (/ _GetClipBoardText pt str)

  (defun _GetClipBoardText (/ htmlfile result)

    ;;  Attribution: Reformatted version of
    ;;  post by Patrick_35 at theswamp.org.
    ;;
    ;;  See http://tinyurl.com/2ngf4r.

    (setq result
           (vlax-invoke
             (vlax-get
               (vlax-get
                 (setq htmlfile (vlax-create-object "htmlfile"))
                 'ParentWindow
               )
               'ClipBoardData
             )
             'GetData
             "Text"
           )
    )
    (vlax-release-object htmlfile)
    result
  )

  (if (and (setq str (_GETCLIPBOARDTEXT))
           (setq pt (getpoint "\nSpecify text start point: "))
      )
    (entmake
      (list
        (cons 0 "TEXT")
        (cons 100 "AcDbText")
        (cons 10 pt)
        (cons 40 (getvar "TEXTSIZE"))
        (cons 1 str)
        (cons 100 "AcDbText")
      )
    )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

Message 3 of 11

Anonymous
Not applicable

Hello again hmsilva

 

It does paste as text, however if more than 1 line of the Office application is copied (i.e. several rows from a table in Word or Excel) it pastes as one long

string instead of separate rows

 

Rows to be copied from Word.JPG

 

Result:

 

Result.JPG

 

 

Desired Result:

 

Desired Result.JPG

 

 

 

 

0 Likes
Message 4 of 11

hmsilva
Mentor
Mentor
Accepted solution

Hi sbanister,

I don't have Office in this old laptop, so, again untested...

 

(defun c:demo (/ _GetClipBoardText ent_last last_ent pt str)

  (defun _GetClipBoardText (/ htmlfile result)
    ;;  Attribution: Reformatted version of
    ;;  post by Patrick_35 at theswamp.org.
    ;;
    ;;  See http://tinyurl.com/2ngf4r.
    (setq result
           (vlax-invoke
             (vlax-get
               (vlax-get
                 (setq htmlfile (vlax-create-object "htmlfile"))
                 'ParentWindow
               )
               'ClipBoardData
             )
             'GetData
             "Text"
           )
    )
    (vlax-release-object htmlfile)
    result
  )

  (if (not (setq ent_last (entlast)))
    (progn
      (entmake '(
                 (0 . "POINT")
                 (100 . "AcDbEntity")
                 (100 . "AcDbPoint")
                 (10 . (0.0 0.0 0.0))
                )
      )
      (setq ent_last (entlast)
            last_ent ent_last
      )
    )
  )
  (if (and (setq str (_GETCLIPBOARDTEXT))
           (setq pt (getpoint "\nSpecify text start point: "))
      )
    (progn
      (entmake (list
                 '(0 . "MTEXT")
                 '(100 . "AcDbEntity")
                 '(100 . "AcDbMText")
                 (cons 10 pt)
                 (cons 1 str)
               )
      )
      (command "_.explode" "_L")
    )
  )
  (if last_ent
    (entdel last_ent)
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

Message 5 of 11

Anonymous
Not applicable

Excellent! It works exacty as I anticipated

 

10/10

0 Likes
Message 6 of 11

hmsilva
Mentor
Mentor

@Anonymous wrote:

Excellent! It works exacty as I anticipated

 

10/10


sbanister,
glad I could help!

Henrique

EESignature

0 Likes
Message 7 of 11

Jonathan3891
Advisor
Advisor
Could this be edited to paste a link?

Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 11

hmsilva
Mentor
Mentor

@Anonymous_dude wrote:
Could this be edited to paste a link?

Hi DSM_dude,

 

do you mean, attach a 'hyperlink' to an object, using the '_GetClipBoardText' function?

 

Henrique

EESignature

0 Likes
Message 9 of 11

Jonathan3891
Advisor
Advisor
No, not hyperlinks.

When the paste special dialog box is open, it gives you two radio buttons on the left. One of them is paste link.

I'm looking for a lisp that will select paste link then autocad entity. I thought maybe your lisp could be edited to do so.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 10 of 11

hmsilva
Mentor
Mentor

@Anonymous_dude wrote:
No, not hyperlinks.

When the paste special dialog box is open, it gives you two radio buttons on the left. One of them is paste link.

I'm looking for a lisp that will select paste link then autocad entity. I thought maybe your lisp could be edited to do so.

No, the previous code just read text strings from clipboard...

Paste link... I've never wrote any code using 'paste link', not even know if it will be possible using AUTO/Visual LISP, but, I'll see what I can do.

 

Henrique

EESignature

Message 11 of 11

m_badran
Advocate
Advocate

I'm waiting for this 

0 Likes