Jump to content

Forced delete (embedded) blocks


Recommended Posts

Posted

My contribution (will also deal with locked layers).

 

(defun c:DBD (/ *error* _name obj name def ss locklist blocks)
 ;; Delete all instances of selected block (nested blocks and definition also removed)
 ;; Alan J. Thompson, 02.17.11

 (vl-load-com)

 (defun *error* (msg)
   (foreach x locklist (vla-put-lock x :vlax-true))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (defun _name (obj)
   (vlax-get-property
     obj
     (if (vlax-property-available-p obj 'EffectiveName)
       'EffectiveName
       'Name
     )
   )
 )

 (if (setq obj (car (entsel "\nSelect block definition to remove: ")))
   (cond
     ((not (eq "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj)))))
      (princ "\nInvalid object!")
     )
     ((eq 1
          (vlax-get (setq def (vla-item (setq blocks (vla-get-blocks
                                                       (cond (*AcadDoc*)
                                                             ((setq *AcadDoc* (vla-get-activedocument
                                                                                (vlax-get-acad-object)
                                                                              )
                                                              )
                                                             )
                                                       )
                                                     )
                                        )
                                        (setq name (_name obj))
                              )
                    )
                    'isXRef
          )
      )
      (princ "\nBlock definition must not be an XRef!")
     )
     ((progn (initget 0 "Yes No")
             (vl-position
               (getkword (strcat "\nDelete all instance of \"" name "\" block? [Yes/No] <Yes>: "))
               '("Yes" nil)
             )
      )
      (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," name)))))
        (progn
          (vlax-for x (vla-get-layers *AcadDoc*)
            (if (eq (vla-get-lock x) :vlax-true)
              (progn (setq locklist (cons x locklist))
                     (vla-put-lock x :vlax-false)
              )
            )
          )
          (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
            (if (eq (_name x) name)
              (vla-delete x)
            )
          )
          (vla-delete ss)
          (vlax-for block blocks
            (vlax-for x block
              (if
                (and (eq (vla-get-objectname x) "AcDbBlockReference") (eq (vla-get-name x) name))
                 (vla-delete x)
              )
            )
          )
          (vla-delete def)
          (vla-regen *AcadDoc* acAllViewports)
          (alert (strcat "Block \"" name "\" has been removed."))
        )
      )
     )
   )
 )
 (*error* nil)
 (princ)
)

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    10

  • Tharwat

    10

  • BlackBox

    10

  • Jaap Marchal

    4

Top Posters In This Topic

Posted
My contribution ...

 

Contribution... you saved the OP's world, Superhero. 8)

 

 

 

superhero.jpgThere's a lot to digest in there, too.

 

Cheers, bud! :beer:

Posted

Oh yeah, I forgot to mention, it will also ignore selected XRefs.

Posted
Oh yeah, I forgot to mention, it will also ignore selected XRefs.

 

I was going to ask about that... if XRef is selected, why not vla-detach? :unsure:

Posted
I was going to ask about that... if XRef is selected, why not vla-detach? :unsure:

One could if that was necessary. Seemed to me that I wouldn't want to be touching XRefs at all - why I added the check. Am I wrong in this assumption? I've only use XRefs for bringing in entire plans.

Posted
One could if that was necessary. Seemed to me that I wouldn't want to be touching XRefs at all - why I added the check. Am I wrong in this assumption? I've only use XRefs for bringing in entire plans.

 

I am not suggesting that your offering is wrong at all - perhaps it's the way I work.

 

As a result of lock and fade, it is very easy to identify XRefs in my drawings; my thinking assumed that the user intentionally selected an XRef.

 

*IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user.

Posted
I am not suggesting that your offering is wrong at all - perhaps it's the way I work.

 

As a result of lock and fade, it is very easy to identify XRefs in my drawings; my thinking assumed that the user intentionally selected an XRef.

 

*IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user.

I know.

If it were an XRef, I would definitely prompt user before actually detaching.

Posted
*IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user.

Another reason why I prompt the use to verify that the selected block *name* is the one they want removed.

Posted
I know.

If it were an XRef, I would definitely prompt user before actually detaching.

 

Another reason why I prompt the use to verify that the selected block *name* is the one they want removed.

 

Like I said, there's a lot to digest in there.

 

Thanks for entertaining my question(s). :)

Posted
Like I said, there's a lot to digest in there.

 

Thanks for entertaining my question(s). :)

Anytime. :) I'm always happy to answer - when I can.
Posted
Like I said, there's a lot to digest in there.

I should have denoted my work, but I wrote it real quick.

Posted

Wel wel wel, keeps you folks from the street. But it isnt wat i ment. Iàm looking for a lisp that askes for a blockname (embedded) and delete it from the drawing. The embedded block is not always visable (visability -dynamic block). The name from the embedded block is BIS.

The couse of using caps in previous threats is, i did this from work en i always uses caps in drawings..........sorry :oops:

 

Jaap

Posted
Wel wel wel, keeps you folks from the street.

 

What do you mean by that ? :?

Posted

That you are so busy with this threat............meaning nothing special with this (Wel wel wel, keeps you folks from the street) . I like to see this, from people who are so into lisp and iàm not. Not smart enough i guess

 

Jaap

Posted

Well, good thing I was writing it more for RenderMan and Tharwat. I'm done.

Posted
Well, good thing I was writing it more for RenderMan and Tharwat. I'm done.

 

Highly appreciated Alanjt.

 

And their way of replies from the first time kept me out of writing or extending my codes to include the nested blocks in blocks definitions .

 

Best regards.

 

Tharwat

Posted
Well, good thing I was writing it more for RenderMan and Tharwat. I'm done.

 

Know how you feel mate - it was poor wording using 'embedded' as opposed to 'nested'.

 

For completeness:

 

(defun c:DeleteNestedBlocks nil (vl-load-com)
 (vlax-for block
   (vla-get-blocks
     (vla-get-activedocument (vlax-get-acad-object))
   )
   (if
     (and
       (eq :vlax-false (vla-get-isXref block))
       (eq :vlax-false (vla-get-isLayout block))
     )
     (vlax-for obj block
       (if
         (and
           (eq "AcDbBlockReference" (vla-get-Objectname obj))
           (eq "BIS" (vla-get-name obj))
         )
         (vl-catch-all-apply 'vla-delete (list obj))
       )
     )
   )
 )
 (princ)
)

You will need to Regen the Inserts to see the results, and also Purge the excess nested blocks from the block table.

Posted
I like to see this, from people who are so into lisp and iàm not.

 

Perhaps you should be - you have enough need for it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...