+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Senior Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Italy
    Posts
    141

    Default Add attributes to BLOCK in LISP with ENTMAKE

    Registered forum members do not see this ad.

    I get error while adding an attribute to a block using ENTMAKE "attdef".

    What am I doing wrong ?

    Code:
    ;makes a block and inserts to drawing
    (defun C:test_blk()
    (setq x 4 y 4)
    (setq ot 0.3 )
    (if (= ct nil) (setq ct 1))  
    (setvar "CMDECHO" 0)
      (and
        (not (tblsearch "BLOCK"
        (setq blk_nm (strcat "SP" (rtos ct 2 2)))))
        (entmake (list (cons 0 "BLOCK")
                  (cons 2 blk_nm)
                  (list 10 0 0 0)
                  (cons 70 0)))
        
       (entmake (list (cons 0 "3DFACE")(cons 8 "0")
                          (list 10 0 0 0) ;First corner 
                  (list 11 x 0 0) ;Second corner 
                          (list 12 x y 0) ;Third corner 
                  (list 13 0 y 0))) ; Fourth corner 
    
    
    
       (entmake (list (cons 0 "TEXT") ;***
                   (cons 1 "P10") ;Default value (the string itself)
                   (cons 6 "BYLAYER")
                   (cons 7 "STANDARD") ;Text style name 
                   (cons 8 "0")
                   (cons 10 (list (+ ot) ot 0.0)) ;First alignment point 
                   ;(cons 11 (list 0.0 0.0 0.0)) ;***
                   (cons 39 0.0)
                   (cons 40 1.5) ;Text height
                   (cons 41 1.0) ;Relative X scale factor
                   (cons 50 0.0) ;Text rotation 
                   (cons 51 0.0) ;Oblique angle (
                   (cons 62 256)
                   (cons 210 (list 0.0 0.0 1.0))))
    
    ;;;(entmake (list (cons 0 "ATTDEF") ;
    ;;;               (cons 8 "0")
    ;;;               (cons 10 (list ot (+ y ot) 0)) ;Text start point 
    ;;;               (cons 40 2) ;Text height
    ;;;               (cons 1 "55") ;Default value (string)
    ;;;               (cons 2 "TAGNAME") ;Attribute tag (string; cannot contain spaces)
    ;;;               (cons 70 0)
    ;;;               (cons 73 0)
    ;;;               (cons 50 0) ;Text rotation (optional; default = 0)
    ;;;               (cons 41 1) ;Relative X scale factor 
    ;;;               (cons 51 0)
    ;;;               (cons 7 "STANDARD") ;***
    ;;;               (cons 71 0)
    ;;;               (cons 72 0)
    ;;;               ;(cons 11 (list 0 0 0)) ;Alignment point 
    ;;;               (cons 210 (list 0 0 1));Extrusion direction.
    ;;;               (cons 74 0)
    ;;;               (cons 62 256)
    ;;;               (cons 39 0)
    ;;;               (cons 6 "BYLAYER")))
    
      (entmake (list (cons 0 "ENDBLK")(cons 8 "0"))))
      (setq blk_rh (entlast))
      (while (eq blk_rh (entlast))
             (command "_.INSERT" blk_nm))
    
     
      (setq ct (+ ct 1))
    
      );defun
    Last edited by sadhu; 27th Aug 2010 at 12:19 pm.
    lost

  2. #2
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jul 2010
    Posts
    347

    Default

    It woks fine.

    Can you paste the error reply please ?

    Regards

  3. #3
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Look into group 70 of the BLOCK header call. The 2 bit should be set if variable attributes follow.

    Also, a decimal is an invalid block name character. ( rtos ct 2 2 ) includes a decimal.

    Those are for starters at least. -David
    R12 (Dos) - A2K

  4. #4
    Senior Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Italy
    Posts
    141

    Default

    After the block is inserted in dwg I type "ATTEDIT" and select the block - there are no attributes to edit.

    Command: attedit
    Select block reference: That block has no editable attributes.
    lost

  5. #5
    Senior Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Italy
    Posts
    141

    Default

    Thanks David - most of the code is from your post in the SWAMP.

    fixed entmake block :
    Code:
    (cons 70 2)
    Still have to get the attributes working.
    lost

  6. #6
    Senior Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Italy
    Posts
    141

    Default

    Code below seems to work but it isn't satisfactory.

    The ENTMAKE attdef code 3 asks for keyboard input while I want it to be a variable generated in LISP (a counter).

    Is it possible with ENTMAKE or do I have to look for another solution?

    Code:
    (defun c:test_blk ()
    
    (setq x 4 y 4)
    (setq ot 0.3 )
    (if (= ct nil) (setq ct 1))  
    
     
      ;BLOCK Header definition:
      
      (entmake '((0 . "BLOCK")
             (2 . "blk_nm")
             (70 . 2)
             (10 0.0 0.0 0.0)))
      
      ;POINT marker definition:
      
      (entmake '((0 . "POINT")
             (8 . "0")
             (10 0.0 0.0 0.0)
             (210 0.0 0.0 1.0)
             (50 . 0.0)))
    
    (entmake (list (cons 0 "3DFACE")(cons 8 "0")
                          (list 10 0 0 0) ;First corner 
                  (list 11 x 0 0) ;Second corner 
                          (list 12 x y 0) ;Third corner 
                  (list 13 0 y 0))) ; Fourth corner 
      
      
      ;Text ATTRIBUTE definition:
      
      (entmake 
        '((0 . "ATTDEF")
          (8 . "0")
          (10 0.3 4.3 0.0 ) ;First alignment point 
          (1 . "")
          (2 . "num");Tag string (cannot contain spaces)
          (3 . "number ??");Prompt string
          (40 . 2.0)
          (41 . 1.0)
          (50 . 0.0)
          (70 . 0)
          (71 . 0)
          (72 . 0)
          (73 . 2))
      )
    
      
      
      ;BLOCK's ending definition:
      
      (entmake '((0 . "ENDBLK")))
    
    
        (command "_.INSERT" blk_nm)
      
    )
    lost

  7. #7
    Forum Deity
    Using
    Civil 3D 2008
    Join Date
    Sep 2006
    Location
    Pittsburgh, PA, USA
    Posts
    3,581

    Default

    try this
    Code:
    (entmake 
       (list
          (cons 0 "ATTDEF")
          (cons 8 0)
          etc...
          (cons 3 variable);variable should be string
          etc.

  8. #8
    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,816

    Default

    This should perhaps point you in the right direction:

    Code:
    (defun GenerateBlock ( name pt )
    
      (if (not (tblsearch "BLOCK" name))
        (progn
          (entmake
            (list
              (cons 0 "BLOCK")
              (cons 2 name)
              (cons 70 2)
              (cons 10 '(0. 0. 0.))
            )
          )
          (entmake
            (list
              (cons 0 "POINT")
              (cons 8 "0")
              (cons 10 '(0. 0. 0.))
            )
          )
          (entmake
            (list
              (cons 0 "3DFACE")
              (cons 10 '(0. 0. 0.))
              (cons 11 '(4. 0. 0.))
              (cons 12 '(4. 4. 0.))
              (cons 13 '(0. 4. 0.))
            )
          )     
          (entmake
            (list
              (cons 0 "ATTDEF")
              (cons 8 "0")
              (cons 10 '(0.3 4.3 0.0))
              (cons 70 0)
              (cons 1 "")
              (cons 2 "NUM")
              (cons 3 "Number: ")
              (cons 40 2.0)
            )
          )
          (entmake
            (list
              (cons 0 "ENDBLK")
              (cons 8 "0")
            )
          )
        )
      )
    
      (entmake
        (list
          (cons 0 "INSERT")
          (cons 2 name)
          (cons 10 pt)
          (cons 66 1)
        )
      )
      (entmake
        (list
          (cons 0 "ATTRIB")
          (cons 10 pt)
          (cons 1 "YourCounter")
          (cons 2 "NUM")
          (cons 40 2.0)
          (cons 70 0)
        )
      )
      (entmake
        (list
          (cons 0 "SEQEND")
        )
      )
    )
    Lee Mac Programming

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

    Just another Swamper

  9. #9
    Senior Member
    Computer Details
    sadhu's Computer Details
    Operating System:
    Vista
    Using
    AutoCAD 2010
    Join Date
    Feb 2010
    Location
    Italy
    Posts
    141

    Default

    Registered forum members do not see this ad.

    Thanks Lee,

    I will try it.
    lost

Similar Threads

  1. Lisp routine use csv to update title block attributes - on ctab
    By HRae in forum AutoLISP, Visual LISP & DCL
    Replies: 110
    Last Post: 27th Mar 2013, 12:24 am
  2. LISP to insert two attributes, pline length, and mtext into block
    By chelsea1307 in forum AutoLISP, Visual LISP & DCL
    Replies: 23
    Last Post: 1st Jun 2011, 03:00 pm
  3. Modify LISP for changing block attributes
    By hosannabizarre in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 27th Sep 2010, 08:30 am
  4. Auto-edit (LISP>) Title Block Attributes
    By bennn in forum AutoCAD General
    Replies: 10
    Last Post: 30th May 2010, 05:43 pm
  5. Lisp for placing a block with attributes to multiple points
    By Jadeous in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 6th Mar 2009, 10:54 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