Author Topic: vla-Delete on Block collection (error)  (Read 11971 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.com • http://cadanalyst.slack.com • http://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.com • http://cadanalyst.slack.com • http://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)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #15 on: November 07, 2005, 05:37:54 PM »
Some more testing.......
This problem also occurs when using similar code in VBA
Even in ODBX documents the block defs will not delete

Luis's routine is VERY thorough! It deletes the Layout blocks as well as any standard blocks! Yet, unlike the ActiveX delete method, deleting the Layout's block does NOT remove the layout.....

Superpurge by Manusoft properly removes all the blocks that should be removed.


T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #16 on: November 07, 2005, 06:30:22 PM »
Here is the updated version, I think is working now....


Seems to have worked here on my simple little test drawing.  I will test more when I get a chance to, and let you know the results.
Thanks Luis.  Is there anyway to translate the arx code to vlisp? activex? lisp?  :roll:  Just asking.

Tim
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #17 on: November 07, 2005, 06:44:44 PM »
I might been able to translate it into C# but do not want to get in trouble with the dark side people...
Have fun.
Luis.

Not really :angel:.  It was a wish.  :wink:
Thanks Luis.
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 #18 on: November 07, 2005, 06:47:43 PM »
Here is the updated version, I think is working now....
Yep, works here as well, although I had to run it twice to remove 2 of the blocks.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #19 on: November 07, 2005, 07:11:40 PM »
Tim,
Can you tell me what you believe the code you posted is trying to do. ?

Regards,
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 #20 on: November 07, 2005, 07:21:52 PM »
Luis,
I think that leaving it up to the user to run as many times as needed is better. HERE is my test drawing. It has 2 drawings inserted as blocks that need to be erased. Once erased, the nested blocks "8-X-11" & "point" are the 2 that a.) Tim's code leaves behind & b.) your code needs to run twice to remove (but I'm sure that it's due to the main blocks need to be removed first)

Kerry,
Tim's code removes unused items from the specified collections.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #21 on: November 07, 2005, 07:22:23 PM »
Tim,
Can you tell me what you believe the code you posted is trying to do. ?

Someone on the AUGI forums was complaining about seeing the purge command echo, so I was just trying to see if I could come up with a routine that would do the same thing as the purge command.  It is supposed to delete all objects that it can, for the collections provided within the code.  I think it is the layer, block, text styles and line type.

Did I miss something?

Tim
Tim

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

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #22 on: November 07, 2005, 08:28:40 PM »
Did I miss something?

Tim
Min. dimstyles

named layer filters would also be nifty.  Other than those, you seem to have the biggies covered.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #23 on: November 07, 2005, 08:34:54 PM »
Tim

Something like this may be more efficient, and a little easier to read ..

