Author Topic: copy to the clipboard via lisp  (Read 30809 times)

0 Members and 1 Guest are viewing this topic.

diarmuid

  • Bull Frog
  • Posts: 417
copy to the clipboard via lisp
« on: March 06, 2008, 05:12:47 AM »
Is it possible to copy a string from AutoCAD to the clipboard via a lisp expression, so that it can be inserted into another application just by pasting into it (excel).

Thanks in advance
If you want to win something run the 100m, if you want to experience something run a marathon

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: copy to the clipboard via lisp
« Reply #1 on: March 06, 2008, 06:25:15 AM »
Number of options, best bet IMO? Exploit DOS LIB.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: copy to the clipboard via lisp
« Reply #2 on: March 06, 2008, 11:16:30 AM »
Hi

An example

Code: [Select]
(defun GetClipText(/ html result)
  (setq html (vlax-create-object "htmlfile")
result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'GetData "Text")
  )
  (vlax-release-object html)
  result
)

@+

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: copy to the clipboard via lisp
« Reply #3 on: March 06, 2008, 11:20:13 AM »
Be mindful that attempting to set the clipboard contents that route can throw a security warning.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

xshrimp

  • Mosquito
  • Posts: 14
Re: copy to the clipboard via lisp
« Reply #4 on: March 07, 2008, 10:19:28 AM »
;;往剪贴板写文字
;;copy str to the clipboard
Code: [Select]
(defun setClipText(str / html result)
(if (= 'STR (type str))
  (progn
  (setq html   (vlax-create-object "htmlfile")
        result (vlax-invoke (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData) 'setData "Text" str)
  )
  (vlax-release-object html)
   str
   )
 );end if
)
abc

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: copy to the clipboard via lisp
« Reply #5 on: March 07, 2008, 10:50:22 AM »
Welcome to the Swamp xshrimp  :-)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: copy to the clipboard via lisp
« Reply #6 on: March 07, 2008, 11:03:55 AM »
2 things --

(1) Welcome to the swamp xshrimp, nice entry.

(2) Apologies to Patrick / all. I could have sworn I had read in Technet a year or so ago (no mention here) that going this route (ie abusing an html object or iexplorer) would throw a security alert, but I've run a couple tests and have seen no such alert. So my apologies and nod for job well done.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: copy to the clipboard via lisp
« Reply #7 on: March 07, 2008, 01:27:14 PM »
Thanks to Patrick_35 and XShrimp, this has gone into my library --

Code: [Select]
(defun _SetClipBoardText ( text / htmlfile result )

    ;;  Caller's sole responsibility is to pass a
    ;;  text string. Anything else? Pie in face.

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

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

    (vlax-release-object htmlfile)

    text

)

and ...

Code: [Select]
(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

)

Thanks folks.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: copy to the clipboard via lisp
« Reply #8 on: March 07, 2008, 02:49:57 PM »
It is a pleasure to share and a fair return that gave me the website  :-)

To alert post, I asked him when read, but as I had no warning message, I expected to see more.

Prevention is better than cure.

@+

ASMI

  • Guest
Re: copy to the clipboard via lisp
« Reply #9 on: March 08, 2008, 03:06:23 PM »
> Patrick_35

That's wonderful! Thank you  :-)

VVA

  • Newt
  • Posts: 166
Re: copy to the clipboard via lisp
« Reply #10 on: March 10, 2008, 10:10:38 AM »
I do not know, that it is better: to create object "htmlfile" or " InternetExplorer. Application ". And can be all the same.
I reached up to clipboard through InternetExplorer. Application
Code: [Select]
;  ! ***************************************************************************
;; !                           copyToclipboard
;; ! ***************************************************************************
;; ! Function : Copy text to clipboard
;; ! Argument : 'str'     - String
;; ! Returns  : nil
;; ! ****************************************************************************

(defun copyToclipboard ( str / ieobj cbrd)
  (setq ieobj (vlax-get-or-create-object
                      "InternetExplorer.Application"
                      )
             )
 (vlax-invoke ieobj 'navigate2 "about:blank")
 (vlax-invoke
(setq cbrd (vlax-get (vlax-get (vlax-get ieobj 'document) 'parentwindow)
'clipboarddata
))
'setdata
"text"
str
)
(vlax-release-object ieobj) 
)

;  ! ***************************************************************************
;; !                           Clearclipboard
;; ! ***************************************************************************
;; ! Function : Clear clipboard
;; ! Argument : nil
;; ! Returns  : nil
;; ! ****************************************************************************;

(defun Clearclipboard (  / ieobj)
  (setq ieobj (vlax-get-or-create-object
                      "InternetExplorer.Application"
                      )
             )
 (vlax-invoke ieobj 'navigate2 "about:blank")
 (vlax-invoke
(vlax-get (vlax-get (vlax-get ieobj 'document) 'parentwindow)
'clipboarddata
)
'clearData
"text"
)
(vlax-release-object ieobj) 
)

;  ! ***************************************************************************
;; !                           Getclipboard
;; ! ***************************************************************************
;; ! Function : Return text string from clipboard
;; ! Argument : nil
;; ! Returns  : string
;; ! ****************************************************************************

(defun Getclipboard ( / ieobj str)
  (setq ieobj (vlax-get-or-create-object
                      "InternetExplorer.Application"
                      )
             )
 (vlax-invoke ieobj 'navigate2 "about:blank")
 (setq str(vlax-invoke
(vlax-get (vlax-get (vlax-get ieobj 'document) 'parentwindow)
'clipboarddata
)
'getData
"text"
))
(vlax-release-object ieobj)
  str
)


VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: copy to the clipboard via lisp
« Reply #11 on: March 11, 2008, 03:53:29 PM »
I do not know, that it is better: to create object "htmlfile" or " InternetExplorer. Application ". And can be all the same.
actually it's not the same. method presented by xshrimp is preferrable, because InternetExplorer may not always be present on the system. in my case it was removed with the help of nLite, so you code is not working.

Fatty

  • Guest
Re: copy to the clipboard via lisp
« Reply #12 on: March 11, 2008, 04:37:07 PM »
I do not know, that it is better: to create object "htmlfile" or " InternetExplorer. Application ". And can be all the same.
actually it's not the same. method presented by xshrimp is preferrable, because InternetExplorer may not always be present on the system. in my case it was removed with the help of nLite, so you code is not working.
FYI
The same thing on my machine
I have A2008 and IE7 and VVA's code
is not working for me too

~'J'~


VVA

  • Newt
  • Posts: 166
Re: copy to the clipboard via lisp
« Reply #13 on: March 12, 2008, 10:24:48 AM »
Probably you are right

ttechnik

  • Newt
  • Posts: 24
Re: copy to the clipboard via lisp
« Reply #14 on: March 09, 2015, 04:41:31 AM »
The code is correct. In W2k....
But in W8 not work.
Send safety messages, but the window isn't active.

is someone's idea?



Tamás Csepcsényi