Jump to content

Delete all attributes except for certain blocks


Jimmy Sean

Recommended Posts

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 c:DelTXT (/ 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)
)

 

Thnaks

Sean

Link to comment
Share on other sites

Yes I think it is yours and thank you for sharing it. I tried locking the layer that the block was on but if the block definition has the text on layer zero it will still delete the attribute. My issue is I need the room id block, door tag's and the like not to be effected yet delete text from chairs or desks.

Link to comment
Share on other sites

I suppose that would work but one of the blocks is room name and number and could be any value. On top of that I have no clue how. There are only ten block names I need to exclude. With your routine I select all and then tried to remove but you can't remove by name.

Link to comment
Share on other sites

Here is the drawing. Ideally the routine would select all then exclude or remove these blocks from the selection. Bubble, gridbubble-b, gridbubble-l, gridbubble-t, gridbubble-r, rmnm-no, dr-no, windowtype, partiontype, iden.

Testing-2.dwg

Link to comment
Share on other sites

What are the name of blocks that you do not want to delete their attributes ?

 

Bubble, gridbubble-b, gridbubble-l, gridbubble-t, gridbubble-r, rmnm-no, dr-no, windowtype, partiontype, iden

Link to comment
Share on other sites

Did it work for you? It deletes the attributes in all the blocks still.

 

My mistake was with number 8 instead of 2 . :)

 

Try it now ...

 

(defun c:Test (/ ss i sn x)
;;; Tharwat 30. Jan. 2013 ;;;
 (vl-load-com)
 (if (setq ss (ssget "_x" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (not (member (strcase (cdr (assoc 2 (entget sn))))
                      '("BUBBLE"          "GRIDBUBBLE-B"
                        "GRIDBUBBLE-L"    "GRIDBUBBLE-T"
                        "GRIDBUBBLE-R"    "RMNM-NO"
                        "DR-NO"           "WINDOWTYPE"
                        "PARTIONTYPE"     "IDEN"
                       )
              )
         )
       (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)
)

Link to comment
Share on other sites

Thank you so much!!!

 

 

My mistake was with number 8 instead of 2 . :)

 

Try it now ...

 

(defun c:Test (/ ss i sn x)
;;; Tharwat 30. Jan. 2013 ;;;
 (vl-load-com)
 (if (setq ss (ssget "_x" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (not (member (strcase (cdr (assoc 2 (entget sn))))
                      '("BUBBLE"          "GRIDBUBBLE-B"
                        "GRIDBUBBLE-L"    "GRIDBUBBLE-T"
                        "GRIDBUBBLE-R"    "RMNM-NO"
                        "DR-NO"           "WINDOWTYPE"
                        "PARTIONTYPE"     "IDEN"
                       )
              )
         )
       (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)
)

Link to comment
Share on other sites

Tharwat,

 

Is there any significance to the block list being in two columns? I tried adding another block name and is not catching that block. Is there something special I need to do if adding another block name to the list?

 

Thanks,

Sean

Link to comment
Share on other sites

Tharwat,

 

Is there any significance to the block list being in two columns?

 

No at all , that is something related to Visual Lisp editor formatting way .

Tharwat,

 

Is there any s I tried adding another block name and is not catching that block. Is there something special I need to do if adding another block name to the list?

 

Thanks,

Sean

 

The Block name must be add as a string with capital letter . e.g. "BLOCK NAME"

 

Good luck :)

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