.. but doesn't solve your/the referencing issue.
Code: [Select]
...
...
(repeat 2
  (foreach i '("Blocks" "Blocks" "DimStyles" "Linetypes" "Layers" "TextStyles")
    (vlax-for Obj (vlax-get Doc i)
      (if (not (vlax-property-available-p Obj 'IsLayout))
        (vl-catch-all-apply 'vla-delete (list Obj))
      )
    )
  )
)
...
...
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 #24 on: November 07, 2005, 08:39:25 PM »
I seem to recall that Tont T. had a reference counter similar to the code Michael posted, but my brain is full of other things at the moment and I can't recall if it was used to solve this issue.
 
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 #25 on: November 07, 2005, 11:56:50 PM »
Something like this may be more efficient, and a little easier to read ..
Dog gone it.....that's what I was trying to do and I just failed to wrap my mind around it, so I suggested the code that Tim used. I knew it was simple, but I was helping Tim while I was also in the midst of my own fires......

Sorry for making your code pukey, Tim. Kerry is absolutely right.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #26 on: November 08, 2005, 12:05:35 AM »
The fact that you had the logic, and it worked, made it easy for a new set of eyes Jeff.
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-Delete on Block collection (error)
« Reply #27 on: November 08, 2005, 07:44:55 AM »
Back to the incorrect referencing business, <guessing> it may be because when entities are deleted they aren't truly deleted per se, that is, they are flagged for deletion but still reside in the drawing database. When the drawing is saved entities flagged for deletion don't get to go along for the ride, thus are deleted. The fact that they still reside in the database seems to trip up the ability to tell whether there are fully disassociated from other entities.

Regarding the authorship of my initial code snip I based it on about a minute of observation in my hotlinked props utility - I can dynamically hop from entity to entity, object to object, as long as the target object / entity name is valid (not deleted) by merely double clicking the object / ename. Observe --



While I've little doubt Tony probably penned something similar years ago (generally speaking he's light years ahead of the great unwashed) he was not the source of what I had posted.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-Delete on Block collection (error)
« Reply #28 on: November 08, 2005, 08:19:22 AM »
Hi Michael,

Flagged for deletion seems to ring a bell. I recall a similar issue with layers that had been deleted but subsequent calls thought they still existed. ... I really have to get a good reference system organised to find this stuff again .. I think Glenn R. did some research on the issue.

Re the origin of your post code , I hadn't thought for a second that anyone other than you was the source.

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

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: vla-Delete on Block collection (error)
« Reply #29 on: November 08, 2005, 08:43:15 AM »
Minor tangent ...

Michael what did you use to create that gif? ( blockcounts.gif )
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-Delete on Block collection (error)
« Reply #30 on: November 08, 2005, 09:22:07 AM »
It was made by Camtasia Studio Mark, ~ $300.

However, if you sniff around the forum Keith posted info about a free proggy.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #31 on: November 08, 2005, 01:42:29 PM »
I believe the "Flagged" for deletion method is for "Undo" purposes, retaining the entities basic geometry so the program knows what it was.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #32 on: November 08, 2005, 02:38:10 PM »
Something like this may be more efficient, and a little easier to read ..
Code: [Select]
(foreach i '("Blocks" "Blocks" "DimStyles" "Linetypes" "Layers" "TextStyles")
 (vlax-for Obj (vlax-get Doc i)
 (if (not (vlax-property-available-p Obj 'IsLayout))
 (vl-catch-all-apply 'vla-delete (list Obj))
 )
 )
 )

Kerry, after looking at this closer this will NOT work. It skips ALL blocks, since each block has that property.......
This does work and still uses the logic you show:
Code: [Select]
(foreach i '("Blocks" "DimStyles" "Linetypes" "Layers" "TextStyles")
  (vlax-for Obj (vlax-get Doc i)
   (if (or (not (vlax-property-available-p Obj 'IsLayout))
   (= (vla-get-IsLayout Obj) :vlax-false)
   )
      (vl-catch-all-apply 'vla-Delete (list Obj))
     )
  )
)

deegeecees, that was a great thought, however I tried setting Undo/Control/None which should remove any references there ans still get the same results.

deegeecees

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #33 on: November 08, 2005, 02:52:53 PM »
Quote
deegeecees, that was a great thought, however I tried setting Undo/Control/None which should remove any references there ans still get the same results.

I don't think AutoCAD takes that placeholder out of the drawing database with or without Undo settings until the session is closed, could be some other reason for it. I'm guessing at the moment. Thanks for the compliment though.  :-)

Serge J. Gianolla

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #34 on: November 08, 2005, 03:55:53 PM »
Could it be flagged only, instead of deleted because at some stage in same dwg session one may want to use UNDO? Just thunkin' loud!

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vla-Delete on Block collection (error)
« Reply #35 on: November 08, 2005, 04:00:11 PM »
Well, not an answer to the original question in this forum, but a solution to the original question that started this thread......a Purge that purges everyting without echoing to the command line....
Code: [Select]
(defun c:SilentPurge ( / doc)
  (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (repeat 5
    (vla-purgeall doc)
    )
  (princ)
  )
It cannot be used on ObjectDBX documents, but that was not a part of the original inquiry anyway.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #36 on: November 09, 2005, 11:07:05 AM »
Thanks for all the information contained here.  I was out of the office yesterday.
Kerry,
 Thanks for the code.  I was trying something along the same lines, but didn't word my if statement correctly like you did.

Jeff,
 You are correct about using (vla-PurgeAll wish I would have tried that one first.  I guess I try to do to many things with ObjectDBX in mind.

Thanks all.
Tim

ps. I'm in the middle of coding something that checks to make sure all blocks are referenced, and if not delete them.  It seems to work, I just need to fine tune it.
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 #37 on: November 09, 2005, 11:08:55 AM »
Well, not an answer to the original question in this forum, but a solution to the original question that started this thread......a Purge that purges everyting without echoing to the command line....
Code: [Select]
(defun c:SilentPurge ( / doc)
 (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (repeat 5
 (vla-purgeall doc)
 )
 (princ)
 )
It cannot be used on ObjectDBX documents, but that was not a part of the original inquiry anyway.

I have a nearly identical one called c:SBD.

:-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

whdjr

  • Guest
Re: vla-Delete on Block collection (error)
« Reply #38 on: November 09, 2005, 11:12:31 AM »
Silent But Deadly ??

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vla-Delete on Block collection (error)
« Reply #39 on: November 09, 2005, 11:24:03 AM »
<ding><ding><ding>

 :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vla-Delete on Block collection (error)
« Reply #40 on: November 09, 2005, 12:11:10 PM »
Here is the code that I was working on.  It seems to work on my test drawing.  It's not pretty, but it works.  All comments welcomed.
Code: [Select]
(defun PurgeBlocks (Doc / LayoutsList tmpList flag)
; Purge blocks from document supplied, that are not inserted into a layout.

(vlax-for i (vla-get-Layouts Doc)
 (setq LayoutsList (cons (vla-get-Name (vla-get-Block i)) LayoutsList))
)
(vlax-for Blk (vla-get-Blocks Doc)
 (if
  (and
   (= (vla-get-IsLayout Blk) :vlax-false)
   (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-Delete (list Blk))
   )
  )
  (foreach x (entget (vlax-vla-object->ename Blk))
   (if (equal (car x) 331)
    (progn
     (while
      (and
       (or (equal 331 (car x)) (equal 330 (car x)))
       (entget (cdr x))
       (not flag)
      )
      (if (member (cdr (assoc 2 (entget (cdr x)))) LayoutsList)
       (setq flag T)
       (progn
        (setq tmpList (cons (vlax-ename->vla-object (cdr x)) tmpList))
        (setq x
         (if (setq tmp (assoc 331 (entget (cdr x))))
          tmp
          (assoc 330 (entget (cdr x)))
         )
        )
       )
      )
     )
     (if flag
      (setq flag nil)
      (mapcar '(lambda (x) (vl-catch-all-apply 'vla-Delete (list x))) tmpList)
     )
     (setq tmpList nil)
    )
   )
  )
 )
)
)
Guess it doesn't like spaces before lines, after lines that start with (vlax-for.

Tim
Tim

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

Please think about donating if this post helped you.