Jump to content

Recommended Posts

Posted

Hi,

I don't know anything about coding or how lisp is written, but I'm using this lisp to calculate all hatch area. I want to copy the result shown in the command line to the windows clipboard instead of select, copy and then paste the value to another document.

here it is the coding that I'm using:


(defun c:HT (/ sset i area obj)

  
(if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)
(progn
(prompt "\nSelect hatches: ")
(if (setq sset (ssget '((0 . "hatch"))))
(progn
(setq
i (1- (sslength sset))
area 0)
(while (>= i 0)
(setq
obj (vlax-ename->vla-object (ssname sset i))
area (+ area (vla-get-area obj)))
(setq i (1- i))) 
(prompt
(strcat
"\nTotal area = "
(if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))
(strcat
(rtos area 2)
" sq. in. ("
(rtos (/ area 144) 2)
" sq. ft.)")
(rtos area))))))))
(princ))

 

thanks for your help!

Posted

It could be something like this:

 

(defun C:HT (/ ctextc sset index area obj)

 (defun ctextc (stringa / html result)
  (if (= (type stringa) 'STR)
   (progn
    (setq html	(vlax-create-object "htmlfile")
	  result (vlax-invoke
		  (vlax-get (vlax-get html 'ParentWindow) 'ClipBoardData)
		  'setData
		  "Text"
		  stringa
		 )
    )
    (vlax-release-object html)
    result
   )
   nil
  )
 )
 
 (if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)
  (progn
   (prompt "\nSelect hatches: ")
   (if (setq sset (ssget '((0 . "HATCH"))))
    (progn
     (setq area 0)
     (repeat (setq index (sslength sset))
      (setq obj  (vlax-ename->vla-object (ssname sset (setq index (1- index))))
            area (+ area (vla-get-area obj))
      )
     )
    )
   )
  )
 )

 (princ (strcat
         "\nTotal area = "
         (if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))
	  (strcat (rtos area 2) " sq. in. (" (rtos (/ area 144) 2) " sq. ft.)")
	  (rtos area)
         )
        )
 )
 
 (ctextc (vl-string-subst "," "." (rtos area)))
 ;;; (ctextc (rtos area))

 (princ)	
)

 

The result of the area obtained is available by simply pasting the content (Ctrl+V) on a command line, Word, Excel, etc...
The heart of the program is the ctextc function that captures the result and makes it available immediately.
Just one thing, in my country we use commas for decimals, so if that's not your problem just put the three commas on the previous line, like this:

 

;;;(ctextc (vl-string-subst "," "." (rtos area)))
(ctextc (rtos area))

 

  • Agree 1
  • Thanks 1
Posted

Thank you so much! This was so helpful and did exactly what I wanted.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...