+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 45
  1. #11
    Super Member DANIEL's Avatar
    Discipline
    Mechanical
    DANIEL's Discipline Details
    Occupation
    Industrial
    Discipline
    Mechanical
    Using
    AutoCAD 2012
    Join Date
    May 2005
    Location
    Arlington Texas
    Posts
    995

    Default

    Registered forum members do not see this ad.

    heres my version
    Code:
    (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
    If you would like to help my 2 year old niece Alaina in her battle against Leukemia you can donate blood at any Carter Blood Care and put SPON050875 on the donor form. Thank you so much for any contributions in this matter that you can make.

    Luminous beings are we, not this crude matter.

  2. #12
    Forum Newbie
    Using
    not specified
    Join Date
    Feb 2006
    Location
    El Paso, TX.
    Posts
    2

    Default attribute extraction

    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.

  3. #13
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

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

  4. #14
    Forum Newbie
    Using
    not specified
    Join Date
    Feb 2006
    Location
    El Paso, TX.
    Posts
    2

    Default attribute extraction

    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.

  5. #15
    Full Member
    Computer Details
    Geordie's Computer Details
    Operating System:
    XP
    Using
    Mechanical 2012
    Join Date
    Dec 2004
    Location
    Brisbane Queensland
    Posts
    49

    Default

    Check out this thread at the swamp
    http://www.theswamp.org/forum/index.php?topic=8661.0
    about extracting attributes

  6. #16
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    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.

    Code:
    ; 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") "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)

  7. #17
    Senior Member Ako's Avatar
    Using
    AutoCAD 2007
    Join Date
    Mar 2006
    Location
    Warrington UK
    Posts
    310

    Default

    Here's some VBA to do a similar thing. Just delete the lines with the info that's not required.

    Code:
    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

  8. #18
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Nov 2008
    Posts
    155

    Default

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

  9. #19
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,741

    Default

    Perhaps;

    Code:
      ; 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") "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)
    Last edited by Lee Mac; 8th May 2009 at 03:27 pm.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  10. #20
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Nov 2008
    Posts
    155

    Default

    Registered forum members do not see this ad.

    COOL!
    Thanx man

    What did you do?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts