• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    *Expert Elite*
    Posts: 2,136
    Registered: ‎11-24-2009

    Re: Lisp routine to delete blocks

    06-21-2012 08:13 AM in reply to: jjorovi

    a quick mod

     

    (defun c:deleteblock  (/ *error* msge effnme ent entl setl e)
          (vl-load-com)
          (alert
                "warning! - this command deletes all occurences of block selected")
          (defun *error*  (msge)
                (princ "error: ")
                (setq msge (princ "\nfunction cancelled"))
                (terpri))
          (setq effnme (lambda (x)
                             (vla-get-effectivename
                                   (if (eq (type x) 'ENAME)
                                         (vlax-ename->vla-object x)
                                         x))))
          (princ "\nselect block to delete: ")
          (if (setq ent (ssget "_:smileyfrustrated:" '((0 . "INSERT"))))
                (progn
                      (setq entl (effnme (ssname ent 0)))
                      (ssget "x" (list (cons 2 (strcat entl ",`*U*"))))
                      (vlax-for
                             itm  (vla-get-ActiveSelectionSet
                                        (vla-get-ActiveDocument
                                              (vlax-get-acad-object)))
                            (if (eq (effnme itm) entl)
                                  (vl-catch-all-apply
                                        'vla-delete
                                        (list itm))))
                      (princ (strcat "\nall blocks named "
                                     entl
                                     " have now been deleted")))
                (princ "\nNo Block Selected:"))

          (princ)
          )

     

    HTH

    Please use plain text.