Author Topic: how do I add a variable to the windows clipboard?  (Read 15009 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
how do I add a variable to the windows clipboard?
« on: November 03, 2010, 12:59:22 PM »
Hello
I'm after a little bit of assistance please.

I'm trying to modify a distance inquiry lisp by alanjt.
The lisp stores the whole circle bearing (WCB) to a variable called #angle.

Currently I get an output to the commandline something like this:

Command: d
Specify first point: int of
Specify second point: int of
Delta X: -13.019, Delta Y: -24.195, Delta Z: -8.363
From: E = 500.040, N = 999.945 -> To: E = 487.021, N = 975.750
Slope Dist: 28.720m, Slope: -30.438% [From: 50.000m -> To: 41.637m]
WCB: 208d17'2", Horiz Dist: 27.476m

and I right click and copy " 208d17'2" ", which i then paste into another software program outside of autocad.
I'm just looking for a way to automate copying the " 208d17'2" " (the #angle variable) to the clipboard.

I thought I was onto something with:
;(command "text" "0,0" "" "" #Angle)
;(setq #angleent (entlast))
;(command "_copyclip" #angleent "")
;(command "erase" #angleent "")

but that was no good, it can be pasted back into autocad with pasteclip but it isn't stored within windows clipboard.

is this even possible?
the lisp is attached if its any assistance.

Thanks
Pads

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: how do I add a variable to the windows clipboard?
« Reply #1 on: November 03, 2010, 01:02:00 PM »
I mostly use these by MP:

Code: [Select]
;;  MP
;;  http://www.theswamp.org/index.php?topic=21764.msg263322#msg263322
(defun _SetClipBoardText ( text / htmlfile result )

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

    (setq result
        (vlax-invoke
            (vlax-get
                (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow)
               'ClipBoardData
            )
           'SetData  "Text"  text)
    )
    (vlax-release-object htmlfile)
    text
)
Code: [Select]
;;  MP
(defun _GetClipBoardText( / htmlfile result )

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

Be sure not to get a pie in your face :wink:

Pad

  • Bull Frog
  • Posts: 342
Re: how do I add a variable to the windows clipboard?
« Reply #2 on: November 03, 2010, 01:32:06 PM »
perfect!

had pie on my face but not because the variable wasn't a text string but because I couldn't figure out how to call it.
a little googling later and of course it's (_SETCLIPBOARDTEXT #angle)  :loco: I have a lot to learn!

Thanks Lee!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: how do I add a variable to the windows clipboard?
« Reply #3 on: November 03, 2010, 01:47:09 PM »
Thanks Lee, but to be honest I wouldn't use those, too much of a hack IMO which will likely be broken by future windows versions. Just download DOSLIb from www.mcneel.com and use the dos_clipboard function. There is no shame using a reputable and capable third party app, just productivity. Of course if you like pies ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: how do I add a variable to the windows clipboard?
« Reply #4 on: November 03, 2010, 03:49:21 PM »
Thanks Lee, but to be honest I wouldn't use those, too much of a hack IMO which will likely be broken by future windows versions. Just download DOSLIb from www.mcneel.com and use the dos_clipboard function. There is no shame using a reputable and capable third party app, just productivity. Of course if you like pies ...

I agree, using the html file is a hack - I use them mainly to create small functions which populate the clipboard with subfunctions I use regularly when writing code - it makes things a lot quicker as I don't have to go scouting through my subfunction library to find what I need...

They work well on Windows7, but, I agree that I wouldn't chance to use them in an application that I needed to be rock solid.

Lee
« Last Edit: November 03, 2010, 03:58:14 PM by Lee Mac »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: how do I add a variable to the windows clipboard?
« Reply #5 on: November 03, 2010, 04:05:14 PM »
exactly, appreciate your perspective Lee
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: how do I add a variable to the windows clipboard?
« Reply #6 on: November 04, 2010, 01:20:22 PM »
As MP stated, the best thing would be to use DosLib (which I already give options for in the routine). I'm curious, why are you still using that old version when I've updated it since to include all possible angles and work with all units.
http://www.theswamp.org/index.php?topic=30416.0

All you really need to do is add the line:
Code: [Select]
(and dos_clipboard (dos_clipboard #Angle)) and it should work.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Pad

  • Bull Frog
  • Posts: 342
Re: how do I add a variable to the windows clipboard?
« Reply #7 on: November 05, 2010, 05:02:37 AM »
Hello Alanjt,
thanks again for your routine.  Why because I changed your old routine to work with metric to 3 dec places and removed some of the angles which I didn't need.

with your latest routine I get this:
Delta X: 24.558, Delta Y: 21.828, Delta Z: 0.000
From: N=502.175, E=403.574 -> To: N=524.003, E=428.132
Rad: 0.727, Azm: 48d22'7", Grad: 53.7427g, Bear: N 41d37'53" E, Dist: 32.856

with your old modified routine I get this:
Delta X: 8.198, Delta Y: -9.439, Delta Z: 0.000
From: E = 504.138, N = 942.242 -> To: E = 512.336, N = 932.803
WCB: 139d1'30", Horiz Dist: 12.502m

and also because I never got round to updating, the old routine works fine for me right now.
Thanks for the tip with dosLib, but for now I'm going to carry on with the htmlfile hack.  Just because it's working which is the main thing.  I'm just a one man band so am my own administrator and if down the line it breaks I'll know where to look.

Maybe when I do get round to installing doslib i'll modify the routine to suiit.
Thanks for everyones help!
P

Pad

  • Bull Frog
  • Posts: 342
Re: how do I add a variable to the windows clipboard?
« Reply #8 on: November 05, 2010, 12:21:18 PM »
LE has put a coupe of clipboard functions here as well http://www.theswamp.org/index.php?topic=8140.0

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: how do I add a variable to the windows clipboard?
« Reply #10 on: November 05, 2010, 12:41:48 PM »
Hello Alanjt,
thanks again for your routine.  Why because I changed your old routine to work with metric to 3 dec places and removed some of the angles which I didn't need.

with your latest routine I get this:
Delta X: 24.558, Delta Y: 21.828, Delta Z: 0.000
From: N=502.175, E=403.574 -> To: N=524.003, E=428.132
Rad: 0.727, Azm: 48d22'7", Grad: 53.7427g, Bear: N 41d37'53" E, Dist: 32.856

with your old modified routine I get this:
Delta X: 8.198, Delta Y: -9.439, Delta Z: 0.000
From: E = 504.138, N = 942.242 -> To: E = 512.336, N = 932.803
WCB: 139d1'30", Horiz Dist: 12.502m

and also because I never got round to updating, the old routine works fine for me right now.
Thanks for the tip with dosLib, but for now I'm going to carry on with the htmlfile hack.  Just because it's working which is the main thing.  I'm just a one man band so am my own administrator and if down the line it breaks I'll know where to look.

Maybe when I do get round to installing doslib i'll modify the routine to suiit.
Thanks for everyones help!
P
Are those readings from the same two points? If so, I need to do some serious unit revising. I wasn't sure if I had it right and I never received any feedback.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Pad

  • Bull Frog
  • Posts: 342
Re: how do I add a variable to the windows clipboard?
« Reply #11 on: November 05, 2010, 01:40:50 PM »
no don't worry, different points  :-)

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: how do I add a variable to the windows clipboard?
« Reply #12 on: December 07, 2015, 03:26:23 PM »
Thanks Lee, but to be honest I wouldn't use those, too much of a hack ..... Just download DOSLIb from www.mcneel.com

As MP stated, the best thing would be to use DosLib ......

The opposing point of view is....what happens when you have a boatload of code that relies on DosLib (or any other compiled code where the source is N/A) and the developer stops developing it?
Yes, I know it has not happened with DosLib, but anything is possible.
Just something to think about. If it were taken away tomorrow, how much of your existing code would no longer work?




MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: how do I add a variable to the windows clipboard?
« Reply #13 on: December 07, 2015, 03:34:40 PM »
Actually the odds are MUCH higher that any solution based on the html hack would be broken before DOSLIB support went south, ergo my comments.

That said, if DOSLIB did go south all one need do is pen a function named dos_clipboard that honors the original calling signature and return value and poof, no issue.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: how do I add a variable to the windows clipboard?
« Reply #14 on: December 07, 2015, 03:40:41 PM »
Actually the odds are MUCH higher that any solution based on the html hack would be broken before DOSLIB support went south, ergo my comments.

That said, if DOSLIB did go south all one need do is pen a function named dos_clipboard that honors the original calling signature and return value and poof, no issue.

I wasn't so much talking about you or LeeMac or alanjt, et. al. but more about the casual lisp programmer who finds this thread and then proceeds to incorporate DosLib into all of his/her code.
The task of "pen a function named dos_clipboard" might be a challenge for a large class of lisp programmers,  (if not, then why use DosLib in the first place?).