Global replacement of an attribute value

Discussion in 'AutoCAD' started by Chris Shoemaker, Nov 18, 2004.

  1. Does anyone know of a way to replace all the values of a certain attribute
    in a certain block from some arbitrary value to a single select value? I've
    tried using the -attedit command, but at the "Enter String to Change" prompt
    it doesn't seem to accept wildcards, meaning I'd have to know the exact
    value of the attribute before I set it to something else.

    Anyone have any ideas?

    -Chris
     
    Chris Shoemaker, Nov 18, 2004
    #1
  2. Chris Shoemaker

    Dann Guest

    Do you know the Tag of the attribute? also need block name.
     
    Dann, Nov 18, 2004
    #2
  3. Chris Shoemaker

    ecable Guest

    Express tools, Blocks, Global Attribute Edit.
    At the prompt enter b for block name,
    type in the name of the block,
    enter the tag name,
    and then the new value.
    Hope that is what you were looking for.
     
    ecable, Nov 18, 2004
    #3
  4. He doesn't need to know these things beforehand,
    they're generally treated as user-input, so you just
    have the program prompt for them.
     
    Tony Tanzillo, Nov 18, 2004
    #4
  5. entmod ?
     
    civilychallenged, Nov 18, 2004
    #5
  6. (defun c:whatever ()
    (prompt "\nSelect Ent:")
    (setq ent1 (entsel))
    (setq lista (entget (entlast))
    (setq listitem (cdr (assoc [dxfnumber])))
    .....and on to update using entmod and subst
     
    civilychallenged, Nov 18, 2004
    #6
  7. Chris Shoemaker

    Jürg Menzi Guest

    Hi Chris

    This one may help to find a solution:
    Code:
    (defun ChgAttVal (ent lst / curenl curent curnme entnme newval tmpenl)
    (if (= 'ENAME (type ent))
    (setq curent ent)
    (setq curent (entnext))
    )
    (while curent
    (setq curenl (entget curent)
    entnme (cdr (assoc 0 curenl))
    )
    (cond
    ((= entnme "ATTRIB")
    (setq curnme (cdr (assoc 2 curenl)))
    (if (member curnme (mapcar 'car lst))
    (setq newval (cdr (assoc curnme lst))
    tmpenl (subst (cons 1 newval) (assoc 1 curenl) curenl)
    curenl (entmod tmpenl)
    )
    )
    (setq curent (entnext curent))
    )
    ((= "INSERT" entnme)
    (ChgAttVal (cdr (assoc -2 (tblsearch "BLOCK" (cdr (assoc 2 curenl))))) lst)
    (setq curent (entnext curent))
    )
    (T
    (setq curent (entnext curent))
    )
    )
    )
    )
    
    (defun C:CAV ()
    (prompt "\nChanging Attributes...")
    (ChgAttVal nil '(("YourTag1" . "YourAttVal1")("YourTag2" . "YourAttVal2")))
    (command "_.REGEN")
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Nov 18, 2004
    #7
  8. Jürg Menzi a exposé le 18/11/2004 :
    Hello,
    Sorry for my poor english (french user)
    Fisrt thing, thanks for your web site and you help !

    I search to modify your lisp progs but i have some problems.
    I want to read a text file :

    myfile.txt in this one there is :
    attname1=value1
    attname2=value2
    ....
    attnameN=valueN

    And then modify all these attribut with reads values !

    Thanks, Daniel
     
    OLIVES Daniel, Mar 8, 2005
    #8
  9. Chris Shoemaker

    Jürg Menzi Guest

    Salü Daniel

    This is a possible solution:
    Code:
    ;
    ; == Main =====================================================================
    ;
    (defun C:CAV ( / AttLst CurLin FilNme OpnFil TmpVal)
    (setq FilNme "c:\\Temp\\MyFile.txt")
    (if (findfile FilNme)
    (progn
    (setq OpnFil (open FilNme "r"))
    (while (setq CurLin (read-line OpnFil))
    (setq TmpVal (MeString2List CurLin "=")
    AttLst (cons (cons (car TmpVal) (cadr TmpVal)) AttLst)
    )
    )
    (close OpnFil)
    (if AttLst
    (progn
    (prompt "\nChanging Attributes...")
    (MeChgAttVal nil AttLst)
    (command "_.REGEN")
    )
    )
    )
    )
    (princ)
    )
    ;
    ; == Subs =====================================================================
    ;
    ; == Function MeChgAttVal
    ; Changes attribute values also in nested blocks.
    ; Arguments [Type]:
    ;   Ent = Entity [ENAME]
    ;   Lst = Attribute list '(("TagName" . "Value")...) [LIST]
    ; Return [Type]:
    ;   > Modified entity [ENAME]
    ; Notes:
    ;   None
    ;
    (defun MeChgAttVal (Ent Lst / CurEnl CurEnt CurNme EntNme NewVal)
    (if (= 'ENAME (type Ent))
    (setq CurEnt Ent)
    (setq CurEnt (entnext))
    )
    (while CurEnt
    (setq CurEnl (entget CurEnt)
    EntNme (cdr (assoc 0 CurEnl))
    )
    (cond
    ((= EntNme "ATTRIB")
    (setq CurNme (cdr (assoc 2 CurEnl)))
    (if (member CurNme (mapcar 'car Lst))
    (setq NewVal (cdr (assoc CurNme Lst))
    CurEnl (entmod (subst (cons 1 NewVal) (assoc 1 CurEnl) CurEnl))
    )
    )
    (setq CurEnt (entnext CurEnt))
    )
    ((= "INSERT" EntNme)
    (MeChgAttVal (cdr (assoc -2 (tblsearch "BLOCK" (cdr (assoc 2 CurEnl)))))
    Lst)
    (setq CurEnt (entnext CurEnt))
    )
    (T
    (setq CurEnt (entnext CurEnt))
    )
    )
    )
    )
    ;
    ; == Function MeString2List
    ; Converts a string to a list.
    ; Arguments [Type]:
    ;   Stg = String [STR]
    ;   Del = Delimiter pattern [STR]
    ; Return [Type]:
    ;   > Converted string [LIST]
    ;   > False if string empty
    ; Notes:
    ;   None
    ;
    (defun MeString2List (Stg Del / DelLgt StrPos TmpLst TmpStr)
    (if (not (eq Stg ""))
    (progn
    (setq TmpStr Stg
    DelLgt (1+ (strlen Del))
    )
    (while (setq StrPos (vl-string-search Del TmpStr))
    (setq TmpLst (cons (substr TmpStr 1 StrPos) TmpLst)
    TmpStr (substr TmpStr (+ StrPos DelLgt))
    )
    )
    (setq TmpLst (cons TmpStr TmpLst))
    (reverse TmpLst)
    )
    )
    )
    
    Cheers
     
    Jürg Menzi, Mar 10, 2005
    #9
  10. Jürg Menzi a écrit :
    Bonjour,
    Yhank you very mutch !
    I try to do some test, just when I come back
    from an external work !
    (I give you a feed back soon )
    Daniel
     
    OLIVES Daniel, Mar 10, 2005
    #10
  11. OLIVES Daniel a pensé très fort :
    Hello,
    It works fine ! I have modify it a litle to do what i really want.
    Daniel
     
    OLIVES Daniel, Mar 15, 2005
    #11
  12. Chris Shoemaker

    Jürg Menzi Guest

    Hi Daniel

    Glad to hear that helped...¦-)

    Cheers
     
    Jürg Menzi, Mar 15, 2005
    #12
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.