Lisp to remove text from a selected block attribute

Lisp to remove text from a selected block attribute

neabailey
Enthusiast Enthusiast
1,877 Views
10 Replies
Message 1 of 11

Lisp to remove text from a selected block attribute

neabailey
Enthusiast
Enthusiast

I have some blocks with multiple attributes pre-filled out. Is there a way to remove the text from an attribute I select by clicking on it? I know I can edit the attribute to delete the text, or view the properties and edit that way. I'm hoping to eliminate opening, then editing, then closing the attribute editor when i just need the text deleted. 

 

I love Lee Mac's Copy Text command, as it sees the text you select regardless of whether its in a block or attribute of whatever. Is there a lisp like that, but instead of Copying the text it deletes it?

 

~nic

0 Likes
Accepted solutions (1)
1,878 Views
10 Replies
Replies (10)
Message 2 of 11

ronjonp
Advisor
Advisor

If you don't want the editor to pop up hold down CNTRL then double click on the attribute to edit.

 

Here's some quick code to do multiple ... you'll have to supply the tag names that are to be edited.

(defun c:foo (/ s tags)
  ;; Edit this list to your needs
  (setq tags '("TAGNAME1" "TAGNAME2" "TAGNAME2"))
  (if (setq s (ssget ":L" '((0 . "INSERT") (66 . 1))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (foreach tag tags (vl-catch-all-apply 'setpropertyvalue (list e tag "")))
    )
  )
  (princ)
)
0 Likes
Message 3 of 11

neabailey
Enthusiast
Enthusiast
Thanks for that suggestion!! I have no idea why thats the first I've heard of it. It'll be awesome for editing, however it won't allow a complete deletion of the text. Not sure why but when you use the control key (ATTIPEDIT) it wont allow for the attribute to be empty.

for the lisp, is there a way to make one that isn't "Tag name" dependent? My hope is to be able to type the command prompt, and select the text I need deleted, one attribute at a time, not all at once. That way it'll work with the many blocks with attribute I have.

For Example, one block has 35 attributes, and I might need 6 attributes emptied. And the next one might need 20 other ones deleted.
0 Likes
Message 4 of 11

pendean
Community Legend
Community Legend

@neabailey   Give the attached a try, read the top of the LISP for limitations and other info

0 Likes
Message 5 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

This should do the trick

 

(defun c:AttEmpty ( / e)
  (while (setq e (car (nentsel "Pick attribute: ")))
    (setpropertyvalue (cdr (assoc 330 (entget e))) (cdr (assoc 2 (entget e))) ""))
  (princ)
  )
Message 6 of 11

neabailey
Enthusiast
Enthusiast
Ive seen that lisp before, but it empties all the attributes not just the one i pick.
0 Likes
Message 7 of 11

neabailey
Enthusiast
Enthusiast
Yesss!!!!
This was exactly what I was looking for. Thank you for this!
0 Likes
Message 8 of 11

ronjonp
Advisor
Advisor

@neabailey wrote:
Yesss!!!!
This was exactly what I was looking for. Thank you for this!

FWIW, If you don't want to pick each attribute, the code I provided above could prove to be much more efficient if you supply the correct tag names to process.

0 Likes
Message 9 of 11

Sea-Haven
Mentor
Mentor

Setproperty does not work with Bricscad so entmod would be better. Or the VL-put-textstring.

0 Likes
Message 10 of 11

Sea-Haven
Mentor
Mentor

Agree with Ronjonp using tagname probably a multi version v's a single pick, just get tagname and block name using Nentsel, then use a simple ssget to choose blocks to be changed. A single block would still work.

0 Likes
Message 11 of 11

neabailey
Enthusiast
Enthusiast
@ronjonp & @Sea-Haven
The Problem is the tags that need clearing are different for every block inserted, its based on the current project design, so a tag based delete wouldn't be more efficient because it is different everytime. The Lisp @ВeekeeCZ provided is a perfect solution for what I needed.
0 Likes