Author Topic: Delete all Attribute from all blocks except certain blocks  (Read 2025 times)

0 Members and 1 Guest are viewing this topic.

Jimmy Sean

  • Guest
Delete all Attribute from all blocks except certain blocks
« on: January 30, 2013, 09:30:04 AM »
I need to have a lisp routine that will delete all attributes in all block except for certain blocks. Those few need to stay. Also it needs little to no user input.
 
I found this lisp but I don't have a clue on how to add an exclusion list of block names to it. If someone could point me in the right direction it would be appriciated.
 
(defun celTXT (/ ss i sn x)(vl-load-com)
 (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
 (repeat (setq i (sslength ss))
 (setq sn (ssname ss (setq i (1- i))))
 (while
 (not
 (eq (cdr (assoc 0 (entget (setq x (entnext sn))))) "SEQEND")
 )
 (if (eq (cdr (assoc 0 (entget x))) "ATTRIB")
 (vla-delete
 (vlax-ename->vla-object (cdr (assoc -1 (entget x))))
 )
 )
 )
 )
 )
 (princ)
 )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Delete all Attribute from all blocks except certain blocks
« Reply #1 on: January 30, 2013, 09:39:42 AM »
Add groupcode 2 to your filter and add the blocknames to it. Note that wildcards can be used too.

This filter will only grab blocks named blockname1, blockname2 or any block with test in it.
(setq ss (ssget '((0 . "INSERT") (2 . "blockname1,blockname2,*test*") (66 . 1))))

.... and welcome to the swamp  8-)

« Last Edit: January 30, 2013, 09:45:49 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Delete all Attribute from all blocks except certain blocks
« Reply #2 on: January 30, 2013, 09:48:55 AM »
Note that you will also need to delete the attribute definitions from within the respective block definitions, else an ATTSYNC will bring all the attribute references back  ;-)

Welcome to the Swamp Jimmy  :-)

Jimmy Sean

  • Guest
Re: Delete all Attribute from all blocks except certain blocks
« Reply #3 on: January 30, 2013, 10:56:47 AM »
Thanks ronjonp and Lee Mac for the welcome. 

ronjonp I think I understand.  What you added only includes those names listed in the selection.  What if I wanted to select all blocks and then exclude or remove ten block names from the selection?

Lee Mac I don't see that being an issue. 

What I'm trying to accomplish is a cleanup for a client hand-off of the drawing.  I need to keep room names and door tags and the like but remove the text from chairs, tables, etc..

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Delete all Attribute from all blocks except certain blocks
« Reply #4 on: January 30, 2013, 11:04:24 AM »
Thanks ronjonp and Lee Mac for the welcome. 

ronjonp I think I understand.  What you added only includes those names listed in the selection.  What if I wanted to select all blocks and then exclude or remove ten block names from the selection?

...


Use the "_x" part of ssget to select all.
Put a tilde in front of the names in your filter and it will exclude them.

(setq ss (ssget "_x" '((0 . "INSERT") (2 . "~blockname1,~blockname2") (66 . 1))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jimmy Sean

  • Guest
Re: Delete all Attribute from all blocks except certain blocks
« Reply #5 on: January 30, 2013, 11:24:46 AM »
Quote
Use the "_x" part of ssget to select all.
Put a tilde in front of the names in your filter and it will exclude them.

(setq ss (ssget "_x" '((0 . "INSERT") (2 . "~blockname1,~blockname2") (66 . 1))))

If I'm understanding correctly like this?
(if (setq ss (ssget "all" '((0 . "INSERT") (2 . "~rmnm-no,~dr-no") (66 . 1))))

Jimmy Sean

  • Guest
Re: Delete all Attribute from all blocks except certain blocks
« Reply #6 on: January 30, 2013, 11:30:17 AM »
Here is a sample drawing if it helps.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Delete all Attribute from all blocks except certain blocks
« Reply #7 on: January 30, 2013, 11:31:08 AM »
Change your "all" to "_x" to make sure you grab everything ... your filter looks correct.
« Last Edit: January 30, 2013, 11:38:52 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Delete all Attribute from all blocks except certain blocks
« Reply #8 on: January 30, 2013, 11:43:03 AM »
Jimmy , are you still looking for a solution , or my codes worked for you as needed ?  :kewl:

Jimmy Sean

  • Guest
Re: Delete all Attribute from all blocks except certain blocks
« Reply #9 on: January 30, 2013, 11:58:45 AM »
Nope you are the man thanks.  Thanks Tharwat and ronjonp for the patience, guidence and help.  For those interested http://www.cadtutor.net/forum/showthread.php?76958-Delete-all-attributes-except-for-certain-blocks/page2