; dimtoxcl selected dimensions in a row sorts left to right and placed into Excel row ; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-can-i-copy-the-selected-dimension-from-cad-to-excel/m-p/13010702/thread-id/471462 (defun c:dimtoxcl (/ lst opn_xcl sortListofSublistsbyItemX ss) (vl-load-com) ; sortListofSublistsbyItemX - sorts list of coordinates ; https://forums.augi.com/showthread.php?137837-Sort-Selectionset-by-X-coord ; sorts list of coordinates ; Arguments: ; lstOfSublists = lists containing x,y coordinates ; intItem = coordinate to sort by (defun sortListofSublistsbyItemX (lstOfSublists intItem) (vl-sort lstOfSublists '(lambda (X Y) (< (nth intItem X) (nth intItem Y)))) ) ; sortListofSublistsbyItemX ; (opn_xcl lst) ; Argument: ; lst-arg = list of items to populate ; modified from: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-text-to-excel/m-p/8655108#M382433 ; (defun opn_xcl (lst-arg / column row xlCells xlSheet xlSheets xlBook xlBooks xlApp) (if (setq xlApp (vlax-get-or-create-object "Excel.Application")) (progn (setq xlBooks (vlax-get-property xlApp "Workbooks") xlBook (vlax-invoke-method xlBooks "Add") xlSheets (vlax-get-property xlBook "Sheets") xlSheet (vlax-get-property xlSheets "Item" 1) xlCells (vlax-get-property xlSheet "Cells") column 1 row 1 ) (vla-put-visible xlApp :vlax-true) ; cycl through the list (foreach itm lst-arg (vlax-put-property xlCells "Item" row column (vl-princ-to-string itm)) (setq column (1+ column)) ; goto next column ) ; foreach ; release objects (mapcar (function (lambda (x) (vl-catch-all-apply (function (lambda () (progn (vlax-release-object x) (setq x nil) ) ) ) ) ) ) (list xlCells xlSheet xlSheets xlBook xlBooks xlApp) ) ; mapcar (princ "\nExcel Cells Successfully Populated.") ) ; progn (princ "\nExcel Failed to Open.") ) ; if (princ) ) ; defun opn_xcl ; ; main function ; (princ"\nPick Dimensions...") (if (setq ss (ssget '((0 . "DIMENSION")))) (progn (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) ; convert selection to list of entities (setq ss (mapcar '(lambda (X)(cons X (list (getpropertyvalue X "TextPosition/X") (getpropertyvalue X "TextPosition/Y") X))) ss)) ; assoc to entities dimension text x,y,z ins points (setq ss (sortListofSublistsbyItemX ss 1)) ; sort x=left->right (foreach itm ss (setq lst (append lst (list (rtos (getpropertyvalue (car itm) "Measurement") 2 (getpropertyvalue (car itm) "Dimdec"))))) ) (if lst (opn_xcl lst)(princ"\nNo Dimension Values Found.")) ) ; progn (princ"\nNo Dimensions Selected.") ) ; if (princ) ) ; defun