Jump to content

Help the Lisp Convert data autocad to Excel


Recommended Posts

Posted

Did you checked the built-in DATAEXTRACTION command?

Posted

Hi Msasu

 

I try DATAEXTRACTION and the results are not like expected, if you can do the same this attachments?

 

and sympathy if you do not understand what I write, because I'm not good at english

 

Regards,

khanhnguyen

Posted

This will get you started,

select your shapes one by another,

then do your rest job:


(defun c:exwr (/ ar del elist en ent filename fn hgt i maxp minp obj per pmax 
pmin rowdata wid  xldata )
(setq i 0 )
 (setq xldata (cons 
(list "" "Length (mm)" "Width (mm)""Perimeter" "Area")xldata))
 (while 

   (setq ent (entsel "\nSelect a rectangle one by another, 
press Enter to stop loop: "))
     (if 
(and
(setq elist (entget (setq en (car ent))))
(eq (cdr (assoc 
0 elist)) "LWPOLYLINE")
(= (cdr (assoc 70 elist)) 1)
(and 
(> (cdr (assoc 90 elist)) 5)
     (< (cdr 
(assoc 90 elist)) 13)

)
)
(progn
     (setq obj 
(vlax-ename->vla-object en))

(vla-getboundingbox obj 'minp 'maxp)
     (setq 
pmin (vlax-safearray->list minp)
    pmax 
(vlax-safearray->list maxp))
     (setq 
wid (abs (- (car pmax) (car pmin)))

hgt (abs (- (cadr pmax) (cadr pmin)))

per (vla-get-length obj)
    ar (vla-get-area 
obj)
    )
     (setq 
rowdata (list
       (itoa (setq i (1+ 
i)))
       (rtos wid 2 
2)
       (rtos hgt 2 
2)
       (rtos per 2 
2)
       (rtos ar 2 
2)))
     ;; gather data in a 
list
     (setq xldata (append xldata (list 
rowdata)))
     )     


    (prompt "\nNothing or not closed pline 
selected.")

)     
 )
(if (> (length xldata) 
1)
  (progn
    ;; put delimiter to suit: 

    (setq del "\t")


    ;; build your text file path here: 

    (setq filename (strcat (getvar 
"dwgprefix")
      (vl-filename-base (getvar 
"dwgname"))

"_Dim.txt"))
    (setq fn (open filename 
"w"))
    ;; Write info to a file


    (mapcar

'(lambda (x)
  (write-line
    (apply 
'strcat
    (append (list (car 
x))
     (mapcar '(lambda (y) (strcat del 
y))
      (cdr 
x)
      )

)
    )

fn
    )

)

xldata
      )



    (close 
fn)
    (gc)
    ;; just to see 
a result
    (startapp "notepad" 
filename)


)
  )
 (alert "Open text file with Excel,\nthen save as 
.xls or .xlsx file")
(princ)
 )
(princ "\n\t***\tStart command 
with EXWR \t***")
(princ)
(or (vl-load-com)(princ))

Posted

Dear Fixo

 

Thank you, but I never knew about the lisp, it's very hard for me, I do not know how and where to start, I have coppy paste the above code into notepad and save the file. LSP, when not use, you can guide me?, or the unfinished lisp you can complete to help me? thank you very much.

 

Regards,

khanhnguyen

Posted
Dear Fixo

 

Thank you, but I never knew about the lisp, it's very hard for me, I do not know how and where to start, I have coppy paste the above code into notepad and save the file. LSP, when not use, you can guide me?, or the unfinished lisp you can complete to help me? thank you very much.

 

Regards,

khanhnguyen

I think you had a problem with copy code,

try attached lisp instead:

 

ExWr.LSP

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