Jump to content

Attribute Extraction Program?


Guest tkwon

Recommended Posts

  • 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

thanx...

 

one more thing...

 

When I use it on another dwg file it over-writes exsisting *csv.

Can it be done so it checks that its extracting from another *.dwg file and if so the case it adds rows below in attributes.csv??

 

So it always checks which file it is and if it matches the file dwg name it over-writes the rows corresponding to the dwg-name...

 

Sorry for beeing annoying :)

 

Thanx in advance.

 

Regards!

Link to comment
Share on other sites

A quick fix - I may consider re-writing this :P

 

 ; 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 (substr (getvar "DWGNAME") 1
                                       (- (strlen (getvar "DWGNAME") 4))) "attributes.CSV") "w")
       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)

Link to comment
Share on other sites

Am I getting this correctly? This routine will extract all attribute info to a csv file?

 

Question, how to modify the lisp so it wil only extract the attribute values of a specific block, i.e. "title".

 

I thought (i think too much sometimes): when havin 10 layouts (drawings) with 10 "title" blocks in the right corner below of each layout, the lisp will extract exactly the info that i need to create a drawing list. So i figured, making the list in excel and copy only the info i need to the right cells.

 

It would be great having a way to creat such drawing list for the automation wil save a lot of time and it is a great way to check the date's of the specific drawings.

 

:shock:

 

Even better it would be when having a file that contains the specific data wich is used by autocad when opening a drawing. So "in reverse".

 

Ie. when creating a drawing with date in the title block, then give a command like "update drawing list". There will be created a file called drawing list (in the same folder as the drawing itself).

 

WHenever either one of the files is updated the info must be exchanged...

 

Anyone got a thingy that does it? I will not ask for you to write it for me...

 

 

 

 

 

Or would you :oops: ?

Link to comment
Share on other sites

How can I convert 3d point to 2d point

 

Waqashraf -

 

You have already posted this question in another unrelated thread and it has been answered in much the same way.

 

I will ask you again - if you have a new question, create a new thread. It will get your question answered both quicker and more accurately, and will also help with user searches.

 

Please don't double post.

 

Lee

Link to comment
Share on other sites

Am I getting this correctly? This routine will extract all attribute info to a csv file?

 

Question, how to modify the lisp so it wil only extract the attribute values of a specific block, i.e. "title".

 

I thought (i think too much sometimes): when havin 10 layouts (drawings) with 10 "title" blocks in the right corner below of each layout, the lisp will extract exactly the info that i need to create a drawing list. So i figured, making the list in excel and copy only the info i need to the right cells.

 

It would be great having a way to creat such drawing list for the automation wil save a lot of time and it is a great way to check the date's of the specific drawings.

 

:shock:

 

Even better it would be when having a file that contains the specific data wich is used by autocad when opening a drawing. So "in reverse".

 

Ie. when creating a drawing with date in the title block, then give a command like "update drawing list". There will be created a file called drawing list (in the same folder as the drawing itself).

 

WHenever either one of the files is updated the info must be exchanged...

 

Anyone got a thingy that does it? I will not ask for you to write it for me...

 

 

 

 

 

Or would you :oops: ?

 

Firstly, to alter the blocks and attributes that are extracted, just alter the two lists at the very top of the LISP file to whatever block names and attribute tags need reading.

 

As for the drawing list "auto-update", short of using a reactor, I think you would have to run the LISP after all the updates are made to the blocks, and overwrite the existing file with the new values.

 

As for going the other way, i.e. updating the CSV and making it update the title blocks... this could be a bit harder.

Link to comment
Share on other sites

Hi Lee, tnx for the reply.

I see what you mean, should have seen it before asking you...

 

This lisp is made with sub-functions if i'm right.

 

How do you make it run? I put (defun c:test () before the code and a ) to the very end but it won't run.

 

--> ; error: bad argument type: stringp 4

 

When speaking about the csv file... would it be easyer when using a database file or so ? ie. Acces...?

Link to comment
Share on other sites

