Jump to content

Many Attdribute Tags in Blocks (Editing)


Cad Guy

Recommended Posts

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?

 

 

 

 

Link to comment
Share on other sites

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)))
     )
   )
 )
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

almost....

 

Select blocks to be edited (Enter for all)

Select objects: Specify opposite corner: 2 found

Select objects:; error: no function definition: SETATTVALUE

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...