Change couple attribute value in a block

Change couple attribute value in a block

Bin2009
Advocate Advocate
1,027 Views
5 Replies
Message 1 of 6

Change couple attribute value in a block

Bin2009
Advocate
Advocate

I found some lisp they are able to modify block attribute, but I just want to a simple one can directly change couple attribute value in a block. The block name is "TITLE-A1"

I want change tag “DATE_A” value to “17/06/10”

This attribute tag name is unique in whole drawing, can I just simply use SETQ to do it? I tried

(setq DATE_A "17/06/10")

Doesn’t work, I search previous post, someone use “change-one-att”, but I don’t know how to use it.

Is anyone have any suggestion, thank for your help in advance.

Bin

0 Likes
Accepted solutions (1)
1,028 Views
5 Replies
Replies (5)
Message 2 of 6

doglips
Advocate
Advocate

I think this might get you there...

 

(setq BlockSearch (ssget "X" '((2 . "TITLT-A1")))) ;;;finds the block
(setq BlockSearch (ssname BlockSearch 0));; finds the block entity name
(defun designsearch() ;;; little function to make spepping through block atts easier
(setq DesignEntity BlockSearch)
(setq DesigntagSearch (entnext DesignEntity))
);;defun


(designsearch) ;;calls the little function
(setq b (cdr(assoc 2 (entget DesigntagSearch))))
(while (/= b "DATE_A")
(setq DesigntagSearch (entnext DesigntagSearch))
(setq b (cdr(assoc 2 (entget DesigntagSearch))))
);;while
(setq old (assoc 1 (entget DesigntagSearch))) ;;finds old value
(setq new (cons 1 "17/06/10")) ;;creates new value
(setq newvalu (subst new old (entget DesigntagSearch))) ;;;swaps them out
(entmod newvalu) ;;modifies the entity name
(entupd (cdr(assoc -1 (entget DesigntagSearch)))) ;;updates the entity

Message 3 of 6

Ranjit_Singh
Advisor
Advisor

Yet another option

(defun c:somefunc  (/ etdata)
 (mapcar '(lambda (x)
           (while (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget (setq x (entnext x)))))))
            (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                 (mapcar '(lambda (x y)
                           (and (= x (cdr (assoc 2 etdata))) (entmod (subst (cons 1 y) (assoc 1 etdata) etdata))))
                         '("DATE_A" "TAG2"); pass the tag names here
                         '("17/06/09" "VAL2"))))); pass the new values here for each tag listed above
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "INSERT") (66 . 1) (2 . "TITLE-A1")))))))
Message 4 of 6

Bin2009
Advocate
Advocate

Hello,

Thank for your quick reply, both of your lisp are working in Autocad, but doesn’t work in Civil 3D, show error information as:

error: bad argument type: lselsetp nil

I don’t know why.

Thanks

BIN

0 Likes
Message 5 of 6

doglips
Advocate
Advocate
Please hit F2 and let me know what the error says
0 Likes
Message 6 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

As long as you have a block, it is named "TITLE-A1" and it has attributes then there should be no selection set empty error. Is the block named something else? missing attributes? 

If you want to go through all the blocks and not restrict yourself to TITLE-A1 block then try below.

(defun c:somefunc  (/ etdata)
 (mapcar '(lambda (x)
           (while (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget (setq x (entnext x)))))))
            (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                 (mapcar '(lambda (x y)
                           (and (= x (cdr (assoc 2 etdata))) (entmod (subst (cons 1 y) (assoc 1 etdata) etdata))))
                         '("DATE_A" "TAG2"); pass the tag names here
                         '("17/06/09" "VAL2"))))); pass the new values here for each tag listed above
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "INSERT") (66 . 1)))))))