Jump to content

Forced delete (embedded) blocks


Recommended Posts

Posted

HELLO,

 

i`AM LOOKING FOR A LISP TO FORCE DELETE A (EMBEDDED)BLOCK FROM A DRAWING. SOMETHING LIKE LAYER DELETE.

 

THANKS

 

JAAP

  • 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

Purge command with Block option?

 

Are the blocks named or anonymous?

Posted

Check this out ..... :)

 

(defun c:test (/ ss ss1 e Blks)
 ; Tharwat 17. 02. 2011
 (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
        (setq ss1 (ssname ss 0))
            (setq e (entget ss1))
        )
   (progn
     (setq Blks (ssget "_x" (list '(0 . "INSERT")
                      (cons 2 (cdr (assoc 2 e))))))
          (command "_.Erase" Blks "")
    )
      (princ)
   )
 (princ)
 )

 

Tharwat

Posted

NO, IS NOT WORKING. WHEN I GIVE THE COMMAND "TEST". IT ASKS TO SELECT.-->

NOTHING IS DONE. AUTOCAD COMES BACK WITH: Command: TEST Unknown command "TEST". Press F1 for help.

 

 

 

WORKING WITH AUTOCAD ELECTRICAL 2010

 

JAAP

Posted

On the contrary , It does the job quickly .

 

But with your Electrical version of Cad which is I have no idea if would except Lisp or not though .

Posted (edited)
NO, IS NOT WORKING. WHEN I GIVE THE COMMAND "TEST". IT ASKS TO SELECT.-->

NOTHING IS DONE. AUTOCAD COMES BACK WITH: Command: TEST Unknown command "TEST". Press F1 for help.

 

 

 

WORKING WITH AUTOCAD ELECTRICAL 2010

 

JAAP

 

Sounds like you haven't loaded the lisp correctly, see these instructions.

 

Also, please stop with the caps, being shout at is not fun.

Edited by Tiger
added link
Posted

You may want to reconsider this line:

 

(defun c:test (/ ss ss1 e Blks)
 ; Tharwat 17. 02. 2011
 (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
        (setq ss1 (ssname ss 0))
            (setq e (entget ss1))
        )
   (progn
     (setq Blks (ssget "_x" (list '(0 . "INSERT")
                      [color=red][b]([/b][/color][color=red]cons 2 (cdr[/color] [color=blue][b]([/b]assoc 2 e[b])[/b][/color][color=red])[b])[/b][/color])))
          (command "_.Erase" Blks "")
    )
      (princ)
   )
 (princ)
 )

 

 

For fun, here's another option:

 

(defun c:FOO  (/ *acadDoc* eName ss blockItem)
 (vl-load-com)
 (vla-startundomark
   (setq *acadDoc*
          (vla-get-activedocument (vlax-get-acad-object))))
 (if (and (setq eName (car (entsel "\nSelect the Block You Wish to Delete: ")))
          (setq ss (ssget "_x" (list '(0 . "INSERT") (assoc 2 (entget eName))))))
   (progn
     (vlax-for x  (setq ss (vla-get-activeselectionset *acadDoc*))
       (cond (blockItem)
             ((setq blockItem (vla-item (vla-get-blocks *acadDoc*)
                                        (vla-get-effectivename x)))))
       (vla-delete x))
     (vla-delete blockItem)
     (vla-delete ss)))
 (vla-endundomark *acadDoc*)
 (princ))

 

Option #2 will also remove the block reference from the blocks collection.

Posted
You may want to reconsider this line:

Always cracks me up when I see that.
Posted

Hello Renderman .:)

 

I guess that the following two lines are the same according to the use of them .

 

(cons 2 (cdr (assoc 2 e)))
(assoc 2 e)

 

But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ?

Posted
Always cracks me up when I see that.

 

You'll laugh, I always try to say it nicely... because I know there's one coming around the corner, pointed at me. :oops:

Posted

I guess that the following two lines are the same according to the use of them .

 

(cons 2 (cdr (assoc 2 e)))
(assoc 2 e)

 

 

More specifically, they yield the same result... that is what's important.

 

But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ?

 

I think not... I'm not a fan of doing extra work for the same result. :)

 

Edit:

 

How's the old saying go... "Brevity is the Soul of Wit"

Posted

I think not... I'm not a fan of doing extra work for the same result. :)

 

Edit:

How's the old saying go... "Brevity is the Soul of Wit"

 

 

But I am a fan of learning a lot, and by time knowledge would become easily obtained and given at the right situation.

And would become more genius than Genious :wink:

 

Regards

Posted
Hello Renderman .:)

 

I guess that the following two lines are the same according to the use of them .

 

(cons 2 (cdr (assoc 2 e)))
(assoc 2 e)

 

But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ?

All cons is going is recreating a dotted pair list. Why create extra work for yourself?

Posted
But I am a fan of learning a lot, and by time knowledge would become easily obtained and given at the right situation.

And would become more genius than Genious :wink:

 

Regards

 

That's great, Tharwat... but did you understand the point being made? :unsure:

 

I think that when you (genuinely) compare the amount of code/work in yours:

 

...
 (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT"))))
          (setq ss1 (ssname ss 0))
          (setq e (entget ss1)))
   (progn
     ([color=black]setq Blks (ssget "_x" (list '(0 . "INSERT") (cons 2 (cdr (assoc 2 e))))))[/color][color=black]...[/color]

 

... To that of mine:

 

[color=black]...[/color]
[color=black](if (and [/color][color=black](setq eName (car (entsel "\nSelect the Block You Wish to Delete: ")))[/color]
[color=black]        (setq ss (ssget "_x" (list '(0 . "INSERT") (assoc 2 (entget eName))))))[/color]
...

 

 

... You will see (appreciate?) the inherent advantage to the latter.

 

Cheers! :beer:

Posted

 

I think that when you (genuinely) compare the amount of code/work in yours:

Cheers! :beer:

 

Yes Renderman .

 

That's what I intended to code at the beginning of the first post and I do not know why I changed my mind with it to ssget .

 

 

... You will see (appreciate?) the inherent advantage to the latter.

 

 

Here is the message that I have received while invoking your codes , I do not why .:unsure:

 

Command: foo

 

Select the Block You Wish to Delete: ; error: Automation Error. Object is

referenced

 

 

Many thanks

Posted
All cons is going is recreating a dotted pair list. Why create extra work for yourself?

 

Yeah.... I should have used it with assoc only without the cons function .

 

Appreciated

Posted

Here is the message that I have received while invoking your codes , I do not why .:unsure:

 

Command: foo

 

Select the Block You Wish to Delete: ; error: Automation Error. Object is referenced

 

Interesting... which line breaks in VLIDE? :unsure:

 

First guess would be the line that deletes the block reference... the error suggests that the block exists elsewhere, perhaps nested inside of another block?

 

Admittedly, my code does not handle nested blocks, only primary.

Posted

First guess would be the line that deletes the block reference... the error suggests that the block exists elsewhere, perhaps nested inside of another block?

 

Admittedly, my code does not handle nested blocks, only primary.

 

Great guess .:)

 

The selected Block was nested to another which caused that message to appear .

 

Appreciated.

 

Tharwat

Posted
Great guess .:)

 

The selected Block was nested to another which caused that message to appear .

 

Ohhhh! That's what the OP meant by '(embedded)'. :lol:

 

I'm busy at the moment, but will try to revist the original request, given this late revelation....

Posted
Ohhhh! That's what the OP meant by '(embedded)'. :lol:

 

I'm busy at the moment, but will try to revist the original request, given this late revelation....

 

We have been dancing out of the ring since the first post .:shock:

 

Although my codes would escape slowly. :lol:

 

Thanks

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