Author Topic: Copy value to Clipboard?  (Read 12539 times)

0 Members and 1 Guest are viewing this topic.

Craig Davis

  • Guest
Copy value to Clipboard?
« on: November 05, 2007, 05:50:39 PM »
I did a quick search but nothing really fitted to what I want to do.

I have cross sections and I want to calculate volumes for excavation and fill etc. The design software I use should do this but it has a few limitations unfortunately and I'm calculating some of the volumes from first principles.

I'm wanting to paste the area value of a closed polygon to the clipboard so I can simply paste it into a cell in excel. In the past I've highlighted the value in the command line and then ctrlC and then gone to excel and ctrlP.

I'd like to try and fine tune the process if I can. I have a Hect program that I use to calculate catchment areas which I should be able to modify easy enough.

Has anyone got a program that simply copies a variable from Lisp into the windows clipboard?

Thanks

Craig (Under the pump)

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Copy value to Clipboard?
« Reply #1 on: November 05, 2007, 06:48:24 PM »
try doslib and it's (dos_clipboard [string])

Craig Davis

  • Guest
Re: Copy value to Clipboard?
« Reply #2 on: November 05, 2007, 07:16:22 PM »
Thanks for that.

I think that is exactly what I want.

What would we do without the great resources out there.

Gotta love the sharing community out there. :-)

Thanks.

Craig

SomeCallMeDave

  • Guest
Re: Copy value to Clipboard?
« Reply #3 on: November 05, 2007, 07:45:22 PM »
Here is a little routine that I cobbled together using DosLib to cut/paste various quantities based on a selection set.

It pops a dialog that lets the user choose Area (yards or acres), total length (perimeter), or count of entities.

I use if for doing take-offs.

Maybe you can modify it to your needs.

Code: [Select]
(defun c:total()
   (if (= "17" (substr (getvar "acadver") 1 2))
    (if (not (member "doslib17.arx" (arx)))
      (if (findfile "doslib17.arx")
        (arxload "doslib17")

      )
    )
    ;else
    (if (not (member "doslib16.arx" (arx)))
       (if (findfile "doslib16.arx")
          (arxload "doslib16")
       )
    );else     
   );outer if
 

   ;(arxload "doslib16")
   (setq e1 (car (entsel "\nSelect Representative Object "))
         e1List (entget e1)
         lay1 (assoc 8 e1list)
         Laystr (cdr lay1)
         col1 (assoc 62 e1list)
         type1 (assoc 0 e1list)
   );setq
   (if (not col1)
      (setq col1 (cons 62 256))
   
   );if
   (setq ss1 (ssget "x" (list type1 lay1 col1)))

   (totalMe ss1 LayStr)
   (prin1)
)

(defun totalMe(pSelSet pLayName / ss1 sumarea sumperim count)
 (setq ss1 pSelSet
       sumarea 0
       sumperim 0
       count 0
  )
  (repeat (sslength ss1)
     (setq ent1 (ssname ss1 count))
     (command "area" "o" ent1)
     (setq Adist (getvar "perimeter"))
     (setq AArea (getvar "area"))
     (setq sumperim (+ sumperim Adist))
     (setq sumarea (+ sumarea AArea))
     (setq count (+ count 1))
  )
  (princ (strcat "\nLayer Name - " pLayName))
  (princ (strcat "\nTotal Objects Counted=" (itoa (sslength ss1)))) 
  (princ (strcat "\nArea= " (rtos sumarea 2 2) " sf = " (rtos (/ sumarea 43560) 2 2) " acres"))
  (princ (strcat "\n" (rtos (/ sumarea 9.0) 2 2) " yd2"))
  (princ (strcat "\nPerimter= " (rtos sumperim 2 2)))
  (setq yardageStr (rtos (dkb_round (/ sumarea 9.0) 5) 2 0)
        acreStr (rtos (dkb_round (/ sumarea 43560.0) 0.1) 2 1)
        perimStr (rtos (dkb_round sumperim 5) 2 0)
        CountStr (itoa (sslength ss1))
        buttons (list "Yardage" "Acreage" "Length" "Count" "None")
        BoxText "Which Quantity should be sent to Clipboard?"
  )
  (setq msgboxResult (dos_msgboxex BoxText (strcat "Items on Layer-" pLayName) buttons 4))
  (cond
     ((= msgboxResult 0)
           (dos_clipboard yardageStr)
     );0
     ((= msgboxResult 1)
           (dos_clipboard acrestr)
     );1
     ((= msgboxResult 2)
           (dos_clipboard perimstr)
     );2
     ((= msgboxResult 3)
           (dos_clipboard CountStr)
     );3
     ((= msgboxResult 4)
           (dos_clipboard "")
     );3
     
     (t
         (dos_clipboard "")   
     );t
 
  );cond
 
 
  (prin1)
)


