Modification in LISP_ Extract table from multiple drawings in an excel

Modification in LISP_ Extract table from multiple drawings in an excel

nck5678
Enthusiast Enthusiast
625 Views
6 Replies
Message 1 of 7

Modification in LISP_ Extract table from multiple drawings in an excel

nck5678
Enthusiast
Enthusiast

Hello everyone,

I wished to extract values from tables in multiple AutoCAD drawings at the same time and was able to find a LISP routine on this forum. The LISP routine when executed extracts data from all the tables in selected folder where AutoCAD drawings are placed and generates an excel.

 

In this routine, I wish to modify the routine so as to extract data from selected table. (i.e., I can differentiate the table with either different layer or table name; and want to routine to extract values of only this table from all the drawings).

Can any one help to modify the same?

 

LISP Routine:

 

(defun c:Exp_Table ( / sh folder folderobject result en eo fname f row col str n qt NO)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "Browse The Folder Containing Drawings" 0))
   (vlax-release-object sh)
   (if folder
      (progn
(setq fname (getstring T "Enter file path to exported data: "))
(if (setq f (open fname "a"))
(progn
(setq SDI_Val (getvar "SDI") LISPI_Val (getvar "LISPINIT"))
(vl-cmdf "SDI" 1)
(vl-cmdf "LISPINIT" 0)
(setq FolderObject (vlax-get-property folder 'Self))
(setq result (vlax-get-property FolderObject 'Path))
(vlax-release-object folder)
(vlax-release-object FolderObject)
(setq Files_Folder (vl-directory-files result "*.dwg"))
 
(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
(setq n 0)
(while (< n (length Files_Folder))
(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
(setq qt 0)
 
(if (setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))
(progn
(repeat (setq NO (sslength ss))
(setq en (ssname ss (setq NO (1- NO))))
(setq eo (vlax-ename->vla-object en))
 
 
(princ (strcat "\n" (getvar 'DWGNAME) " - Table - " (itoa (setq qt (1+ qt))) "\n\n\n") f)
(setq row -1)
(while (< (setq row (1+ row)) (vla-get-Rows eo))
(setq col -1 str "")
(while (< (setq col (1+ col)) (vla-get-Columns eo))
(setq str (strcat str ",\"" (vla-GetText eo row col) "\""))
)
(princ (substr str 2) f)
(princ "\n" f)
)
)
)
)
 
 
(setq n (+ 1 n))
)
(vl-cmdf "SDI" SDI_Val)
(vl-cmdf "LISPINIT" LISPI_Val)
(close f)
)
)
      )
  
   )
)

 

 

In the routine, I tried to tweak this line: (if (setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))

with this: (setq ss (ssget "_X" '((0 . "ACAD_TABLE")(8 ."layer"))))

(With layer as the layer name on which the table is set), but to avail no success. 

0 Likes
626 Views
6 Replies
Replies (6)
Message 2 of 7

paullimapa
Mentor
Mentor

perhaps you can share a sample dwg with a table on that particular layer?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 7

devitg
Advisor
Advisor

@nck5678 as to follow the topic

0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

This may be useful a table to Excel, its not an answer to your request but your welcome to use parts of it.

 

 

0 Likes
Message 5 of 7

ec-cad
Collaborator
Collaborator

Try putting a space, right after the . as in:

(ssget "_X" '((0 . "ACAD_TABLE")(8 . "layer"))))

 

ECCAD

0 Likes
Message 6 of 7

ec-cad
Collaborator
Collaborator

Try this instead. Gets a selection set.

(setq ss (ssget "_X" '((0 . "ACAD_TABLE")(8 . "0"))))

 

ECCAD

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

Every object in a dwg has a unique "HANDLE" ID so if your Excel has dwgname & Handle in cells then you can get one table from a dwg using the handle ID. 

 

PICK((-1 . <Entity name: 60eb8df0>) (0 . "ACAD_TABLE") (5 . "1B1") the 5 is the handle.

PICK((-1 . <Entity name: 60ea11f0>) (0 . "ACAD_TABLE") (5 . "192")

0 Likes