TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: danny 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.
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..
-
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,
-
try this
-attedit
n
n
test
3
D
D
X
;;END OF SCRIPT
***edit***
scrap that, just realised it changed the values with ABD as well.
-
For a lisp-based solution, you could maybe use something like this (without tweaking it, it only takes one attrib value at a time).
(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))
)
)
)
-
Darn Stig, I got interupted by work and you snunk in ahead of me. I use your changeatt.lsp (http://www.theswamp.org/phpBB2/viewtopic.php?p=14297#14297) for about a thousand things.
I think I like this one too, thanks.
-
.. 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.
-
"WHAT IF" the attributed blocked are nested one level, like in an x-ref?
-
Then you're in trouble :D
-
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.
:?
-
I got this far, but dont know how to pass the "find tag" and "with value" through the selection set.
(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))
)
)
)
-
Well not as pretty as Stig would have done but it works. :)
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:
(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)
)
-
Dude.....thats sick...
:shock:
much mahalo's for the lesson CAB...and STIG, the lisp.
:D