Manipulating Block attributes

Discussion in 'AutoCAD' started by Chip Harper, Feb 8, 2004.

  1. Chip Harper

    Chip Harper Guest

    On occasion we fill our revision block so we have to scroll the oldest off
    to insert the newest (ie REVA-REVB-REVC becomes REVB-REVC-REVD).

    I'm stuck getting the value of the 2nd attribute tag ....

    (defun C:RevUpdate ()
    ;;
    ;; ***Select Revision Block***
    ;;
    (setq RUBLK (car (entsel "\nSelect Revision Block: ")))


    ;;
    ;; ***Locate Attribute Tag***
    ;;
    (defun RevReset ()
    (while (/= tag REVAL1)
    (setq ENTY (entget RUBLK))
    (setq TAG (cdr (assoc 2 ENTY)))
    (setq RUBLK (entnext RUBLK))
    )

    ;; <----STUCK HERE,
    ;; I need the value applied to REVAL2 to use in Update Tags section
    ;;
    (while (/= tag REVAL2)
    (setq ENTY2 (entget RUBLK))
    (setq TAG2 (cdr (assoc 1 ENTY2)))
    (setq RUBLK (entnext RUBLK))
    )

    ;;
    ;; ***Update Tags***
    ;;
    (setq ENTI (subst (cons 1 TAG2) (assoc 1 ENTY) ENTY))
    (entmod ENTI)
    (entupd RUBLK)
    ) ; End RevReset


    ;;
    ;; ***Set Line Numbers***
    ;;
    (setq LINE_NUM '(1 2 3 4 5 6))
    (foreach REVN LINE_NUM
    (progn
    (setq REVAL1 (strcat "REV_MARK" (itoa REVN)))
    (setq REVAL2 (strcat "REV_MARK" (itoa (+ 1 REVN))))
    (RevReset)
    ) ; End progn

    (progn
    (setq REVAL1 (strcat "REV_DATE" (itoa REVN)))
    (setq REVAL2 (strcat "REV_DATE" (itoa (+ 1 REVN))))
    (RevReset)
    ) ; End progn

    (progn
    (setq REVAL1 (strcat "REV_TYPE" (itoa REVN)))
    (setq REVAL2 (strcat "REV_TYPE" (itoa (+ 1 REVN))))
    (RevReset)
    ) ; End progn

    ) ; Foreach
    ) ; Defun


    (C:RevUpdate)
     
    Chip Harper, Feb 8, 2004
    #1
  2. Chip Harper

    dean_bourke Guest

    You need to use entnext to step thru the block and attributes
    eg.
    (entget (setq ent(entnext ent)))
    repeating this will step thru the block and attributes.
    Best do a check along the way for (0 . "SEQEND") that denotes the end of attributes.

    Dean
     
    dean_bourke, Feb 8, 2004
    #2
  3. I use this:

    ; return a list of all attribs in EntNam in form:
    ; (("TAG" "value" <Entity name: 400cbf70>) ...)
    ;
    (defun ALE_GetAttribs (EntNam / EntDat OutLst)
    (while
    (/=
    "SEQEND"
    (DXF 0 (setq EntDat (entget (setq EntNam (entnext EntNam)))))
    )
    (setq OutLst
    (cons
    (list (DXF 2 EntDat) (DXF 1 EntDat) (DXF -1 EntDat))
    OutLst
    )
    )
    )
    )

    (defun DXF (code elist)
    (cdr (assoc code elist))
    )


    Example:

    Command: (setq EntNam (car (entsel)))

    Select objects: <Nome entità: 40084c40>

    Command: (setq AttLst (ALE_GetAttribs EntNam))
    (("ITEM_QTY" "1" <Nome entità: 40084c58>)
    ("ITEM_DESCR" "S/S Plate" <Nome entità: 40084c50>)
    ("ITEM_NO" "42012" <Nome entità: 40084c48>))

    To get a value:
    Command: (DXF "ITEM_QTY" AttLst)
    ("1" <Nome entità: 40084c58>)

    To put a value:
    Command: (setq AttInf (DXF "ITEM_QTY" AttLst))
    ("1" <Nome entità: 40084c58>)

    Command: (entmod (list (cons -1 (cadr Attinf)) (cons 1 "NewValue")))
    ((-1 . <Nome entità: 40084c58>) (1 . "NewValue"))

    Command: (entupd (cadr Attinf))
    <Nome entità: 40084c58>

    Example to filter attribs:

    (setq AttNms '("ITEM_QTY" "ITEM_NO"))

    ; put a null string in all AttNms:
    (foreach ForElm AttNms
    (entmod (list (cons -1 (caddr (assoc ForElm AttLst))) (cons 1 "")))
    )

    HTH

    Marco
     
    Marc'Antonio Alessi, Feb 9, 2004
    #3
  4. Chip Harper

    Chip Harper Guest

    Ok thanks guys, I'll give it another run tonight.
     
    Chip Harper, Feb 9, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.