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

0 Members and 1 Guest are viewing this topic.

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.comhttp://cadanalyst.slack.comhttp://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.comhttp://cadanalyst.slack.comhttp://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.comhttp://cadanalyst.slack.comhttp://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.