Guest tkwon Posted November 16, 2004 Posted November 16, 2004 Is there an attribute extraction program that will let you extract attributes from multiple Autocad 2004 dwgs, and put them into Excel spreadsheets. I want to extract data from the parts lists of multiple dwgs, and combine the parts that are repeatedly used to create a master parts list. A program that creates this master parts list on one sheet, and then parts lists for the individual sheets is what im looking for. Is this out there? Quote
Mr T Posted November 16, 2004 Posted November 16, 2004 Sounds like an XREF task. Although If there is little repsonse I would move the post to the LISP topic for you. Nick Quote
fuccaro Posted November 18, 2004 Posted November 18, 2004 Here is the Lisp program. To process a few drawings drag the lisp file icon in the drawing area. The program will auto start. A possible usage for batch processing: open a new drawing, go to TOOLS > AutoLisp > LOAD and in the "Load/Unload Application" window locate the lisp file and drag it in the Startup Suit. Now this program will be loaded in every drawing. Close the window and go to FILE > OPEN. Select all the files you wish to process (hold shift/Ctrl to select multiple files) and press OPEN. Relax and watch the screen. After the last file opened search the file C:\attributes.CSV and open it with Excel. Probable a double-click on the file will make it open in Excel, but that also depends on your settings. If a dwg contains no blocks with attributes you will see an error message in the AutoCAD command line. Please ignore it. And don't forget to remove the program from the Startup Suit! P.S. Without an adecvate filter the program will extract all your attributes -including the data in the title data block, date stamp and so on. ; Global ATTribute EXtractor ; by Miklos Fuccaro [email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email] ;-------------------------November 2004 ------- (defun gattex() (setq ss (ssget "X" '((0 . "INSERT") (66 . 1)))) (if (not ss) (quit)) (setq file (open "c:\\attributes.CSV" "a") i -1) (write-line (strcat (getvar "DWGPREFIX") (getvar "DWGNAME") " -found " (itoa (sslength ss)) " block(s) with attributes") file) (repeat (sslength ss) (setq l (entget (setq e (ssname ss (setq i (1+ i)))))) (write-line (strcat "block name:" "," (cdr (assoc 2 l))) file) (while (/= (cdr (assoc 0 l)) "SEQEND") (if (= (cdr (assoc 0 l)) "ATTRIB") (write-line (strcat ",," (cdr (assoc 1 l)) "," (cdr (assoc 2 l))) file)) (setq l (entget (setq e (entnext e)))) ) ) (close file) (princ) ) (gattex) Quote
sab423 Posted November 18, 2004 Posted November 18, 2004 Impressive Fuccaro! I really need to learn autolisp! Scott Quote
DANIEL Posted May 24, 2005 Posted May 24, 2005 ... or you can filter the data within Excel The dark side I sense in you.....just kidding....I'm getting someone to show me how to filter it in excel thanks again Quote
fuccaro Posted May 25, 2005 Posted May 25, 2005 Daniel What kind of filtering do you think about? The simplest way is to add a list of block names and to teach the routine to ignore all the blocks not contained in the list. Or to ignore those and work the other ones. MAY THE FORCE BE WITH YOU! Quote
DANIEL Posted May 25, 2005 Posted May 25, 2005 DanielWhat kind of filtering do you think about? The simplest way is to add a list of block names and to teach the routine to ignore all the blocks not contained in the list. Or to ignore those and work the other ones. MAY THE FORCE BE WITH YOU! I was going to modify your code, when i can find the time, so that it lists the block names, what drawing its in and its attributes all in the same row, for example block1, drawing1, attribute value1, attribute value2, ect..... block2, drawing1, attribute value1, attribute value2, ect..... block3, drawing2, attribute value1, attribute value2, ect..... so on and so forth basicly i am providing a contractor with a list of valves and instruments off of our Process flow sheets. I hadn't considered writing a lisp routine until you pointed me to this thread, good stuff fuccaro, thanks, and if you've got any ideas for me, or see anything i may be overlooking let me know, your help has been greatly appreciated. Quote
DANIEL Posted May 28, 2005 Posted May 28, 2005 heres my version (defun gattex() (setq ss (ssget "X" '((0 . "INSERT") (66 . 1)))) (if (not ss) (quit)) (setq file (open "c:\\attributes.CSV" "a") i -1) (repeat (sslength ss) (setq A (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))) (setq l (entget (setq e (ssname ss (setq i (1+ i)))))) (setq A (strcat A "," (cdr (assoc 2 l)))) (while (/= (cdr (assoc 0 l)) "SEQEND") (if (= (cdr (assoc 0 l)) "ATTRIB") (setq A(strcat A "," (cdr (assoc 1 l))))) (setq l (entget (setq e (entnext e)))) ) (write-line A file) ) (close file) (princ) ) (gattex) thanks again for the insight fuccaro Quote
iosa1 Posted February 28, 2006 Posted February 28, 2006 Hi everyone. This is my first post on this forum. It is a great forum I must say. I went through the process of the extraction wizzard and I saw it does have problems. It actually leaves out files from the batch process and in a random fashion. I need to extract info from a block called "I" which has some of the info that the title block has; being it E.C.N. number, drawing number, revision level, revision class, description of change and engineer in charge. All this from several drawings (*.dwg files) to be able to have them in an excel document with the info I mentioned as column titles. I see the Lisp program that is shown on this forum thread does extract attributes effectivelly. But it takes the info from all the blocks in the drawing. Quoting fuccaro: "The simplest way is to add a list of block names and to teach the routine to ignore all the blocks not contained in the list. Or to ignore those and work the other ones." Since I don't know AUTO LISP; how can I make the routine do this? In other words where in the routine can I tell it which block to look for in each drawing? How do I tell it which info to look for in each block so I make copies of the routine as needed for different sets of info? How do I make it to revese the info as in rows to columns and columns to rows? Sorry if this is too long. I thank you for your time. Quote
CarlB Posted March 1, 2006 Posted March 1, 2006 Well to answer one of your questions.... to have the routine work on just the blocks you select, rather than all blocks, change one line from: (setq ss (ssget "X" '((0 . "INSERT") (66 . 1)))) to (setq ss (ssget '((0 . "INSERT") (66 . 1)))) Quote
iosa1 Posted March 1, 2006 Posted March 1, 2006 Thanks for your reply. I did the replacement and it still takes all blocks. Where in the routine can I type a list of blocks or an only block from which to extract info? I'm not litterate on lisp programing. I appreciate your time. Quote
Geordie Posted March 4, 2006 Posted March 4, 2006 Check out this thread at the swamp http://www.theswamp.org/forum/index.php?topic=8661.0 about extracting attributes Quote
CarlB Posted March 4, 2006 Posted March 4, 2006 I replied to iosa1 at another forum but thought it should go here as well since it builds on this thread and on Fuccaro's routine. Edit the second and third lines to specify block names and tag names to extract. Case of text in list needs to match block and tag names. ; Global ATTribute EXtractor ; by Miklos Fuccaro [email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email] ;-------------------------November 2004 ------- ;;Edited March 2006 by C. Bassler to allow specification of block and tage names to extract (defun gattex() (setq Blocklist '("Name1" "Name2" "Name3"));; ** edit to include block names to select (setq TagList '("Tag1" "TAG2" "Tag3"));; ** edit to include tag names to extract ;;create block names separated by columns, for selection filter (setq Blocknames (List2String BlockList)) (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 BlockNames)))) (if (not ss) (quit)) (setq Root (getvar "DWGPREFIX")) (setq file (open (strcat Root "attributes.CSV") "a") i -1) (write-line (strcat Root (getvar "DWGNAME") " -found " (itoa (sslength ss)) " block(s) with attributes") file) (repeat (sslength ss) (setq TagRow nil ValRow nil) (setq Edata (entget (setq e (ssname ss (setq i (1+ i)))))) (write-line "" file) (write-line (strcat "block name:" "," (Dxf 2 Edata)) file) (while (/= (Dxf 0 Edata) "SEQEND") (if (and (= (Dxf 0 Edata) "ATTRIB") (member (dxf 2 Edata) TagList);;if tag is on list );and (progn (setq TagRow (cons (Dxf 2 Edata) TagRow)) (setq valRow (cons (Dxf 1 Edata) ValRow)) );progn ) (setq Edata (entget (setq e (entnext e)))) );while (write-line (List2String (reverse TagRow)) file) (write-line (List2String (reverse ValRow)) file) );repeat (close file) (princ (strcat "\nDone writing file " Root "attributes.csv")) (princ) );defun ;;------------------------------- (defun List2String (Alist) (setq NumStr (length Alist)) (foreach Item AList (if (= Item (car AList));;first item (setq LongString (car AList)) (setq LongString (strcat LongString "," Item)) ) ) LongString );defun ;;-------------------------------- (defun Dxf (code pairs) (cdr (assoc code pairs)) ) (gattex) Quote
Ako Posted March 18, 2006 Posted March 18, 2006 Here's some VBA to do a similar thing. Just delete the lines with the info that's not required. Sub Blocks(row, col) Dim BlocksSelSet As AcadSelectionSet Dim blockref As AcadBlockReference Dim AttRef As Variant Dim I As Integer Dim gpCode(0) As Integer Dim dataValue(0) As Variant Dim groupCode As Variant, dataCode As Variant Dim NumOfBlocks As Integer Dim mode Dim AttMode As Long Dim constant As String Dim currentmode As Integer Dim attrobject As AcadAttribute On Error Resume Next Set BlocksSelSet = ThisDrawing.SelectionSets.Add("All_Blocks") 'define type of selection set (crossing, window, etc, in this case, all) mode = acSelectionSetAll 'this is a selection set filter gpCode(0) = 0 dataValue(0) = "Insert" groupCode = gpCode dataCode = dataValue 'this collects all blocks into the seletion set BlocksSelSet.Select mode, , , groupCode, dataCode NumOfBlocks = BlocksSelSet.Count For x = 1 To NumOfBlocks Set blockref = BlocksSelSet(x) excelsheet.Cells(row, col).Value = blockref.Name excelsheet.Cells(row, col + 1).Value = blockref.layer excelsheet.Cells(row, col + 2).Value = Format(blockref.insertionPoint(0), "##,##0.00") & "," & Format(blockref.insertionPoint(1), "##,##0.00") row = row + 1 AttRef = blockref.GetAttributes For I = LBound(AttRef) To UBound(AttRef) Set attrobject = AttRef(I) ' Do something with the attribute refs here. excelsheet.Cells(row, col).Value = AttRef(I).TagString excelsheet.Cells(row, col + 1).Value = AttRef(I).layer excelsheet.Cells(row, col + 3).Value = AttRef(I).TextString constant = Choose(attrobject.mode, "acAttributeModeInvisible", "acAttributeModeConstant", "", "acAttributeModeVerify", "", "", "", "acAttributeModePreset") row = row + 1 Next Next row = row + 1 'clean up BlocksSelSet.Clear BlocksSelSet.Delete rownum = row End Sub Dave Quote
au-s Posted May 8, 2009 Posted May 8, 2009 I am using this and I find it cool... Is it possible to remake it ? I want it to 1. overwrite existing cvs-file (cause now it adds lines below previous created ones) That goes for lisp code Thanx for help!! Quote
Lee Mac Posted May 8, 2009 Posted May 8, 2009 Perhaps; ; Global ATTribute EXtractor ; by Miklos Fuccaro mfuccaro@hotmail.com ;-------------------------November 2004 ------- ;;Edited March 2006 by C. Bassler to allow specification of block and tage names to extract (defun gattex () (setq Blocklist '("Name1" "Name2" "Name3")) ;; ** edit to include block names to select (setq TagList '("Tag1" "TAG2" "Tag3")) ;; ** edit to include tag names to extract ;;create block names separated by columns, for selection filter (setq Blocknames (List2String BlockList)) (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 BlockNames)))) (if (not ss) (quit)) (setq Root (getvar "DWGPREFIX")) (setq file (open (strcat Root "attributes.CSV") [color=Red][b]"w"[/b][/color]) i -1) (write-line (strcat Root (getvar "DWGNAME") " -found " (itoa (sslength ss)) " block(s) with attributes") file) (repeat (sslength ss) (setq TagRow nil ValRow nil) (setq Edata (entget (setq e (ssname ss (setq i (1+ i)))))) (write-line "" file) (write-line (strcat "block name:" "," (Dxf 2 Edata)) file) (while (/= (Dxf 0 Edata) "SEQEND") (if (and (= (Dxf 0 Edata) "ATTRIB") (member (dxf 2 Edata) TagList) ;;if tag is on list ) ;and (progn (setq TagRow (cons (Dxf 2 Edata) TagRow)) (setq valRow (cons (Dxf 1 Edata) ValRow)) ) ;progn ) (setq Edata (entget (setq e (entnext e)))) ) ;while (write-line (List2String (reverse TagRow)) file) (write-line (List2String (reverse ValRow)) file) ) ;repeat (close file) (princ (strcat "\nDone writing file " Root "attributes.csv")) (princ) ) ;defun ;;------------------------------- (defun List2String (Alist) (setq NumStr (length Alist)) (foreach Item AList (if (= Item (car AList)) ;;first item (setq LongString (car AList)) (setq LongString (strcat LongString "," Item)) ) ) LongString ) ;defun ;;-------------------------------- (defun Dxf (code pairs) (cdr (assoc code pairs)) ) (gattex) 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.