appending to an attribute value

Discussion in 'AutoCAD' started by The Real JD, Feb 14, 2005.

  1. The Real JD

    The Real JD Guest

    I need to append letters to an attribute value within a block

    the block it TBLOCK-A1
    the tag is CONSULDWG but the values vary drawing to drawing. But i just need
    to append the letter "P" to the tag value.
    I'm hoping to do this via script or lisp, so i can run it as a batch on a
    few hundred drawings. Any suggestions?
     
    The Real JD, Feb 14, 2005
    #1
  2. The Real JD

    T.Willey Guest

    Seach the drawing for the block, then search the block for the tag, grab the value, then use strcat to add the P, then replace the value.

    Tim
     
    T.Willey, Feb 14, 2005
    #2
  3. pseudo code use -
    ssget
    foreach block
    entget
    entnext
    while not seqend
    if attrib name = CONSULDWG
    progn
    strcat
    entmod
    entupd
    else
    entnext
     
    Alan Henderson @ A'cad Solutions, Feb 14, 2005
    #3
  4. The Real JD

    hulioman Guest

    Here is a routine that will help.
    Use the existing code and modify it where it prompts for user information. Then remove the Defun, so it will run when you load it.

    Note this routine will only work on blocks with unique attribute tags because it uses the tags to identify the attribute.
    So... if, during the creation of the block, the user just copied the same attribute and did not rename the tag all the attributes with the same tag value will be modified... For example... your titleblock may have three lines where you put cilent data. If the tags for each line is not unique, this routine will modify every line.
     
    hulioman, Feb 14, 2005
    #4
  5. The Real JD

    The Real JD Guest

    Sorry my lisp skill are beginner at best... could you clarify the code for
    me?
     
    The Real JD, Feb 15, 2005
    #5
  6. The Real JD

    BillZ Guest

    Code:
    ;02/15/05
    ;To find Block reference, Attribute tag name and edit TagString attribute.
    ;Usage: (AttTagEdit "BlockReference name" "Attribute tag name" "New string to append")
    ;
    (defun AttTagEdit (BlkNam TagStr NewStr / *mspace*)
    (vl-load-com)
    (setq *mspace* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    )
    ;;;
    (vlax-for item *mspace*
    (if (and (= (vla-get-objectname item)"AcDbBlockReference")
    (= (strcase (vla-get-name item)) BlkNam))
    (mapcar '(lambda (a)
    (if (= (vla-get-TagString a) TagStr)
    (vla-put-TextString a (strcat NewStr (vla-get-TextString a))) ;put NewStr where needed in string.
    )
    )
    (vlax-safearray->list
    (variant-value
    (vla-GetAttributes item)
    )
    )
    )
    )
    )
    ;;;
    (princ)
    )
    Bill
     
    BillZ, Feb 15, 2005
    #6
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.