moh.zizo Posted September 21, 2021 Posted September 21, 2021 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! Quote
confutatis Posted September 22, 2021 Posted September 22, 2021 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)) 1 1 Quote
moh.zizo Posted September 22, 2021 Author Posted September 22, 2021 Thank you so much! This was so helpful and did exactly what I wanted. Quote
BIGAL Posted September 23, 2021 Posted September 23, 2021 The other document is it excel or word ? Can be done. Quote
Recommended Posts
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.