Author Topic: delete block in all layout.  (Read 6833 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
delete block in all layout.
« on: October 04, 2006, 11:47:53 PM »
Hi all...

I'm trying to find a routine who can delete a specific block name in ALL LAYOUT
without changing layout..

I know it's possible....but to much work here...
so if you can give me a hand...it will be appreciated..

thanks
Keep smile...

kpblc

  • Bull Frog
  • Posts: 396
Re: delete block in all layout.
« Reply #1 on: October 05, 2006, 12:35:40 AM »
Code: [Select]
(defun test (/ block_name)
  (if (and (setq block_name (getstring t "\nBlock Name : "))
   (tblobjname "block" block_name)
   ) ;_ end of and
    (foreach item
  (mapcar
    'vlax-ename->vla-object
    (vl-remove-if
      'listp
      (mapcar
'cadr
(ssnamex
  (ssget "_X"
(list '(0 . "INSERT")
       '(410 . "~model")
       (cons 2 block_name)
       ) ;_ end of list
) ;_ end of ssget
  ) ;_ end of ssnamex
) ;_ end of mapcar
      ) ;_ end of vl-remove-if
    ) ;_ end of mapcar
      (vla-erase item)
      ) ;_ end of foreach
    ) ;_ end of if
  ) ;_ end of defun
Sorry for my English.

CADmium

  • Newt
  • Posts: 33
Re: delete block in all layout.
« Reply #2 on: October 05, 2006, 02:15:54 AM »
a function in ActivX :
Code: [Select]
(defun blockrefdelete(Blockname / Block)
  (vlax-for layout(vla-get-layouts(vla-get-activedocument(vlax-get-acad-object)))
    (vlax-for ITEM (vla-get-block Layout)
      (if(and(member(strcase(vla-get-objectname  ITEM))
                   '("ACDBBLOCKREFERENCE" "ACDBMINSERTBLOCK")
             )
             (=(strcase(vla-get-name ITEM))(strcase BLOCKNAME))
         )
        (vla-delete ITEM)
      ) 
    )
  )
)

or try
Code: [Select]
(defun blockrefdelete(BLOCKNAME / LISTE)
  (if(and(setq BLOCK (tblobjname "block" BLOCKNAME))   
         (setq LISTE(entget(cdr (assoc 330 (entget BLOCK)))))
         (setq LISTE(cdr(reverse(cdr(member(assoc 102 LISTE)LISTE)))))
     )
    (mapcar '(lambda(X)
               (not(vl-catch-all-error-p
                     (vl-catch-all-apply
                       'vla-delete
                       (list X)
                     )
                   )
               )
             )
             (vl-remove-if-not '(lambda(Y) Y)       
                (mapcar '(lambda(X) (vlax-ename->vla-object  X))
                        (mapcar '(lambda(X) (cdr X)) LISTE)
                )
             )   
    )             
  )
)


and you can call both functions

(blockrefdelete (cdr(assoc 2(entget(ssname (ssget "_:S" '((0 . "INSERT")))0)))))
« Last Edit: October 05, 2006, 03:48:16 AM by CADmium »
"Bei 99% aller Probleme ist die umfassende Beschreibung des Problems bereits mehr als die Hälfte der Lösung desselben."

Patrick_35

  • Guest
Re: delete block in all layout.
« Reply #3 on: October 05, 2006, 09:30:40 AM »
Hi
An another

Code: [Select]
(defun c:delb(/ bloc bls bl ent)
  (if (setq bloc (getstring T "\nBlock name : "))
    (if (tblsearch "block" bloc)
      (progn
        (setq bls (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
        (vlax-for bl bls
          (vlax-for ent bl
            (if (eq (vla-get-objectname ent) "AcDbBlockReference")
              (if (eq (strcase (vla-get-name ent)) (strcase bloc))
                (vla-delete ent)
              )
            )
          )
        )
      )
      (princ (strcat "\nBlock " bloc " don't exist"))
    )
  )
  (princ)
)

@+

kpblc

  • Bull Frog
  • Posts: 396
Re: delete block in all layout.
« Reply #4 on: October 05, 2006, 09:43:46 AM »
Your code will erase block definition, not reference (i think). And anyway you're working with block collection (not insertions)
Sorry for my English.

Patrick_35

  • Guest
Re: delete block in all layout.
« Reply #5 on: October 05, 2006, 10:08:43 AM »
There is an trick. Test it

@+

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: delete block in all layout.
« Reply #6 on: October 05, 2006, 10:18:02 AM »
This is an oldie I created. May not be what you want.
Deletes a list of block names and purges them.

<edit: removed code as it does not work as planed>
« Last Edit: October 05, 2006, 10:49:28 AM by CAB »
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: delete block in all layout.
« Reply #7 on: October 05, 2006, 10:25:58 AM »
This is an oldie I created. May not be what you want.
Deletes a list of block names and purges them.

Today, my morning began from such program and coffee...
Your program deletes all blocks only in the last page

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: delete block in all layout.
« Reply #8 on: October 05, 2006, 10:37:23 AM »
Thanks Evgeniy

Checking the code, you are correct.
Back then I was using one layout drawings & switched to xrefs & multi tabs
and left that code behind. I'll put it in the trash bin and use yours. :)
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: delete block in all layout.
« Reply #9 on: October 05, 2006, 10:40:56 AM »
I have deleted the last post...
Has rechecked it is it does not work: (

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: delete block in all layout.
« Reply #10 on: October 05, 2006, 11:20:05 AM »
kpblc & Evgeniy

If I may be so bold, I took your routines & modified for my subroutine like this.

Code: [Select]
(defun delblock_1 (bnames / ss)
  (if (setq ss
             (ssget
               "_X"
               (list
                 '(0 . "INSERT")
                 (cons 2
                       (substr
                         (apply
                           (function strcat)
                           (mapcar (function (lambda (x) (strcat "," x)))
                                   bnames
                           )
                         )
                         2
                       ) ;_  substr
                 )
               ) ;_ end of list
             ) ;_ end of ssget
      )
    (foreach item
                  (mapcar
                    'vlax-ename->vla-object
                    (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
                  ) ;_ end of mapcar
      (vla-erase item)
    ) ;_ end of foreach
  )
) ;_ end of defun

Code: [Select]
(delblock_1 '("Aproved Title Block D" "Aproved Title Block"))
« Last Edit: October 05, 2006, 11:29:11 AM by CAB »
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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: delete block in all layout.
« Reply #11 on: October 05, 2006, 05:23:27 PM »
Woo !   :roll:

thanks all for the quick response..
Keep smile...

whdjr

  • Guest
Re: delete block in all layout.
« Reply #12 on: October 10, 2006, 03:46:36 PM »
This is my favorite however I am partial.   :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: delete block in all layout.
« Reply #13 on: October 11, 2006, 01:21:59 PM »
nice one wh... :wink:
Keep smile...

ELOQUINTET

  • Guest
Re: delete block in all layout.
« Reply #14 on: February 02, 2007, 04:23:35 PM »
I just happened to come across this post in a search and was wondering if anyone has a lisp that I could run in a batch script to get rid of a specified block from all layouts without picking it. It would also be splendid if it then purged the block out of the drawing. I know this is available just haven't had the time to do a full sweep of the forum today.