Author Topic: Remove or modify all block descriptions  (Read 6448 times)

0 Members and 1 Guest are viewing this topic.

cadmoogle

  • Guest
Remove or modify all block descriptions
« on: January 06, 2009, 08:01:29 AM »
s it possible to remove all existing block definitions VIA lisp?

Name: 1WM_METER
Description: 1" Water main meter

I need to modify or remove the old descriptions completely. If I could remove I would like to do this to a large number if possible.

I'm not sure if AutoCAD has a built in feature for this, does anyone else know?

**I found a way to remove the descriptions from the tool palette, but not in AutoCAD without redefining the block.

Thanks in advance,
Daniel

For the members who use Cadalyst, my post link for that site is http://forums.cadalyst.com/showthread.php?p=23252#post23252
« Last Edit: January 06, 2009, 09:04:31 AM by CAB »

dustinthiesse

  • Guest
Re: Remove or modify all block definitions
« Reply #1 on: January 06, 2009, 08:55:12 AM »
Not sure exactly what you're wanting here.
These two lines will delete all blocks named 1WM_METER from your drawing and purge the definition.

Code: [Select]
(command "_erase" (ssget "X" '((0 . "INSERT")(2 . "1WM_METER"))) "")
(command "_-purge" "blocks" "1WM_METER" "n")

cadmoogle

  • Guest
Re: Remove or modify all block definitions
« Reply #2 on: January 06, 2009, 08:58:27 AM »
I don't wish to delete the block it self just the description. Sorry I just noticed I placed definition in the subject  :lol:

I was able to piece the following code together from what others have posted online. It will work on just one block (16X16WM_CROSS), how can I modify it to work on all blocks in the drawing?

Thank you,
Daniel

Code: [Select]
(defun c:bwipe ()
(setq a (entget (tblobjname "block" "16X16WM_CROSS")))
(setq a (append a (list (cons 4 "DESCRIPTION HERE"))))
(entmake a)
(setq b (cdr (assoc -1 a)))
(while (setq b (entnext b))
(entmake (entget b))
)
(setq e (entmake (list (cons 0 "endblk"))))
)

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #3 on: January 06, 2009, 10:00:58 AM »
Ahhh...I misunderstood.  So you want to get rid of all block descriptions in the drawing?
Something like this perhaps?

Code: [Select]
(defun c:bwipe()
  (defun wipeone (bname)
    (setq a (entget (tblobjname "block" bname)))
    (setq a (append a (list (cons 4 "DESCRIPTION HERE"))))
    (entmake a)
    (setq b (cdr (assoc -1 a)))
    (while (setq b (entnext b))
      (entmake (entget b))
    )
    (setq e (entmake (list (cons 0 "endblk"))))
  );defun wipeone

  (setq bname(cdr(assoc 2(tblnext "BLOCK" 1))))
  (wipeone bname)
  (while(/= (setq bname(cdr(assoc 2(tblnext "BLOCK")))) nil)
    (wipeone bname)
  );while
  (princ)
);defun bwipe
(princ "BWIPE")
« Last Edit: January 06, 2009, 10:31:34 AM by dustinthiesse »

cadmoogle

  • Guest
Re: Remove or modify all block descriptions
« Reply #4 on: January 06, 2009, 10:18:41 AM »
Thanks for the quick reply when I run the command I get the following error.


Quote
Command:
Command: (LOAD "C:/Documents and Settings/dgj520/Desktop/TES2T.lsp")
BWIPE"BWIPE"

Command: bwipe
; error: bad argument type: stringp ((0 . "BLOCK") (2 . "12WM_22.5BEND") (70 .
0) (4 . "12\" 22-1/2D BEND FOR WATER MAIN") (10 0.0 0.0 0.0) (-2 . <Entity
name: 7ef23478>))

Command:

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #5 on: January 06, 2009, 10:33:19 AM »
That's what I get for typing faster than I'm thinking.
I've edited the code above to set the block name correctly.
One thing I think I need to add is a filter for xrefs though.  It might crash on an xref.
NOTE:  If you're trying to get rid of the descriptions then you'll want to get rid of the "DESCRIPTION HERE" part.
Change it to "" instead.

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #6 on: January 06, 2009, 10:48:36 AM »
OK Here's the whole code again.
Now it filters out xrefs and xref blocks so it won't crash in those cases.

Code: [Select]
(defun c:bwipe()
  (defun wipeone (bname)
    (setq a (entget (tblobjname "block" bname)))
    (setq a (append a (list (cons 4 ""))))
    (entmake a)
    (setq b (cdr (assoc -1 a)))
    (while (setq b (entnext b))
      (entmake (entget b))
    )
    (setq e (entmake (list (cons 0 "endblk"))))
  );defun wipeone

  (setq blk(tblnext "BLOCK" 1))
  (if(and
       (not(assoc 1 blk)) ;not xref
       (not(vl-string-position (ascii "|") (cdr(assoc 2 blk)))) ;not part of xref
     )
    (progn
      (setq bname(cdr(assoc 2 blk)))
      (wipeone bname)
    )
  );if
  (while(/= (setq blk(tblnext "BLOCK")) nil)
    (if(and
(not(assoc 1 blk))
(not(vl-string-position (ascii "|") (cdr(assoc 2 blk))))
       )
      (progn
        (setq bname(cdr(assoc 2 blk)))
        (wipeone bname)
      )
    );if
  );while
  (princ)
);defun bwipe
(princ "BWIPE")

cadmoogle

  • Guest
Re: Remove or modify all block descriptions
« Reply #7 on: January 06, 2009, 10:59:55 AM »
Here is the version 1.2

I changed the name and added some lines of text. Thank you for your help.

Code: [Select]
;;Block description wipe v1.2
;;Resets all block descriptions to blank
;;Thanks to dustinthiesse from TheSwamp
(defun c:bdwipe()
  (defun wipeone (bname)
    (setq a (entget (tblobjname "block" bname)))
    (setq a (append a (list (cons 4 " ")))); Modify quotes if needed
    (entmake a)
    (setq b (cdr (assoc -1 a)))
    (while (setq b (entnext b))
    (entmake (entget b))
    )
    (setq e (entmake (list (cons 0 "endblk"))))
  );defun wipeone

  (setq blk(tblnext "BLOCK" 1))
  (if(and
       (not(assoc 1 blk));not xref
       (not(vl-string-position (ascii "|") (cdr(assoc 2 blk))));not part of xref
     )
    (progn
      (setq bname(cdr(assoc 2 blk)))
      (wipeone bname)
    )
  );if
  (while(/= (setq blk(tblnext "BLOCK")) nil)
    (if(and
(not(assoc 1 blk))
(not(vl-string-position (ascii "|") (cdr(assoc 2 blk))))
       )
      (progn
        (setq bname(cdr(assoc 2 blk)))
        (wipeone bname)
      )
    );if
  );while
  (princ)
);defun bwipe
(princ "Type BDWIPE to run command")
(princ)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Remove or modify all block descriptions
« Reply #8 on: January 06, 2009, 11:19:29 AM »
You also might want to localize your variables:

(defun c:bdwipe (/ blk bname e wipeone)
  (defun wipeone (bname / a b e)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #9 on: January 06, 2009, 11:38:48 AM »
You also might want to localize your variables:

(defun c:bdwipe (/ blk bname e wipeone)
  (defun wipeone (bname / a b e)

True.
Question for ya ronjon.  If you localize the function "wipeone" can it still be called external to the program or would it then be limited to only being called within C:BDWIPE?

I ask because a lot of the times I will set up functions like I did here where the main function will run with some default values (for use mainly by general users who don't care how the program actually works), but I like to have the ability to still be able to call the sub-functions independently by other programs and provide parameters other than the defaults in that manner.  Maybe I'm making my setup more complex than it needs to be, but I think it gives me more flexibility.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Remove or modify all block descriptions
« Reply #10 on: January 06, 2009, 12:23:38 PM »
You also might want to localize your variables:

(defun c:bdwipe (/ blk bname e wipeone)
  (defun wipeone (bname / a b e)

True.
Question for ya ronjon.  If you localize the function "wipeone" can it still be called external to the program or would it then be limited to only being called within C:BDWIPE?
.....

It will only be available for C:BDWIPE. I would think a better plan of action would be to load all your functions with startup. It kinda defeats the purpose of reusing the code if it is located in program "A" and needed in program "B" but program "A" has not run yet? Or am I missing something?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #11 on: January 06, 2009, 12:46:37 PM »
You also might want to localize your variables:

(defun c:bdwipe (/ blk bname e wipeone)
  (defun wipeone (bname / a b e)

True.
Question for ya ronjon.  If you localize the function "wipeone" can it still be called external to the program or would it then be limited to only being called within C:BDWIPE?
.....

It will only be available for C:BDWIPE. I would think a better plan of action would be to load all your functions with startup. It kinda defeats the purpose of reusing the code if it is located in program "A" and needed in program "B" but program "A" has not run yet? Or am I missing something?

Actually, I just realized I'm talking about a different scenario.  I've got lisp files that contain multiple functions but they are not nested within each other.   :doa:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Remove or modify all block descriptions
« Reply #12 on: January 06, 2009, 01:20:24 PM »
Another routine to consider.
Code: [Select]
;;  CAB 01.06.09
(defun RemoveBlockDescription (/ data)
  (vl-load-com)
  (while (setq data (tblnext "block" (null data)))
    (if (and (zerop (logand 21 (cdr (assoc 70 data)))) ; ignore xref, xref dependent, anonymous
             (not (equal '(4 . "") (assoc 4 data)))
        )
      (vl-catch-all-apply
        '(lambda (/ elst ent)
           (setq elst (entget (tblobjname "block" (cdr (assoc 2 data)))))
           (entmake (subst '(4 . " ") (assoc 4 elst) elst))
           (setq ent (cdr (assoc -1 elst)))
           (while (setq ent (entnext ent))
             (entmake (entget ent))
           )
           (entmake (list (cons 0 "endblk")))
         )
      )
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dustinthiesse

  • Guest
Re: Remove or modify all block descriptions
« Reply #13 on: January 06, 2009, 01:53:12 PM »
Nice tricks CAB.  I always enjoy learning from your code.  I'll have to remember the (setq data(tblnext "block" (null data))) and logand tricks for sure!

I've got a question.  If I select an XREF entity by using (setq data(entget(car(entsel)))), the DXF code 70 is 0; but if I cycle through the block table using (setq data(tblnext "block" (null data))), the DXF code 70 for that same XREF is 44.  What gives?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Remove or modify all block descriptions
« Reply #14 on: January 06, 2009, 02:23:41 PM »
(setq data(entget(car(entsel))))
This will get the dxf code for the insert, not the block definition, where as
Quote
(setq data(tblnext "block" (null data)))
gets the dxf code for the block definition.

With the first code, data equals
Quote
(-1 . <Entity name: 75b0ae00>)
(0 . "INSERT")
(330 . <Entity name: 7becac10>)
(5 . "4F50")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "XREF")
(100 . "AcDbBlockReference")
(2 . "NORT-009-A-1FL")
(10 0.0 0.0 0.0)
(41 . 1.0)
(42 . 1.0)
(43 . 1.0)
(50 . 0.0)
(70 . 0)
(71 . 0)
(44 . 0.0)
(45 . 0.0)
(210 0.0 0.0 1.0)
Notice the dxf code 0.  Now to get the block definition of selected blocks just use
Code: [Select]
(setq data (entget (tblobjname "block" (cdr (assoc 2 data)))))
Which will return
Quote
(-1 . <Entity name: 75b0ac30>)
(0 . "BLOCK")
(330 . <Entity name: 75b0ac28>)
(5 . "4F16")
(100 . "AcDbEntity")
(67 . 0)
(8 . "0")
(100 . "AcDbBlockBegin")
(70 . 44)
(10 0.0 0.0 0.0)
(-2 . <Entity name: 740dddf8>)
(2 . "NORT-009-A-1FL")
(1 . "NORT-009-A-1FL.DWG")
Now notice the dxf code 0, and the correct way to test dxf code 70 for xref'ness.

Hope that clears some things up.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.