Craig Davis

  • Guest
Re: Copy value to Clipboard?
« Reply #4 on: November 05, 2007, 08:21:35 PM »
I'll take a look at it thanks.

It will probably help with the problem of having to add a couple of different polyline areas together if they're not in one single area.

It's very much appreciated.

VVA

  • Newt
  • Posts: 166
Re: Copy value to Clipboard?
« Reply #5 on: November 06, 2007, 04:54:34 AM »
This is my some functions
Code: [Select]
(vl-load-com)
;| ! ***************************************************************************
;; !                           copyToclipboard
;; ! ***************************************************************************
;; ! Function : Copy text to clipboard
;; ! Argument : 'str'     - String
;; ! Returns  : nil
;; ! ****************************************************************************|;

(defun copyToclipboard ( str / ieobj)
  (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
)


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Copy value to Clipboard?
« Reply #6 on: November 06, 2007, 07:03:32 AM »
Ha, great minds think alike VVA!! I went that route too, but newer versions of Internet Explorer (IE) detect the abuse of their clipboard and intercept with a "Do you want this web page to access your clip board?" dialog prompt. Even worse, said dialog may be hidden behind the AutoCAD session, so it may appear AutoCAD has gone 404 (minimize all windows and poof, there the bugger is). So in my mind it's an interesting but completely unusable / unreliable technique, and why I opted not to post it. I'm guessing the technet article is a couple years old and predates versions of IE which attempt to be more immune to hostiles.

This is my experience anyway, coders beware; cheers.

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

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Copy value to Clipboard?
« Reply #7 on: November 06, 2007, 12:37:08 PM »
Maybe I'm missing something but .... what about LE's arx application?

[ http://www.theswamp.org/index.php?topic=13289.msg161064#msg161064 ]
TheSwamp.org  (serving the CAD community since 2003)

Craig Davis

  • Guest
Re: Copy value to Clipboard?
« Reply #8 on: November 06, 2007, 07:06:10 PM »
Maybe I'm missing something but .... what about LE's arx application?

[ http://www.theswamp.org/index.php?topic=13289.msg161064#msg161064 ]


I did find that thread and I decided to go with the DOSLib as it sounded like LE's app wasn't going to be supported in the future. I also didn't know how to apply it in the LISP I was writting.

Code: [Select]
(defun trap (errmsg)
  (prompt "\nAn error has occured.")
  (command "undo" "b")
  (setvar "osmode" os)
  (vlax-release-object theobj) ;release the obj vla-object
  (setq *error* temperr)
)

(defun c:XsectArea (/ temperr trap ss1 count sumarea AArea ent1 sqmarea)
  (setq ss1 (ssget '((0 . "HATCH"))))
  (setq count 0)
  (setq sumarea 0)
  (setq AArea 0)
  (repeat (sslength ss1)
    (setq ent1 (ssname ss1 count))
    (command "area" "o" ent1)
    (setq AArea (getvar "area"))
    (setq sumarea (+ sumarea AArea))
    (setq count (+ count 1))
  )
  (setq sqmarea (/ sumarea 200))
  (princ (strcat "\nArea= "
(rtos sumarea 2 3)
" = "
(rtos sqmarea 2 3)
" Sqm"
)
  )
  (setq sqmarea (rtos sqmarea 2 3))
  ;(command "text" "" "" 0 sqmarea)
  (dos_clipboard sqmarea)
    (setq *error* temperr)
  (prin1)
)

That's my very simple program that works for the moment. It's enough to help automate what I want to do for now. I create a hatch pattern in a layer for each area I want to sum and paste in the excel spreadsheet. It will do for now.

I would like to improve it later on but hopefully the software developer will fix the annoying design problems with the volumes etc soon.

I was wanting to grab the Area property of the hatch rather than using the command "area" but couldn't find a way of doing it. I did see that the help within Vlisp said for the Area to use the "Hatch objects: Note To access this property, use the IAcadHatch2 interface." but I couldn't find how to use that.

I'm trying not to get too tied down in perfecting it even though it's doing what I need it to for now. :-)