nod684 Posted February 23, 2023 Posted February 23, 2023 Best way is to convert those texts, numbers, etc to attribute then you can use data extraction to export the data to excel. Quote
devitg Posted February 23, 2023 Posted February 23, 2023 11 hours ago, Cecep said: Drawing1.xlsx 8.91 kB · 1 download Drawing1.dwg 84.04 kB · 2 downloads Please state about x and y coordinates , will it be the name insertion point? Quote
j2lstaples Posted February 23, 2023 Posted February 23, 2023 (edited) I asked this question a few days ago. I was creating a custom csv (comma-separated values) to use on Excel. Most of the time you can just use ATTOUT in the command line and select your blocks - which only works for blocks with attributes. What I had solved was to also include dynamic properties of custom blocks or anonymous blocks. I didn't include the handle and the anonymous block name but with a few tweaking it could act exactly like ATTOUT but extended to dynamic properties and any other entity properties you need from (entget). What I would do in your case is to create a function that create a selection boundary within each shape and then add each text to a list and then do a lot of lisp manipulation. What I expect is to compare (cdr (assoc 10 ent)) for each entity seen and then group close blocks together but this doesn't tell you what data they are to include in your table. This would be easier if each of those plots were blocks with attributes like nod684 mentioned which would make ATTOUT the tool of choice. Edited February 23, 2023 by j2lstaples Quote
BIGAL Posted February 23, 2023 Posted February 23, 2023 (edited) The way to go is use search for plines and get all text within, sort on Y value of text, then export to csv or excel direct. This question has been asked for many times before. Do a google "get text inside pline Autocad lisp" Hint (setq ss (ssget "WP" lstpts )) Hint2 is can get centroid of a pline. Edited February 23, 2023 by BIGAL Quote
devitg Posted February 24, 2023 Posted February 24, 2023 @CecepPlease give it a try. data to xls or csv.csv data to xls or csv.dwg DATA2CSV.lsp Quote
Ajmal Posted 11 hours ago Posted 11 hours ago (edited) ;;------------------------------------------------------------------------- ;; TBL2XL.lsp | Version 1.0 ;; Date: 2026-07-20 ;; NEW TOOL - Pick one AutoCAD TABLE. Copies its full grid (all rows and ;; columns, same layout) straight into Excel - uses your open Excel if ;; there is one, otherwise opens a fresh one, starting from wherever your ;; cursor is in the sheet. ;; Changelog: ;; v1.0 - initial release ;;------------------------------------------------------------------------- (vl-load-com) ;; Returns the VLA Active Document Object (defun t2x_acdoc nil (eval (list 'defun 't2x_acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (t2x_acdoc) ) ;; Opens an Undo Group. (defun t2x_startundo ( doc ) (t2x_endundo doc) (vla-startundomark doc) ) ;; Closes an Undo Group. (defun t2x_endundo ( doc / tries ) (setq tries 0) (while (and (= 8 (logand 8 (getvar 'undoctl))) (< tries 5)) (vl-catch-all-apply 'vla-endundomark (list doc)) (setq tries (1+ tries)) ) ) ;; Write a value into a cell (row, col) via the Cells collection's Item property (defun t2x_write_cell ( xlCells row col val ) (vlax-put-property xlCells "Item" row col val) ) ;; Main command (defun c:TBL2XL ( / *error* xlApp xlRun xlBooks xlBook xlSheets xlSheet xlCells xlCell es ent tbl rows cols r c cellval baseRow baseCol wr skipped ) (defun *error* ( msg ) (if xlBooks (vl-catch-all-apply 'vlax-release-object (list xlBooks))) (if xlApp (vl-catch-all-apply 'vla-put-visible (list xlApp :vlax-true)) ;; leave visible so Ajmal keeps the data ) (if xlApp (vl-catch-all-apply 'vlax-release-object (list xlApp))) (t2x_endundo (t2x_acdoc)) (if (and msg (not (wcmatch (strcase msg t) "*break*,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (t2x_startundo (t2x_acdoc)) (setq es (entsel "\nSelect the table: ")) (if (not es) (princ "\nNothing selected.") (progn (setq ent (car es)) (if (/= "ACAD_TABLE" (cdr (assoc 0 (entget ent)))) (princ "\nThat's not a table.") (progn (setq tbl (vlax-ename->vla-object ent)) (setq rows (vla-get-Rows tbl) cols (vla-get-Columns tbl) ) ;; use Excel if one is already open, otherwise open a fresh one (setq xlApp (vlax-get-or-create-object "Excel.Application") xlRun (vlax-get-property xlApp 'Visible) ) (if (= xlRun :vlax-false) (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) ) (vla-put-visible xlApp :vlax-true) ) (setq xlSheet (vlax-get-property xlApp 'ActiveSheet)) ) (setq xlCells (vlax-get-property xlSheet "Cells")) ;; start writing from wherever the cursor is in Excel right now (setq xlCell (vlax-get-property xlApp 'ActiveCell)) (setq baseRow (vlax-get-property xlCell 'Row) baseCol (vlax-get-property xlCell 'Column) ) (setq skipped 0) (princ (strcat "\nTable is " (itoa rows) " rows x " (itoa cols) " columns. Copying...")) (setq r 0) (repeat rows (setq c 0) (repeat cols (setq cellval (vl-catch-all-apply 'vla-GetText (list tbl r c))) (if (vl-catch-all-error-p cellval) (setq skipped (1+ skipped)) ;; likely a merged cell - leave blank (progn (setq wr (vl-catch-all-apply 't2x_write_cell (list xlCells (+ baseRow r) (+ baseCol c) cellval))) (if (vl-catch-all-error-p wr) (princ (strcat "\nExcel write error at row " (itoa r) " col " (itoa c) ": " (vl-catch-all-error-message wr))) ) ) ) (setq c (1+ c)) ) (setq r (1+ r)) ) (princ (strcat "\nDone. " (itoa rows) "x" (itoa cols) " table copied to Excel." (if (> skipped 0) (strcat " (" (itoa skipped) " merged cell(s) left blank)") ""))) ) ) ) ) (vl-catch-all-apply '*error* (list nil)) (princ) ) (princ "\n:: TBL2XL.lsp | Version 1.0 :: Type TBL2XL to run.") (princ) Edited 11 hours ago by Ajmal small change Quote
BIGAL Posted 8 hours ago Posted 8 hours ago Not saying what you have done is not worthwhile but a search here would possibly have found this "Table to excel.lsp". I also know there are a few others out there. ; simple table to excel ; expects Title header and data ; BY Alanh Jan 2022 ; do not have excel open You may be interested in this it contains multiple Excel defuns to carry out task to do with Excel. A big help was FIXO who did some great Excel stuff but is no longer of this world. It is a work in progress as more functions are added. Just copy and paste the defun needed. Alan Excel library.lsp 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.