Sorry dude, it had one bracket missing :oops:

 

 

 ; 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 '("Test Blockatt"))
 ;; ** edit to include block names to select
 (setq TagList '("TAG1"))
 ;; ** 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
                          (substr (getvar "DWGNAME")
                                  1
                                  (- (strlen (getvar "DWGNAME")) 4))
                          "attributes.CSV")
                  "w")
       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))
 )

(defun c:test  ()
 (gattex)
 (princ))

 

type "test" to run

 

I'm not sure you can write to such files as Access etc, without some seriou coding.

 

.txt and .csv are easiest :)

Link to comment
Share on other sites

Still there is an error:

 

Command: test

; error: quit / exit abort

 

I got the right block name ...

Link to comment
Share on other sites

Nice JOb sir...

 

One problem though...

In the previous version I could have a relative path to save file..

like this:

 

(setq file (open (strcat Root "..\\Attribute\\Export\\Litt\\Rooms.CSV") "w")

 

If I do this in your version, the lisp fails:

  (setq Root (getvar "DWGPREFIX"))
 (setq file (open (strcat Root
                          (substr (getvar "DWGNAME")
                                  1
                                  (- (strlen (getvar "DWGNAME")) 4))
                          "..\\Attribute\\Export\\Litt\\Rooms.CSV")
                  "w")
       i    -1)

 

Thanx in advance for help Sir!

 

Itried also to change path like this...

 

(setq Root (getvar "DWGPREFIX"))
 [color=red](setq path (strcat "..\\Attribute\\Export\\Litt\\"))[/color]
 (setq file (open (strcat Root
                          (substr (getvar "DWGNAME")
                                  1
                                  (- (strlen (getvar "DWGNAME")) 4))
                          [color=red]path[/color] "Rooms.CSV")
                  "w")
       i    -1)

Link to comment
Share on other sites

I solved it with this one ...

My fault..

 

(setq path (strcat "..\\Attribut\\Export\\Litt\\"))

(setq file (open (strcat Root path

(substr (getvar "DWGNAME")

1

(- (strlen (getvar "DWGNAME")) 4))

"Rooms.CSV" )

"w")

i -1)

Link to comment
Share on other sites

Have you guys considered using the built-in ACAD command "Dataextraction". Just enter it in the command line and a Wizard pops up that is basically an elaborate filter. It takes some time to go through, but I've used it successfully several times. You can export the filtered data into several formats (xls, cvs, mdb).

Link to comment
Share on other sites

If I change the row:

 

 
(setq LongString (strcat LongString "\n" Item))

 

I changed the "," to "\n" so I can have one item/row.

Why is it that the formatting in csv is :

I have Tag-1 as 001, 002, 003 etc ... in csv it prints as:

1 2 3 and they are right adjusted in the cell..

The text is okej but the only thing that happens is that it cut the zeros and right adjust numbers.

Link to comment
Share on other sites

  • 3 years later...

Hi Daniel,

 

I am also an instrument guy. Did you ever mod the programme to be able to use it for instrumentation take-offs? Thanks,

 

Chris.

Link to comment
Share on other sites

Hi Daniel,

 

I am also an instrument guy. Did you ever mod the programme to be able to use it for instrumentation take-offs? Thanks,

 

Chris.

 

Welcome to the forum Britman. :)

Might this help you? http://www.lee-mac.com/macatt.html

If not, there may well be something else on Lee's site which would help you out. Thanks Lee! :beer:

 

Your profile shows you using LT, is that correct?

If so then I believe lisp won't help you.

 

Do you have DATA EXTRACTION in 2005?

 

Daniel is still a regular on the site, and may well see this and get back to you.

Link to comment
Share on other sites

Thank you so much DADGAD. That programme is awesome!!!! Lee Mac certainly is an incredible guy. You mention me having AutoCad LT 2005, well just at the moment I have access to AutoCad 2009 so I can run .lsp's.

 

Interested in your handle, are you a guitar player?

 

Chris.

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