TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: diarmuid 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
-
Number of options, best bet IMO? Exploit DOS LIB (http://en.wiki.mcneel.com/default.aspx/McNeel/DOSlib.html#Functions).
-
Hi
An example
(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
)
@+
-
Be mindful that attempting to set the clipboard contents that route can throw a security warning.
-
;;往剪贴板写文字
;;copy str to the clipboard
(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
)
-
Welcome to the Swamp xshrimp :-)
-
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 (http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0221.mspx)) 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.
:)
-
Thanks to Patrick_35 and XShrimp, this has gone into my library --
(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 ...
(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.
:)
-
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.
@+
-
> Patrick_35
That's wonderful! Thank you :-)
-
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
; ! ***************************************************************************
;; ! 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
)
-
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.
-
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'~
-
Probably you are right
-
The code is correct. In W2k....
But in W8 not work.
Send safety messages, but the window isn't active.
is someone's idea?