+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Full Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Bologna, Italy
    Posts
    86

    Default Lisp for attribute extract from block

    Registered forum members do not see this ad.

    I got most of the code below from here
    What I am trying to do is read the attribute value and tag from a block (the block has multiple attributes). When I (princ) it, it returns nil. What am I doing wrong ?

    thanks

    Code:
    (defun c:sk (/)
    (if (setq ent(entsel "\n Select a Block: "))  ;- Let the user select a block
    (progn                                                   
      (setq en(car ent))                                                        ;- Get the entity name of the block
      (setq enlist(entget en))                                          ;- Get the DXF group codes
      (setq blkType(cdr(assoc 0 enlist)))                 ;- Save the type of entity
      (if (= blkType "INSERT")                                          ;- If the entity type is an Insert entity
       (progn
        (if(= (cdr(assoc 66 enlist)) 1)    ;- See if the attribute flag equals one (if so, attributes follow)
        (progn
          (setq en2(entnext en))                                    ;- Get the next sub-entity
          (setq enlist2(entget en2))                           ;- Get the DXF group codes
          (while (/= (cdr(assoc 0 enlist2)) "SEQEND")  ;- Start the while loop and keep   
            (princ "\n ")                                                 ;-Print a new line
            (princ enlist2)                                               ;- Print the attribute DXF group codes
            (setq en2(entnext en2))                             ;- Get the next sub-entity
            (setq enlist2(entget en2))                      ;- Get the DXF group codes
          )
         )
        )  ;- Close the if group code 66 = 1 statement
       )
      )   ;- Close the if block type = "ATTRIB" statement
    )
    )   ;- Close the if an Entity is selected statement
      (setq att_value (cdr (assoc 1 enlist2)))
      (princ "\nAtt_value  :  ")
      (princ att_value)
      (setq att_tag (cdr (assoc 2 enlist2)))
      (princ "\nAtt_tag  :  ")
      (princ att_tag)
     
    )
    lost

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows Vista Home Premium (32-bit)
    Using
    AutoCAD 2010
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    10,248

    Default

    Perhaps:

    Code:
    (defun c:sk (/ dxf ent)
    
      (defun dxf (code ent) (cdr (assoc code (entget ent))))
    
      (if (and (setq ent (car (entsel "\nSelect an Attributed Block: ")))
               (eq "INSERT" (dxf 0 ent))
               (= 1 (dxf 66 ent)))
    
        (while (not (eq "SEQEND" (dxf 0 (setq ent (entnext ent)))))
          (princ (strcat "\n\nAtt_Tag:" (dxf 2 ent) "\nAtt_Value: " (dxf 1 ent)))))
    
      (princ))

  3. #3
    Forum Deity alanjt's Avatar
    Using
    Civil 3D 2009
    Join Date
    Apr 2008
    Posts
    3,862

    Default

    What a strange thing to list. This information can be seen by double-clicking on the attributed block and looking at that editor.
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...


  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows Vista Home Premium (32-bit)
    Using
    AutoCAD 2010
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    10,248

    Default

    Quote Originally Posted by alanjt View Post
    What a strange thing to list. This information can be seen by double-clicking on the attributed block and looking at that editor.
    I think it's more of a learning exercise

  5. #5
    Forum Deity alanjt's Avatar
    Using
    Civil 3D 2009
    Join Date
    Apr 2008
    Posts
    3,862

    Default

    Quote Originally Posted by Lee Mac View Post
    I think it's more of a learning exercise
    Perhaps, it just seemed odd.
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...


  6. #6
    Full Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Bologna, Italy
    Posts
    86

    Default

    I just read the posts. Thanks Lee for your code. It is what I wanted to do. Now I have to study all of your code because what I have to do to is even more complex. All the posts I have made serve for the same project.

    Anyway I have started.

    Now I need to transfer these att_value to another block (the block isn't on the drawing yet). So I have to call this block "RH" change its att_value (replace them with the ones just read and place it on the drawing.

    So you see, it is learning and exercise though it may seem odd. Maybe what I ask is so simple to you guys that it seems odd.

    Both of you are of great help.
    lost

  7. #7
    Full Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Bologna, Italy
    Posts
    86

    Default

    Can you add another feature to your code that can read and extract sub-entity ( I mean blocks inside blocks - one level) tags, values and prints them.

    sub-entity-1 name : xxx
    sub-entity-1 tag: xxx
    sub-entity-1 value : xxx

    ....
    Code:
    (defun c:sk (/ dxf ent)
    
      (defun dxf (code ent) (cdr (assoc code (entget ent))))
    
      (if (and (setq ent (car (entsel "\nSelect an Attributed Block: ")))
               (eq "INSERT" (dxf 0 ent))
               (= 1 (dxf 66 ent)))
    
        (while (not (eq "SEQEND" (dxf 0 (setq ent (entnext ent)))))
          (princ (strcat "\n\nAtt_Tag:" (dxf 2 ent) "\nAtt_Value: " (dxf 1 ent)))))
    
      (princ))
    Thanks
    lost

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows Vista Home Premium (32-bit)
    Using
    AutoCAD 2010
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    10,248

    Default

    Not a simple addition, you would have to dig into the block definition for that.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows Vista Home Premium (32-bit)
    Using
    AutoCAD 2010
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    10,248

  10. #10
    Super Member
    Using
    Civil 3D 2011
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    1,126

    Default

    You can definately change the values of one block but pick another block to get the values. You just need to know the name of each block your working with.

    We do something like your asking pick a block on the layout (model space) it then updates another block with information from the model the other block can be anywhere in the total Autocad dwg usually in a layout tab.

    It reads the displayed attributes as a common ID link

Similar Threads

  1. need help making addition to existing attribute block numbering lisp
    By mtreyger in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 4th Jul 2010, 05:42 pm
  2. Attribute Block Lisp
    By BlackAlnet in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 21st May 2009, 05:40 pm
  3. Creating tool (lisp) for copy attribute and global attribute edit
    By MarcoW in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 14th May 2009, 10:41 am
  4. Replies: 21
    Last Post: 21st Nov 2008, 06:54 pm
  5. Block Attribute answers ability to change block Physical Attributes??
    By Kaidoz in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 19th Mar 2008, 09:25 pm

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