Author Topic: vla-Delete on Block collection (error)  (Read 11965 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
vla-Delete on Block collection (error)
« on: November 07, 2005, 12:41:49 PM »
Quote
Quote
Originally Posted by CiphDRMRS
On a side note. Does anyone know why this won't delete the blocks within my test drawing? I started with a blank drawing, and inserted other drawings into it. I then ran the routine, and it seems to work fine on all the other collections except the block collection. I tried code to just delete objects from the block collection, but that didn't delete any either. I'm lost as to why.

Thanks for any insight.
Tim

Hi, Tim.
I just tested this and can duplicate your results Strangely, the 2 blocks that will not delete CAN be purged via the normal purge command. Checking the error that is raised when the deletion should occur, I get this:
(vl-catch-all-error-message msg)
"Automation Error. Object is referenced"

However a Save, Exit, Open of the same file allows those blocks to be removed with your code.

So now to find out HOW/WHERE they are being referenced so they can be addressed.....

Jeff
Referring to code below.
Code: [Select]
(defun MyPurge (Doc / )
; If used in the current drawing, then use like (MyPurge nil), else supply a valid
;  document object.
; Know problem: Won't delete all blocks not being used.  Lost as to why.

(if (not Doc)
 (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
)
(repeat 2
 (foreach i '("Blocks" "DimStyles" "Linetypes" "Layers" "TextStyles")
  (vlax-for Obj (vlax-get Doc i)
   (cond
    ((vlax-property-available-p Obj 'IsLayout)
     (if (= (vla-get-IsLayout Obj) :vlax-false)
      (vl-catch-all-apply 'vla-Delete (list Obj))
     )
    )
    (t (vl-catch-all-apply 'vla-Delete (list Obj)))
   )
  )
 )
)
(princ)
)

Can anyone here sheld some light on this problem?  Code was written by me, for someone on the AUGI forum that didn't want to see the return value of the purge command on screen.

Thanks.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: vla-Delete on Block collection (error)
« Reply #1 on: November 07, 2005, 01:44:15 PM »
Are you trying to sole the block problem or the echo problem?

Reading material:
http://www.theswamp.org/forum/index.php?topic=5630.msg68503#msg68503

http://tinyurl.com/9gre7

Looks like there is no echo when I run your routine so must be the block.
Would you post a sample DWG that leaves the blocks?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #2 on: November 07, 2005, 01:53:17 PM »
Would you post a sample DWG that leaves the blocks?
I would, but Jeff already proved that a save and then open would allow the blocks to be deleted out of the collection.
Quote
However a Save, Exit, Open of the same file allows those blocks to be removed with your code.

I think the only want to test it is the way I mentioned in the quote back.  Open a blank drawing, and start inserting blocks, and then run my routine.  In my drawing none would purge out with my routine.
I will read what you have provided.

Thanks.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-Delete on Block collection (error)
« Reply #3 on: November 07, 2005, 02:23:52 PM »
I may be wrong but it seems to me the subtitle to this is "What is a block's reference count?"

If so then perhaps this (without error handling) may offer food for thought --

Code: [Select]
(defun ReferenceCount ( block )
    (length
        (vl-remove-if-not
           '(lambda (pair)
                (and
                    (eq 331 (car pair))
                    (entget (cdr pair))
                )   
            )
            (entget (vlax-vla-object->ename block))
        )
    )
)

For example --

Code: [Select]
(   
    (lambda ( blocksCollection )
   
        (vlax-for block blocksCollection
            (princ
                (strcat
                    (vla-get-name block)
                    ".ReferenceCount = "
                    (itoa (ReferenceCount block))
                    "\n"
                )
            )
        )
   
        (princ)
       
    )

    (vla-get-blocks
        (vla-get-ActiveDocument
            (vlax-get-acad-object)
        )
    )

)

If not please ignore and my apologies for thread hijacking, a talent of late.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #4 on: November 07, 2005, 02:54:40 PM »
I may be wrong but it seems to me the subtitle to this is "What is a block's reference count?"

If so then perhaps this (without error handling) may offer food for thought --

Nice peace of coding.  If I understand it right, you are looking at where the block is being referenced from.  What space right, that is what 331 group code tells you?  If that is correct, how come it gives a number, but I don't see anything on the screen?  After I ran your code, and then mine, I saw that it did delete all the blocks that had a number of 0.

I'm still lost as to how they are referenced like they are inserted into the drawing, but I don't see anything, and I can purge then with the command.

Can anyone give insight into this?  I think I am more lost now than when I started the post.  :cry:

Thanks.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #5 on: November 07, 2005, 03:25:20 PM »
Thanks, Michael, for jogging my memory on the Block_Record table. Of course it still doesn't answer the question why can't these blocks be deleted? It appears to me that when a drawing that contains blocks is inserted to a new drawing, then that block of the drawing is erased, any blocks that were inserted only once become "unreferenced" and can be deleted. BUT, those blocks that had been inserted more than once somehow do not have thier references reset.

Note the following....I started a new drawing; I inserted a drawing that contains 10 blocks, 2 of which have multiple insertions; I erase said block; I run (mypurge nil) and then run MP's code to list the references:
Quote
*Model_Space.ReferenceCount = 0
*Paper_Space.ReferenceCount = 0
*Paper_Space0.ReferenceCount = 0
8-X-11.ReferenceCount = 3
point.ReferenceCount = 10
There is absolutely no ploace that these blocks are inserted, and the drawing they are a part of HAS been removed, yet here the references remain......trying an entget on the owner of each reference returns this:
Code: [Select]
$ (setq blk (vla-item (vla-get-blocks *doc*) "point"))
#<VLA-OBJECT IAcadBlock 02014704>
_$ (setq blk (entget (vlax-vla-object->ename blk)))
((-1 . <Entity name: 400ebad0>) (0 . "BLOCK_RECORD") (330 . <Entity name: 40083c08>) (5 . "1C2") (100 . "AcDbSymbolTableRecord") (100 . "AcDbBlockTableRecord") (2 . "point") (360 . <Entity name: 400ebaf8>) (340 . <Entity name: 0>) (102 . "{BLKREFS") (331 . <Entity name: 400ebba0>) (331 . <Entity name: 400ebc08>) (331 . <Entity name: 400ebc30>) (331 . <Entity name: 400ebc58>) (331 . <Entity name: 400ebc80>) (331 . <Entity name: 400ebca8>) (331 . <Entity name: 400ebcd0>) (331 . <Entity name: 400ebcf8>) (331 . <Entity name: 400ebd20>) (331 . <Entity name: 400ebd48>) (102 . "}"))
_$ (setq blk1 (entget (cdr (assoc 331 blk))))
((-1 . <Entity name: 400ebba0>) (0 . "INSERT") (330 . <Entity name: 400ebb78>) (5 . "1DC") (100 . "AcDbEntity") (67 . 0) (100 . "AcDbBlockReference") (66 . 1) (2 . "point") (10 10.227 5.56124 12.497) (41 . 72.0) (42 . 72.0) (43 . 72.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
_$ (entget (cdr (assoc 330 blk1)))
nil
which says to me that the owner no longer exists, so how can it still be referencing it? Acad knows that there are really no references, as you can purge this block without problem. Is there someway we can force the Block_Record table to update without closing/opening the drawing?

Tim, at least we now know the WHERE......

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #6 on: November 07, 2005, 03:50:37 PM »
Michael, you are missing the fact that Block "B" as been erased, and hase even been "purged" via the vla-delete method. The only place Block "A" was ever referenced was as a part of Block "B", yet it is still being shown as being referenced, even when the block table shows it's owner to not exist.

And again, using the Purge command WILL purge Block "A" but trying to (vla-delete BlockA) results in the "block is referenced" error.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-Delete on Block collection (error)
« Reply #7 on: November 07, 2005, 03:52:40 PM »
You're right Jeff. I'll look at this tonight. I'm doing us all a disservice by such cursory fly bys.

Edit: Jeff had responded to the following post which I had deleted as soon as I had posted it, but apparently not before Jeff had a chance to see it --

Quote from: MP
Maybe I'm missing something, and (forgive the terse involvement here, I'm juggling way too much right now) but it's a simple matter of block instances being in other block definitions no? That is, you cannot see the references, but there are real and would prevent a purging.

i.e.

Block "A" has no model or paperspace instances but is included in block definition "B", which has one instance in modelspace. Thus you cannot purge block "A".

Sorry for making your post look out of place Jeff.
« Last Edit: November 07, 2005, 04:15:06 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #8 on: November 07, 2005, 04:44:25 PM »
DLed it LE, don't have time to try it yet...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #9 on: November 07, 2005, 04:49:32 PM »
I would like the answer in Lisp format better, but I'm willing to try yours, but I don't know how to call it.  Grin.  I down loaded it, unzipped it, and dragged it into my Acad session, but how do I call it.  I tried "purgeblks" "ads_purgeblks", so I am lost.

I guess more than an answer as to how it purge them, is I'm looking for why the lisp routine I tried didn't work.  I think that if I knew why, then maybe I could figure out a why around it.

Thanks for the post Luis.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #10 on: November 07, 2005, 05:01:14 PM »
Tim,
use (PURGEBLKS) at the command line.

Please note Luis's conditions for use .. he wasn't kidding about making sure the blocks are deleted first :)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #11 on: November 07, 2005, 05:01:42 PM »
.... too slow, again  :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #12 on: November 07, 2005, 05:04:13 PM »
Hi Luis,
Yes your function worked on the problem blocks. Is that code convertable to lisp? Or at least a description of what it does? Now to make it only work on only unreferenced blocks....maybe step through each block and see if it has any other blocks in it's definition?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #13 on: November 07, 2005, 05:06:59 PM »
Luis,

  Here it got rid of all blocks but one, and that block could be purged with the command version of purge, but not with my code.  I have the same question as Jeff, about translated to lisp?
I will try and see if I can understand the logic behind your arx code, but I don't think I will be able to, seeing as how I can barely understand Lisp.

Thanks for showing that it is possible.
Tim
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: vla-Delete on Block collection (error)
« Reply #14 on: November 07, 2005, 05:21:57 PM »
If so then perhaps this (without error handling) may offer food for thought --

In a word  :kewl:
TheSwamp.org  (serving the CAD community since 2003)