Jump to content

Attribute Extraction Program?


Recommended Posts

Posted

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?

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • au-s

    6

  • Britman

    5

  • DANIEL

    4

Top Posters In This Topic

Posted

Sounds like an XREF task. :?

 

Although If there is little repsonse I would move the post to the LISP topic for you.

 

Nick

Posted

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)

Posted

Impressive Fuccaro! :thumbsup:

 

I really need to learn autolisp!

 

Scott 8)

  • 6 months later...
Posted

does this lisp come with a complimentary filter :mrgreen:

Posted

... or you can filter the data within Excel :twisted:

Posted
... or you can filter the data within Excel :twisted:

 

The dark side I sense in you.....just kidding....I'm getting someone to show me how to filter it in :shifty: excel

 

thanks again

Posted

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!

Posted
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!

 

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.

Posted

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

  • 8 months later...
Posted

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.

Posted

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

Posted

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.

Posted

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)

  • 2 weeks later...
Posted

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

  • 3 years later...
Posted

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!! :)

Posted

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)

Posted

COOL! :)

Thanx man

 

What did you do?

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