Jump to content

Recommended Posts

Posted

What command can I use to find a block by its name in my drawing and then delete it?

Posted
On 8/24/2021 at 12:01 PM, yxl030 said:

To See if this is what you want
http://www.lee-mac.com/deleteblocks.html

 

I'm looking for something like that. But I can't get it work right now. In some drawings I have a block that I want to delete if it is there (via lisp).

 

;;; Purge named block
;;; Example: (ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "testblock")
;;; Argument: doc {document}
;;;           name {a block name}
;;; Return values: T if successful, nil if not successful

(defun c:deletetestblock ()

    (defun ax:purge-block (doc name)
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              'vla-delete
              (list (vl-catch-all-apply
                      'vla-item
                      (list (vla-get-blocks doc) name)
                    )
              )
            )
          )
        nil ; name cannot be purged or doesn't exist
        T ; name purged
      )
    )
  
  (ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "testblock")
  
)

 

Posted
8 minutes ago, Manuel_Kunde said:

 

I'm looking for something like that. But I can't get it work right now.

 

Load the lisp. type delblocks it will allow you to pick a block. if you choose the name option it will open a menu to pick the names out of a list. if your drawing has alot of blocks use the filter at the bottom to narrow the list of blocks that contain whats in the filter.

 

in your lisp im guessing you just want to automatically purge it when you open a drawing?

add a vl-load-com to that bad boy and you should be good.

 

(ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "BLOCKNAME")

 

  • Like 1
Posted
31 minutes ago, mhupp said:

 

Load the lisp. type delblocks it will allow you to pick a block. if you choose the name option it will open a menu to pick the names out of a list. if your drawing has alot of blocks use the filter at the bottom to narrow the list of blocks that contain whats in the filter.

 

in your lisp im guessing you just want to automatically purge it when you open a drawing?

add a vl-load-com to that bad boy and you should be good.

 

(ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "BLOCKNAME")

 

 

Thanks for your quick reply, but I don't get it.

I want to delete the block without user input, so when I write the command "deletetestblock", the "testblock" should be deleted.

 

(defun ax:purge-block (doc name)
  (if (vl-catch-all-error-p
        (vl-catch-all-apply
          'vla-delete
          (list (vl-catch-all-apply
                  'vla-item
                  (list (vla-get-blocks doc) name)
                )
          )
        )
      )
    nil ; name cannot be purged or doesn't exist
    T ; name purged
  )
)

(defun c:deletetestblock ()
  
  (vl-load-com)
  (ax:purge-block (vla-get-activedocument (vlax-get-acad-object)) "testblock")
  
)

 

Posted (edited)

Load lee's and use the following

 

(defun C:deletetestblock ()
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (LM:deleteblocks doc '("testblock"))
)

 

Edited by mhupp
  • Like 1
Posted
5 minutes ago, mhupp said:

just load lee's and use the following

 

Thank's, this works for me.

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...