Author Topic: attribute value change  (Read 7388 times)

0 Members and 1 Guest are viewing this topic.

danny

  • Guest
attribute value change
« on: July 13, 2005, 11:18:09 PM »
I'm looking for a lisp that can find and replace specific tag values of attribute blocks.
Code: [Select]
find block: symb-qp
replace all blocks with attribute tag:item ,value:REWC and tag:num, value:200
to tag:item, value:REWC and teg:num to value 203

I hope I explained this well enough..

danny

  • Guest
attribute value change
« Reply #1 on: July 14, 2005, 04:57:57 AM »
I've uploaded a drawing in my directory called edit attribute...hoping it will explain my situation better.
http://www.theswamp.org/lilly_pond
what i would like to do is change the block "TEST" with attribute values EBD, keeping the values EB and changing the value D to X.  So the block will read EBX.

I've tried the autocad commands -attedit and gatte but had no luck.  if there is a way to do it without lisp, I would appreciate the tip.
mahalo,

hudster

  • Gator
  • Posts: 2848
attribute value change
« Reply #2 on: July 14, 2005, 05:15:02 AM »
try this
Code: [Select]
-attedit
n
n
test
3
D
D
X
;;END OF SCRIPT


***edit***
scrap that, just realised it changed the values with ABD as well.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
attribute value change
« Reply #3 on: July 14, 2005, 08:30:19 AM »
For a lisp-based solution, you could maybe use something like this (without tweaking it, it only takes one attrib value at a time).
Code: [Select]
(defun changeAttribValue (ent atttag oldval newval / entl)
  (while (and ent (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (and (= atttag (cdr (assoc 2 entl)))
         (= oldval (cdr (assoc 1 entl))) ;<- could use WCMATCH instead
         (entmod (subst (cons 1 newval) (assoc 1 entl) entl))
         (entupd ent)
         (mapcar 'princ (list "\n" oldval " -> " newval))
    )
    (setq ent (entnext ent))
  )
)

(defun C:CHATTRIB (/ ss a attag bname oldval newval)
  (and (/= "" (setq bname (getstring "\nBlock name: ")))
       (/= "" (setq attag (getstring T "\nTag: ")))
       (/= "" (setq oldval (getstring T "\nOld value: ")))
       (/= "" (setq newval (getstring T "\nNew value: ")))
       (setq a  0
             ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname)))
       )
       (repeat (sslength ss)
         (changeAttribValue (ssname ss a) attag oldval newval)
         (setq a (1+ a))
       )
  )
)

CADaver

  • Guest
attribute value change
« Reply #4 on: July 14, 2005, 08:42:10 AM »
Darn Stig, I got interupted by work and you snunk in ahead of me.  I use your changeatt.lsp for about a thousand things.

I think I like this one too, thanks.

SMadsen

  • Guest
attribute value change
« Reply #5 on: July 14, 2005, 09:22:31 AM »
Quote from: CADaver
.. I got interupted by work ...

Darn it! I hate it when that happens.

Glad you can use it. I also use it alot, in different shapes and forms. It's a plain and easy solution that adjusts to many needs.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10387
attribute value change
« Reply #6 on: July 14, 2005, 10:01:16 AM »
"WHAT IF" the attributed blocked are nested one level, like in an x-ref?
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
attribute value change
« Reply #7 on: July 14, 2005, 12:50:03 PM »
Then you're in trouble :D

danny

  • Guest
attribute value change
« Reply #8 on: July 14, 2005, 01:46:05 PM »
STIG,
your lisp worked great, but it still changed all the blocks with the value "D".  What I was hoping to do is change only the blocks with values EBD TO EBX.
So the lisp would need to find all block with attribute values of EBD then allow to change only those from the value D to X.
 :?

danny

  • Guest
attribute value change
« Reply #9 on: July 14, 2005, 02:29:42 PM »
I got this far, but dont know how to pass the "find tag" and "with value" through the selection set.
Code: [Select]
(defun changeAttribValue (ent atttag oldval newval / entl)
  (while (and ent (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (and (= atttag (cdr (assoc 2 entl)))
         (= oldval (cdr (assoc 1 entl))) ;<- could use WCMATCH instead
         (entmod (subst (cons 1 newval) (assoc 1 entl) entl))
         (entupd ent)
         (mapcar 'princ (list "\n" oldval " -> " newval))
    )
    (setq ent (entnext ent))
  )
)

(defun C:CHATTRIB2 (/ ss a attag bname oldval newval)
  (and (/= "" (setq bname (getstring "\nBlock name: ")))
       (/= "" (setq tag (getstring T "\nFind Tag: ")))
       (/= "" (setq value (getstring T "\n:With Value: ")))
       (/= "" (setq attag (getstring T "\nTag: ")))
       (/= "" (setq oldval (getstring T "\nOld value: ")))
       (/= "" (setq newval (getstring T "\nNew value: ")))
       (setq a  0
             ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname)))
       )
       (repeat (sslength ss)
         (changeAttribValue (ssname ss a) attag oldval newval)
         (setq a (1+ a))
       )
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10387
attribute value change
« Reply #10 on: July 14, 2005, 08:58:09 PM »
Well not as pretty as Stig would have done but it works. :)

Code: [Select]
Command: CHATTRIB

Block name: TEST

Tag to change: 3

Old value: D

New value: X

Tag to match: 1

Value to match: E

D -> X
D -> X
D -> X
D -> X
D -> X
D -> X
D -> X
D -> X

Command:


Code: [Select]
(defun changeAttribValue (ent atttag oldval newval attagm matval / entl ok)
  (setq enttop ent
        ok 0
  )
  (while (and ent (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (cond
      ((and (/= "" attagm)
            (/= "" matval)
            (= attagm (cdr (assoc 2 entl)))
            (= matval (cdr (assoc 1 entl)))
       )
       (setq ok (1+ ok))
      )
      ((and (= atttag (cdr (assoc 2 entl)))
            (= oldval (cdr (assoc 1 entl)))
       ) ;<- could use WCMATCH instead
       (setq ok (1+ ok))
      )
    )
    (setq ent (entnext ent))
  )
  (while (and (= ok 2)
              enttop
              (/= "SEQEND" (cdr (assoc 0 (setq entl (entget enttop)))))
         )
    (and (= atttag (cdr (assoc 2 entl)))
         (entmod (subst (cons 1 newval) (assoc 1 entl) entl))
         (entupd enttop)
         (setq ok 0)
         (mapcar 'princ (list "\n" oldval " -> " newval))
    )
    (setq enttop (entnext enttop))
  )
)

(defun C:CHATTRIB (/ ss a attag bname oldval newval attagm matval)
  (and (/= "" (setq bname (getstring "\nBlock name: ")))
       (/= "" (setq attag (getstring t "\nTag to change: ")))
       (/= "" (setq oldval (getstring t "\nOld value: ")))
       (/= "" (setq newval (getstring t "\nNew value: ")))
       (progn
         (setq attagm (getstring t "\nTag to match: "))
         (setq matval (getstring t "\nValue to match: "))
         t
       )
       (setq a  0
             ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname)))
       )
       (repeat (sslength ss)
         (changeAttribValue (ssname ss a) attag oldval newval attagm matval)
         (setq a (1+ a))
       )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

danny

  • Guest
attribute value change
« Reply #11 on: July 14, 2005, 10:11:59 PM »
Dude.....thats sick...
 :shock:
much mahalo's for the lesson CAB...and STIG, the lisp.
 :D