dieblockdie by Robert Bell

Ursus Uziemblo

Usenet Archive
Joined
Jul 7, 2003
Messages
27
Reaction score
0
Robert,
it is very nice code, but please explain why it works :) in my logic (wrong) it kills only INSERT part of other block definition (vla-delete object) is inside (vlax-for object block..). How Your code find insert with given name? What I missed?
Ursus Uziemblo
 
Could that file be used for AutoCAD 2000??
 
I believe that was in response to a poster who thought he had already deleted all direct insertions of the block but still could not purge, thus roberts solution would get the remaining embedded occurances.
 
Yes.

--
R. Robert Bell, MCSE
www.AcadX.com

| Could that file be used for AutoCAD 2000??
|
|
| | > Robert,
| > it is very nice code, but please explain why it works :) | > in my logic (wrong) it kills only INSERT part of other block definition | > (vla-delete object) is inside (vlax-for object block..). | > How Your code find insert with given name? | > What I missed? | > Ursus Uziemblo | > | > | |
 
In the object model, even the layouts are simply blocks. So even a "normal" insertion in Model Space is a nested block, by definition.

I loop thru all the Blocks in the Blocks collection, looping thru each Object in the Block itself, looking for BlockReferences (which are inserts). If I find a BlockReference, I check its Name, and if there is a match, I delete it.

A Regen updates the drawing visibly.

Here is the code for others that might have missed the post Ursus was referring to.

;;; Written by: R. Robert Bell
(defun rrbI:DieBlockDie (BlkN / Doc)
(vl-Load-Com)
(setq BlkN (strcase BlkN)
Doc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
(vlax-For Block (vla-Get-Blocks Doc)
(vlax-For Object Block
(if (and
(= (vla-Get-ObjectName Object) "AcDbBlockReference")
(= (strcase (vla-Get-Name Object)) BlkN))
(vla-Delete Object))))
(vla-Regen Doc acAllViewports)
(princ))

Usage: (rrbI:DieBlockDie "StupidBlock")
 
Thanks Robert for explanation - I did not thing of modelSpace like a block - learn something new - thanks again Ursus
 
so a user could do the same thing with a layer, correct?
 
You could use a similar approach to find what is *on* a layer (and optionally delete it if that is what you wish). However, layers can still be referenced by other conditions, such as a PViewport freezing that layer.

--
R. Robert Bell, MCSE
www.AcadX.com

| so a user could do the same thing with a layer, correct? | | | | > In the object model, even the layouts are simply blocks. So even a | "normal" | > insertion in Model Space is a nested block, by definition. | > | > I loop thru all the Blocks in the Blocks collection, looping thru each | > Object in the Block itself, looking for BlockReferences (which are | inserts). | > If I find a BlockReference, I check its Name, and if there is a match, I | > delete it. | > | > A Regen updates the drawing visibly. | > | > Here is the code for others that might have missed the post Ursus was | > referring to. | > | > ;;; Written by: R. Robert Bell | > (defun rrbI:DieBlockDie (BlkN / Doc) | > (vl-Load-Com) | > (setq BlkN (strcase BlkN) | > Doc (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) | > (vlax-For Block (vla-Get-Blocks Doc) | > (vlax-For Object Block | > (if (and | > (= (vla-Get-ObjectName Object) | "AcDbBlockReference") | > (= (strcase (vla-Get-Name Object)) BlkN)) | > (vla-Delete Object)))) | > (vla-Regen Doc acAllViewports) | > (princ)) | > | > Usage: (rrbI:DieBlockDie "StupidBlock") | > | > | > -- | > R. Robert Bell, MCSE | > www.AcadX.com | > | > | > | > | Robert, | > | it is very nice code, but please explain why it works :) | > | in my logic (wrong) it kills only INSERT part of other block definition | > | (vla-delete object) is inside (vlax-for object block..). | > | How Your code find insert with given name? | > | What I missed? | > | Ursus Uziemblo | > | | > | | > | > | |
 

Latest threads

Back
Top