TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dgpuertas on February 01, 2023, 04:53:39 AM

Title: odbx delete entities in a layer
Post by: dgpuertas 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.
Title: Re: odbx delete entities in a layer
Post by: Lee Mac 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)