I am looking for a LISP program that will allow me to select multiple dimensions, copy them to the clipboard, and paste into Excel in the following format (include "=")
=dimensions1+dimensions2+dimensions3+.......+dimensionsn
The command should have the following prompts:
1. Select dimensions in order by click then hit the space bar to finish the command and it auto copy the result to Clipboard
2. Then I go over to an open excel file and CTRL+V to paste the result
Results must be calculated in Excel, not on autocad
Is this possible? If not could someone suggest an alternative such that I can easily transfer these dimensions to a preexisting excel file?
Solved! Go to Solution.
Solved by kajanthangavel. Go to Solution.
Solved by kajanthangavel. Go to Solution.
I used this code but got an error
--------------------------------------------------------------
(defun c:copydimsexcel2 ()
(setq dimlst '())
(setq total 0.0)
(setq dimstr "")
(prompt "\nSelect dimensions in order by clicking. Press spacebar to finish and copy the result to clipboard:\n")
(while
(setq dim (car (entsel "\nSelect dimension: ")))
(if (and (eq (cdr (assoc 0 (entget dim))) "DIMENSION")
(not (member dim dimlst)))
(progn
(setq dimlst (cons dim dimlst))
(setq dimval (cdr (assoc 42 (entget dim))))
(setq total (+ total dimval))
(setq dimstr (strcat dimstr (rtos dimval) "+"))))
)
(setq dimstr (substr dimstr 1 (- (strlen dimstr) 1)))
(setq result (strcat "=" dimstr))
(vl-cmdf "CLIPBOARD" "SET" result)
(prompt "\nResult copied to clipboard. Paste into Excel using CTRL+V.")
(princ)
)
Here it is.
(vl-load-com) (defun c:Dims2Clip ( / s pt tx html) ; Copy Text To Clipboard (and (princ "\nSelect dimensions,") (setq s (ssget '((0 . "DIMENSION")))) (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) (setq s (mapcar '(lambda (e / s) (if (not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list e "Measurement"))))) x)) s)) (setq s (mapcar '(lambda (x) (atoi x)) s)) (setq s (strcat "=" (substr (apply 'strcat (mapcar '(lambda (x) (strcat "+" x)) s)) 2))) (princ "\nClipboard: ") (princ s) (vlax-invoke (vlax-get (vlax-get (setq html (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" s) (vlax-release-object html) ) (princ) )
Try This,
(vl-load-com)
(defun c:Dims2Clip ( / ss d a tx html c) ; Copy Text To Clipboard
(princ "\nSelect dimensions,")
(if (and (setq ss (ssget '((0 . "DIMENSION"))) x 0.))
(repeat (setq i (sslength ss))
(setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq a (vlax-get-property o 'Measurement))
(setq d (cons a d))
)
)
(foreach c d
(setq x (+ c x))
)
(princ x)
(vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'SetData "Text" (rtos x))
(vlax-release-object htmlfile)
(princ)
)
Acad, Bricscad and others can talk to Excel so could write the answers into individual cells then use Excel sum to add them up. That would give you a presentation of the values picked. No need for copy and paste, Cad opens Excel and fills in the cells. Is that what you want.
Try this.
(vl-load-com)
(defun c:Dims2Clip ( / ss d a htmlfile c b) ; Copy Text To Clipboard
(princ "\nSelect dimensions,")
(if (and (setq ss (ssget '((0 . "DIMENSION"))) x 0.))
(repeat (setq i (sslength ss))
(setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq a (vlax-get-property o 'Measurement))
(setq d (cons a d))
)
)
(foreach c d
(setq x (+ c x))
)
(setq b (strcat "=" (substr (apply 'strcat (mapcar '(lambda (x) (strcat "+" (rtos x))) d)) 2)))
(princ (rtos x))(princ b)
(vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'SetData "Text" b)
(vlax-release-object htmlfile)
(princ)
)
Thank you ВeekeeCZ I got ideas from your code.
I want to change the result in a different way, the result is a formula that calculates the average value and is still automatically copied to the clipboard like the lisp above.
For example
=(dimension_1 + dimension _2 + dimension _3 + .... + dimension_2)/n
Example 1:
=(2000+3000+1000+4000)/4
Example 2:
=(2000+3000+1000)/3
Can someone help me?
Try this,
(vl-load-com)
(defun c:Dims2Clip_average ( / ss d a htmlfile c b)
(princ "\nSelect dimensions,")
(if (setq ss (ssget '((0 . "DIMENSION"))))
(repeat (setq i (sslength ss))
(setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq a (vlax-get-property o 'Measurement))
(setq d (cons a d))
)
)
(setq e (apply '+ (mapcar '(lambda (x) x) d)))
(setq b (strcat "=(" (substr (apply 'strcat (mapcar '(lambda (x) (strcat "+" (rtos x 2 0))) d)) 2) ")/" (rtos (sslength ss) 2 0)))
(princ (rtos (/ e (sslength ss)) 2 0))(princ b)
(vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'SetData "Text" b)
(vlax-release-object htmlfile)
(princ)
)
Can't find what you're looking for? Ask the community or share your knowledge.