Author Topic: odbx delete entities in a layer  (Read 508 times)

0 Members and 1 Guest are viewing this topic.

dgpuertas

  • Newt
  • Posts: 80
odbx delete entities in a layer
« on: February 01, 2023, 04:53:39 AM »

I want to use odbx (thanks a lot, lee for this amazing code http://www.lee-mac.com/odbxbase.html)

To delete all entities in a specific layer.

I can't use ssget
How can I do?

Thanks a lot.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: odbx delete entities in a layer
« Reply #1 on: February 01, 2023, 08:26:31 AM »
Iterate over the blocks collection (which includes layouts), and then over the objects within each block (i.e. the objects in every block definition and layout), and use a conditional expression to test whether the object resides on the target layer, deleting if so.

Something like:
Code - Auto/Visual Lisp: [Select]
  1. (defun doit ( doc lyr )
  2.     (vlax-for blk (vla-get-blocks doc)
  3.         (if (= :vlax-false (vla-get-isxref blk))
  4.             (vlax-for obj blk
  5.                 (if (and (= (strcase lyr) (vla-get-layer obj)) (vlax-write-enabled-p obj))
  6.                     (vla-delete obj)
  7.                 )
  8.             )
  9.         )
  10.     )
  11. )
  12.  
  13. (LM:odbx '(lambda ( doc ) (doit doc "YourLayer")) nil t)