Delete single Attribute and Text from a Block

Delete single Attribute and Text from a Block

brian_shick
Enthusiast Enthusiast
1,645 Views
8 Replies
Message 1 of 9

Delete single Attribute and Text from a Block

brian_shick
Enthusiast
Enthusiast

We have the need to remove an Attribute and a Text string from our existing title blocks.

Is there a simple way to run a LISP or a Command that will refresh-update the title block with a new block of the same name that has been revised to not have the attribute and text?  We have several hundred drawings that will need the update and are asking for suggestions on how to proceed... 

Is there a better way I am not remembering...?

 

Block Name: "36x24_TB"

Attribute to be removed: "ACCURACY_STATUS"

Text to be deleted: "Verification:"

 

0 Likes
Accepted solutions (1)
1,646 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Mentor
Mentor
Accepted solution

Give this a try ... you'll need to make sure that the items are not on locked layers.

(defun c:foo (/ bn)
  ;; RJP » 2018-11-07
  (setq bn "36x24_TB")
  (cond
    ((tblobjname "block" bn)
     (vlax-for x (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bn)
       (cond
	 ((and (vlax-property-available-p x 'tagstring) (= "ACCURACY_STATUS" (vla-get-tagstring x)))
	  (vla-delete x)
	 )
	 ((and (vlax-property-available-p x 'textstring) (= "VERIFICATION:" (vla-get-textstring x)))
	  (vla-delete x)
	 )
       )
     )
     (command "_.attsync" "name" bn)
    )
  )
  (princ)
)
(vl-load-com)
Message 3 of 9

dbhunia
Advisor
Advisor

Hi,

 

You can try this........(command is "EB")

 

(defun ATTDEL (blkname attname / bn bd en ed attlst)
(vl-load-com) (if (setq bn (tblobjname "BLOCK" blkname)) (progn (setq bd (entget bn) en (cdr (assoc -2 bd)) attlst nil ) (while en (setq ed (entget en)) (if (= "ATTDEF" (cdr (assoc 0 ed))) (setq attlst (cons (cons (strcase (cdr (assoc 2 ed))) (vlax-ename->vla-object en)) attlst)) ) (setq en (entnext en)) ) (if (setq en (assoc (strcase attname) attlst)) (progn (setq ed (cdr en)) (vla-Delete ed) (command "_.ATTSYNC" "_Name" blkname) ) ) ) ) (princ) ) (defun TEXTDEL (nme val / acdoc lst Blockdefinition txt) (vl-load-com) (setq acdoc (vla-get-activedocument (vlax-get-acad-object))) (setq lst '()) (if (not (member nme lst)) (progn (setq Blockdefinition (vla-item (vla-get-blocks acdoc) nme)) (vlax-for x Blockdefinition (if (and (eq :vlax-false (vla-get-isxref Blockdefinition)) (eq :vlax-false (vla-get-islayout Blockdefinition)) (eq (vla-get-objectname x) "AcDbText") ) (progn (setq txt (vla-get-textString x)) (if (= txt val)(vla-delete x)) ) ) ) (setq lst (cons nme lst)) ) ) (princ) (vla-regen acdoc acAllViewports) (princ) ) (defun C:EB (/) (ATTDEL "36x24_TB" "ACCURACY_STATUS") (TEXTDEL "36x24_TB" "Verification:") (princ) )

 

For more check this ......

 

Delete Attribute and for Delete Text


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 9

brian_shick
Enthusiast
Enthusiast

Than you so much... this seems to do what I need. 

But I do have a question... what is the (vl-load-com) at the end of code for? What does it do?

0 Likes
Message 5 of 9

ronjonp
Mentor
Mentor

Glad it worked for you. 🙂 (vl-load-com) loads the ActiveX functions (vl-*,vla-*vlax-* and so on)

Message 6 of 9

Anonymous
Not applicable

This is great and very helpful and this is similar to what I have right now.

One more question. How can we make this a single command on multiple Block name.

Let's say, "36x24_TB", "36x24_T-1", "36x24_TB_2", "36x24_TB_3" and so forth

0 Likes
Message 7 of 9

ronjonp
Mentor
Mentor

You could try something like this:

(defun _foo (bn)
  ;; RJP » 2018-11-13
  (cond
    ((tblobjname "block" bn)
     (vlax-for x (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bn)
       (cond
	 ;; You'll need to modify these conditions below to suit your needs
	 ((and (vlax-property-available-p x 'tagstring) (= "ACCURACY_STATUS" (vla-get-tagstring x)))
	  (vla-delete x)
	 )
	 ((and (vlax-property-available-p x 'textstring) (= "VERIFICATION:" (vla-get-textstring x)))
	  (vla-delete x)
	 )
       )
     )
     (command "_.attsync" "name" bn)
    )
  )
  (princ)
)
(vl-load-com)

(foreach name '("36x24_TB" "36x24_T-1" "36x24_TB_2" "36x24_TB_3") (foo name))
Message 8 of 9

Anonymous
Not applicable

This is excellent. Thanks

 

0 Likes
Message 9 of 9

ronjonp
Mentor
Mentor

Glad to help. 🙂

0 Likes