Jump to content

extracting data from AutoCAD to Excel


tefached2809

Recommended Posts

hi everyone.
i have someone made this lisp and i want it modified

what it does:
it extracts the length and width of rectangles (length as horizontal dimension width as vertical dimension) and the ref ID inside the rectangle and puts it into excel

what i wanted:

sometimes there are multiple ID ref inside the rectangle, i want to include all ID's on the cell

 

(defun c:Test ( / int sel cad ent lst ref one two out csv get)
  
  (and (princ "\nSelect closed polylines with four corners : ")
       (setq int -1 sel (ssget '((0 . "*POLYLINE") (-4 . "<AND") (-4 . "&=") (70 . 1) (90 . 4) (-4 . "AND>"))))
       (or (vla-zoomextents (setq cad (vlax-get-acad-object))) t)
       (while (setq int (1+ int) ent (ssname sel int))
         (setq lst nil)
         (foreach p (entget ent)
           (if (= (car p) 10) (setq lst (cons (cdr p) lst)))
           )
         (and (setq ref (ssget "_CP" lst '((0 . "TEXT"))))
              (setq one (distance (car lst) (cadr lst))
                    two (distance (car lst) (last lst))
                    )
              (if (equal (cadar lst) (cadadr lst) 1e-4)
                (setq len one wid two)
                (setq len two wid one)
                )
              (setq out (cons (list len wid (cdr (assoc 1 (entget (ssname ref 0))))) out))
              )
         )
       (or (vla-zoomprevious cad) t)
       (setq csv (getfiled "Specify file name" (getvar 'DWGPREFIX) "csv" 1))
       (setq get (open csv "w"))
       (write-line "L,W,ID" get)
       (foreach itm out
         (write-line (strcat (rtos (car itm) 2 2) "," (rtos (cadr itm) 2 2) "," (caddr itm)) get)
         )
       (close get)
       )
  (princ)
  ) (vl-load-com)

 

1.png

2.png

3.png

Link to comment
Share on other sites

You get a selection set of text, 1 or more so convert the text into a string you would use something like this then write to file

 

(setq tstr "")
(repeat (setq x (sslength ref))
  (setq str (cdr (assoc 1 (entget (ssname ref (setq x (1- x)))))))
  (setq tstr (strcat tstr "," str))
)

 

Just a comment you can write direct to Excel no need to use a csv.

Edited by BIGAL
  • Thanks 1
Link to comment
Share on other sites

On 3/25/2023 at 10:36 AM, tefached2809 said:

hi everyone.
i have someone made this lisp and i want it modified

Why did you remove my name from my codes ?

Did you pay me to say that you had someone made this program for you ?

Link to comment
Share on other sites

On 3/25/2023 at 3:36 AM, tefached2809 said:

hi everyone.
i have someone made this lisp and i want it modified

what it does:
it extracts the length and width of rectangles (length as horizontal dimension width as vertical dimension) and the ref ID inside the rectangle and puts it into excel

what i wanted:

sometimes there are multiple ID ref inside the rectangle, i want to include all ID's on the cell

 

(defun c:Test ( / int sel cad ent lst ref one two out csv get)
  
  (and (princ "\nSelect closed polylines with four corners : ")
       (setq int -1 sel (ssget '((0 . "*POLYLINE") (-4 . "<AND") (-4 . "&=") (70 . 1) (90 . 4) (-4 . "AND>"))))
       (or (vla-zoomextents (setq cad (vlax-get-acad-object))) t)
       (while (setq int (1+ int) ent (ssname sel int))
         (setq lst nil)
         (foreach p (entget ent)
           (if (= (car p) 10) (setq lst (cons (cdr p) lst)))
           )
         (and (setq ref (ssget "_CP" lst '((0 . "TEXT"))))
              (setq one (distance (car lst) (cadr lst))
                    two (distance (car lst) (last lst))
                    )
              (if (equal (cadar lst) (cadadr lst) 1e-4)
                (setq len one wid two)
                (setq len two wid one)
                )
              (setq out (cons (list len wid (cdr (assoc 1 (entget (ssname ref 0))))) out))
              )
         )
       (or (vla-zoomprevious cad) t)
       (setq csv (getfiled "Specify file name" (getvar 'DWGPREFIX) "csv" 1))
       (setq get (open csv "w"))
       (write-line "L,W,ID" get)
       (foreach itm out
         (write-line (strcat (rtos (car itm) 2 2) "," (rtos (cadr itm) 2 2) "," (caddr itm)) get)
         )
       (close get)
       )
  (princ)
  ) (vl-load-com)

 

1.png

2.png

3.png

You ask for the same topic about 3 years  ago 

 

Length and Width of Rectangles With ID to excel

 

 

Link to comment
Share on other sites

On 3/26/2023 at 1:00 PM, Tharwat said:

Why did you remove my name from my codes ?

Did you pay me to say that you had someone made this program for you ?

sorry i lost that account and just received the code from another guy and copy paste everything. i did not pay anyone, nor i claim to make any code. i lost the account i can not remember the names of persons involved in the code creation.

 

 

On 3/27/2023 at 2:27 AM, devitg said:

You ask for the same topic about 3 years  ago 

 

Length and Width of Rectangles With ID to excel

 

 

thanks for the link! i lost that account. iirc one code there does get all text but have issues about the len and wid, but the other code gets the len and wid properly but not all text.
 

 

On 3/26/2023 at 10:28 PM, hosneyalaa said:

yes that one exactly thank you

Link to comment
Share on other sites

On 3/26/2023 at 2:59 AM, BIGAL said:

You get a selection set of text, 1 or more so convert the text into a string you would use something like this then write to file

 

(setq tstr "")
(repeat (setq x (sslength ref))
  (setq str (cdr (assoc 1 (entget (ssname ref (setq x (1- x)))))))
  (setq tstr (strcat tstr "," str))
)

 

Just a comment you can write direct to Excel no need to use a csv.

thank you so much

Link to comment
Share on other sites

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