Jump to content

Recommended Posts

Posted (edited)

AutoCAD to excel

From AutoCAD I will click one text and after that for I will measure one length

That both things I need to excel

1.       I will click one text that things I need to come one row in excel at the same time

2.       I will measure one length that I need to come on next row

3.       This thing I will continue

Actually, this is for quantity take off from AutoCAD to excel

 

 

Please help me

 

 

1203511777_MODEL-gif.gif.bef870835efabf8a5491db07334216bb.gif602063738_AutoCADtoexcel.png.bb3be2bc98e8838cb9311db996035dad.png

 

 

Edited by Ajmal
Posted

Interesting using Google

 

Autocad to excel 36 million.

Autocad export attributes 587,000

 

devitg this may be a useful example to be saved in the downloads area.

 

For Admin have suggested before need a excel subject catergory this would save lots of duplication.

Posted (edited)

I got it, It is a must the xls be online?. or the LISP could give a XLS or a CSV , after you m end  pick .

 

Edited by devitg
Posted
On 17/10/2019 at 19:38, devitg said:

I got it, It is a must the xlsbe online?. or the LISP could give a XLS or a CSV , after you m end  pick .

 

if you can make active excel that will okey. 2 types of data same comment..

Posted

Here is a simple answer uses pick point for distance and a csv file which you can open in excel. 

 

Change D:\acadtemp to a directory where you want the csv file to go to.

 

(defun c:ajmal ( / fo txt pt1 pt2)
(setq fo (open (setq fname "D:\\acadtemp\\ajmal.csv") "w"))
(write-line "Size,Length" fo)
(while (setq tent (entsel "Pick text"))
(setq txt (cdr (assoc 1 (entget (car tent)))))
(setq pt1 (getpoint "Pick 1st point for length"))
(setq pt2 (getpoint "Pick 2nd point for length"))
(write-line (strcat txt "," (rtos (distance pt1 pt2) 2 0)) fo)
)
(close fo)
)

 

Posted

I need this quantity at the same time in active excel 

Posted

Ah yes the answer is the $100 question, only joking, its not straight forward but it is achievable and again there are just so many answers to your question out there  that do just that pick something in Autocad and put an answer in a Excel cell.

 

This is why the csv is offered first as its simple. 

 

The excel answers always seem to come back with more requests for enhancements people like me offer solutions for free here, so Cadtutor should not be used as a I want for free. Start with getexcel.lsp.

 

Again GOOGLE search here also, it may take say an hour but you will find what you want it is definitely out there.

 

 

 

 

  • Like 1
  • 6 years later...
Posted (edited)
;;-------------------------------------------------------------------------
;; TXT2XL.lsp | Version 1.0 
;; Date: 2026-07-20
;; NEW TOOL - Pick text entities one by one in AutoCAD. Each pick is sent
;; 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.
;; Keep picking - press ENTER or ESC to stop.
;; Changelog:

;;-------------------------------------------------------------------------

(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)
)

;; Gets the clean text string from a TEXT or MTEXT entity, else nil
(defun t2x_get_text_value ( ent / obj etype )
    (setq etype (cdr (assoc 0 (entget ent))))
    (if (member etype '("TEXT" "MTEXT"))
        (progn
            (setq obj (vlax-ename->vla-object ent))
            (vla-get-textstring obj)
        )
    )
)

;; Main command
(defun c:TXT2XL ( / *error* xlApp xlRun xlBooks xlBook xlSheets xlSheet xlCells xlCell
                     es ent val row col wr )

    (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))

    ;; 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, so an
    ;; existing sheet's data never gets overwritten
    (setq xlCell (vlax-get-property xlApp 'ActiveCell))
    (setq row (vlax-get-property xlCell 'Row)
          col (vlax-get-property xlCell 'Column)
    )

    (princ "\nTXT2XL running - pick text, ENTER/ESC to stop.")
    (while (setq es (entsel "\nSelect text: "))
        (setq ent (car es))
        (setq val (vl-catch-all-apply 't2x_get_text_value (list ent)))
        (cond
            ( (vl-catch-all-error-p val)
                (princ (strcat "\nRead error: " (vl-catch-all-error-message val)))
            )
            ( val
                (setq wr (vl-catch-all-apply 't2x_write_cell (list xlCells row col val)))
                (if (vl-catch-all-error-p wr)
                    (princ (strcat "\nExcel write error: " (vl-catch-all-error-message wr)))
                    (progn
                        (princ (strcat "\n-> Row " (itoa row) " : " val))
                        (setq row (1+ row))
                    )
                )
            )
            ( t (princ "\nNot a TEXT/MTEXT entity - skipped.") )
        )
    )

    (princ "\nDone. Excel left open with your data.")
    (vl-catch-all-apply '*error* (list nil))
    (princ)
)

(princ "\n:: TXT2XL.lsp | Version 1.0 :: Type TXT2XL to run.")
(princ)

 

Edited by Ajmal
small change

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...