Cad Guy Posted October 1, 2009 Share Posted October 1, 2009 Before I start this is an amazing site, very helpful Now for my question. I have this project were we are using the customers blocks. And there are many attributes with there own "Tags" with in the blocks that's need edited. For an example: Block Name ABC_123 TAG Value AAAA #### TAG Value BBBB #### and so on And I want to give them different values for each. A simple find and replace will work fine in this case but every block used has the same tags in them and I don't want to update them all. I was wondering if there was a way I could do a search and replace based on Tag name and not the value. Like a search for Tag AAAA and replace its Value with 4321, Tag BBBB and replace its Value with 8765. And the values would be used for the whole drawing set. Can any one help me out with this? Quote Link to comment Share on other sites More sharing options...
gile Posted October 1, 2009 Share Posted October 1, 2009 Hi, Here's a quickie (defun c:setAtt (/ ent elst val ss tag) (if (and (setq ent (car (nentsel "\nSelect the attribute: "))) (setq elst (entget ent)) (= (cdr (assoc 0 elst)) "ATTRIB") (setq val (getstring "\nNew value: ")) (princ "\nSelect blocks to be edited (Enter for all)") (or (setq ss (ssget (list '(0 . "INSERT") (assoc 2 (entget (cdr (assoc 330 elst)))))) ) (setq ss (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget (cdr (assoc 330 elst))))) ) ) ) (setq tag (cdr (assoc 2 elst))) (setq n 0) ) (progn (while (setq ent (ssname ss n)) (SetAttValue ent tag val) (setq n (1+ n)) ) ) (princ "\nInvalid input") ) (princ) ) ;;; SetAttValue (gile) ;;; Sets a value to an attribute ;;; ;;; Arguments ;;; blk : block ename ;;; tag : attribute tag ;;; val : new value (defun SetAttValue (blk tag val / lst loop) (setq lst (entget (entnext blk)) loop (= "ATTRIB" (cdr (assoc 0 lst))) ) (while loop (if (= (strcase tag) (cdr (assoc 2 lst))) (progn (entmod (subst (cons 1 val) (assoc 1 lst) lst)) (setq loop nil) (entupd blk) ) (setq lst (entget (entnext (cdr (assoc -1 lst)))) loop (= "ATTRIB" (cdr (assoc 0 lst))) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Cad Guy Posted October 1, 2009 Author Share Posted October 1, 2009 For give me, but I'm a new to the lisp format. but when I run it it gave me an error. Select blocks to be edited (Enter for all); error: bad argument type: lentityp 0.0 Quote Link to comment Share on other sites More sharing options...
gile Posted October 1, 2009 Share Posted October 1, 2009 Sorry, there was an error, I edited the code. Give a try with the new one. Quote Link to comment Share on other sites More sharing options...
Cad Guy Posted October 1, 2009 Author Share Posted October 1, 2009 almost.... Select blocks to be edited (Enter for all)Select objects: Specify opposite corner: 2 found Select objects:; error: no function definition: SETATTVALUE Quote Link to comment Share on other sites More sharing options...
Cad Guy Posted October 1, 2009 Author Share Posted October 1, 2009 oops, I got it. I think my copy of the code was missing the last part. But it works now, Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.