Author Topic: delete block in all layout.  (Read 6829 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: delete block in all layout.
« Reply #15 on: February 02, 2007, 05:35:34 PM »
Dan,

You could use this:

Code: [Select]
(defun eblock (bname / ss)
  (if (setq ss (ssget "_X" (list (cons 2 bname))))
    (progn
      (mapcar 'entdel (mapcar 'cadr (ssnamex ss)))
      (vla-purgeall
(vla-get-activedocument (vlax-get-acad-object))
      )
    )
  )
)
(eblock)

To use in your script: (eblock "yourblockname")

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: delete block in all layout.
« Reply #16 on: February 02, 2007, 05:45:47 PM »
If you don't want to purge everything, you can just try and erase the blocks definition from the block collection.

Code: [Select]
(if
 (not
  (vl-catch-all-error-p
   (setq BlkObj
    (vl-catch-all-apply
     'vla-Item
     (list
      (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
      bname
     )
    )
   )
  )
 )
 (vl-catch-all-error-p 'vla-Delete (list BlkObj))
)
Tim

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

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: delete block in all layout.
« Reply #17 on: February 02, 2007, 07:54:38 PM »
Code: [Select]
.
 .....
      (mapcar 'entdel (mapcar 'cadr (ssnamex ss)))
 ....
.
Ron
Ron,
I, too, thought this would work until I was recently advised that (entdel) only works for Modelspace and the most recently active Layout. Changing the code to use ActiveX's Delete method will solve this and work for all Layouts.
Code: [Select]
(mapcar '(lambda (x)
                (vla-delete
                  (vlax-ename->vla-object x)
                 )
                )
   (mapcar 'cadr (ssnamex ss)))

ronjonp

  • Needs a day job
  • Posts: 7531
Re: delete block in all layout.
« Reply #18 on: February 03, 2007, 10:12:25 AM »
Good to know Jeff. Thanks.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: delete block in all layout.
« Reply #19 on: February 03, 2007, 07:59:56 PM »
ditto
Thanks Jeff
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.

Joe Burke

  • Guest
Re: delete block in all layout.
« Reply #20 on: February 04, 2007, 12:24:35 PM »
I wonder if anyone else thinks a program which tries to delete a block from a drawing should offer an option? Either expode all the references, including nested, and then delete the definition. Or simply delete the references and pugre the block definition.

I wrote something recently which deals with that question. I definitely felt a need to offer that option.

ELOQUINTET

  • Guest
Re: delete block in all layout.
« Reply #21 on: February 06, 2007, 09:59:29 AM »
basically i have updated our titleblock and need to go into our library and delete the old one and purge it out because when i insert the new one it is being overriden. ron i tried yours and it works great but i have a few more questions. how can i modify this so it looks for several blocks or should i repeat it in my script looking for a different eblock name? also another thing i didn't think about is that some but not all of our files are read only. i'm wondering how i can find which files are then make my changes then reset them to read only afterwards. anyone know how to do this via script?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: delete block in all layout.
« Reply #22 on: February 06, 2007, 12:39:33 PM »
basically i have updated our titleblock and need to go into our library and delete the old one and purge it out because when i insert the new one it is being overriden. ron i tried yours and it works great but i have a few more questions. how can i modify this so it looks for several blocks or should i repeat it in my script looking for a different eblock name? also another thing i didn't think about is that some but not all of our files are read only. i'm wondering how i can find which files are then make my changes then reset them to read only afterwards. anyone know how to do this via script?

Per Jeff M...you should use this variant:

Code: [Select]
(defun eblock (bname / ss)
  (if (setq ss (ssget "_X" (list (cons 2 bname))))
    (progn
      (mapcar '(lambda (x)
(vla-delete
   (vlax-ename->vla-object x)
)
       )
      (mapcar 'cadr (ssnamex ss))
      )
      (vla-purgeall
(vla-get-activedocument (vlax-get-acad-object))
      )
    )
  )
)
(eblock)

As far as filtering for different block names:

(eblock "blocknm1,blocknm2")

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: delete block in all layout.
« Reply #23 on: February 06, 2007, 03:10:04 PM »
thanks ron and jeff i will give this a try when i have a moment