Author Topic: Delete Objects on Layers from List  (Read 8668 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Delete Objects on Layers from List
« Reply #15 on: August 28, 2006, 02:57:51 PM »
(vlar-yourwelcome Gary)

Not sure if it will work with ObjectDBX though
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: Delete Objects on Layers from List
« Reply #16 on: August 28, 2006, 03:00:19 PM »
(vlar-yourwelcome Gary)

Not sure if it will work with ObjectDBX though
Nope.  You can't use (ssget.... ) with ObjectDBX.  I just code that way most of the time now, no biggie Alan.  If it's only for the current draiwng, no need to.  :wink:
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Delete Objects on Layers from List
« Reply #17 on: August 28, 2006, 03:30:56 PM »
Tim

Thanks

So is this how I should call it?

(DeletLays_ExplodeBlk
    (vla-get-ActiveDocument (vlax-get-Acad-Object)) '("A-ARE*" "A-DIM*" "A-NOT*" "A-PAT*" "A-SHT*" "A-SYM*") '("UT*"))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete Objects on Layers from List
« Reply #18 on: August 28, 2006, 03:47:12 PM »
Tim

Thanks

So is this how I should call it?

(DeletLays_ExplodeBlk
    (vla-get-ActiveDocument (vlax-get-Acad-Object)) '("A-ARE*" "A-DIM*" "A-NOT*" "A-PAT*" "A-SHT*" "A-SYM*") '("UT*"))

Gary

For the current draiwng, yes.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Delete Objects on Layers from List
« Reply #19 on: August 28, 2006, 04:10:28 PM »
Tim

Thanks. I was not sure. I get this error.

Because I can't speak vla I just want to be sure that the code expodes the blocks before deleteing the layers.


Command: (DeletLays_ExplodeBlk
(_>     (vla-get-ActiveDocument (vlax-get-Acad-Object))
(_>     '("A-ARE*" "A-DIM*" "A-NOT*" "A-PAT*" "A-SHT*" "A-SYM*")
(_>     '("UT*"))
; error: bad argument type: VLA-OBJECT nil

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #20 on: August 28, 2006, 04:16:02 PM »
vla-have vla-you vla-check vla-how vla-many vla-arguments vla-the vla-function vla-is vla-required vla-?

vlax-just vlax-guessing

GDF

  • Water Moccasin
  • Posts: 2081
Re: Delete Objects on Layers from List
« Reply #21 on: August 28, 2006, 04:25:51 PM »
vla-have vla-you vla-check vla-how vla-many vla-arguments vla-the vla-function vla-is vla-required vla-?

vlax-just vlax-guessing

Luis

vla-this-many -> (defun DeletLays_ExplodeBlk (Doc LayList BlkList / cnt)

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #22 on: August 28, 2006, 04:40:43 PM »
:-D

Have not tested Tim's code.... are you making sure that is possible to explode the block? and is not nested?, it is a valid list of blocks, it is check with vla-item? against vla-get-blocks?.... (again guessing)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Delete Objects on Layers from List
« Reply #23 on: August 28, 2006, 04:53:33 PM »
Oops :oops:
<reply removed.>
« Last Edit: August 28, 2006, 04:54:57 PM 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.

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #24 on: August 28, 2006, 04:55:14 PM »
Code: [Select]
(vl-position (strcase (vla-get-Name x)) (mapcar 'strcase BlkList))

Notice in the above code line, you are passing a wild card name not the valid block name.... and I think in the other calls too.....

GDF

  • Water Moccasin
  • Posts: 2081
Re: Delete Objects on Layers from List
« Reply #25 on: August 28, 2006, 04:55:42 PM »
Luis

:-D

Have not tested Tim's code.... are you making sure that is possible to explode the block? and is not nested?, it is a valid list of blocks, it is check with vla-item? against vla-get-blocks?.... (again guessing)

Yes, the unit blocks are have been "bind inserted" from xrefs that can be exploded.
It is not nested. It does however occur multiple times within the building plan.

Example: "building plan" drawing file has the following unit plans that were xrefed, but are now blocks within the drawing:
UTA4  four blocks
UTA5  four blocks
UTA6  two blocks

I hope this is clear. If I understood vlisp better I could read Tim's code

Here is what I am using:

Code: [Select]
;;;by Tim Willey 8/24/06
  (defun ReloadBindXrefs  (Doc / XrefList LstLen TroubleList)
    (vlax-for
   Blk (vla-get-Blocks Doc)
      (if (= (vla-get-IsXref Blk) :vlax-true)
(progn
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Reload (list Blk)))
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Detach (list Blk)))
      (setq TroubleList (cons Blk TroubleList))
      (prompt (strcat "\n Detached xref: " (vla-get-Name Blk))))
    (progn (vla-Bind Blk :vlax-true)
   (if (and (= (vla-get-IsXref Blk) :vlax-true)
    (not (vl-position (vla-get-Name Blk) XrefList)))
     (setq XrefList (cons Blk XrefList))))))))
    (setq LstLen (length XrefList))
    (while (and (> LstLen 0) (> LstLen (setq LstLen (length XrefList))))
      (foreach
     Blk  XrefList
(if (or (= (vla-get-IsXref Blk) :vlax-false)
(and (vla-Bind Blk :vlax-true) (= (vla-get-IsXref Blk) :vlax-true)))
  (setq XrefList (vl-remove Blk XrefList)))))
    (foreach
   Blk (append XrefList TroubleList)
      (prompt (strcat "\n Unable to bind xref: " (vla-get-Name Blk))))
    (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;by Tim Willey 8/28/06
  (defun DeletLays_ExplodeBlk  (Doc LayList BlkList / cnt)
    (defun ExplodeList (ObjList BlkList / NewObjList)
      (mapcar
'(lambda (x)
   (if (and (= (vla-get-ObjectName x) "AcDbBlockReference")
    (vl-position (strcase (vla-get-Name x)) (mapcar 'strcase BlkList)))
     (if (vl-catch-all-error-p
   (setq NewObjList
  (vla-catch-all-apply 'vlax-invoke (list x "Explode"))))
       (setq cnt (1+ cnt))
       (ExPlodeList NewObjList BlkList)))
   ObjList))
      (princ))
    ;------------------------------------------------------------------------------
    (setq cnt 0)
    (vlax-for
   Lo  (vla-get-Layouts Doc)
      (vlax-for
     Obj  (vla-get-Block Lo)
(cond
  ((vl-position
     T
     (mapcar '(lambda (x) (wcmatch (strcase (vla-get-Layer Obj)) (strcase x)))
     LayList))
   (vla-Delete Obj))
  ((and (= (vla-get-ObjectName x) "AcDbBlockReference")
(vl-position (strcase (vla-get-Name x)) (mapcar 'strcase BlkList)))
   (if
     (vl-catch-all-error-p
       (setq NewObjList (vla-catch-all-apply 'vlax-invoke (list x "Explode"))))
      (setq cnt (1+ cnt))
      (ExPlodeList NewObjList BlkList))))))
    (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (ReloadBindXrefs (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (DeletLays_ExplodeBlk
    (vla-get-ActiveDocument (vlax-get-Acad-Object))
    '("A-ARE*" "A-DIM*" "A-NOT*" "A-PAT*" "A-SHT*" "A-SYM*")
    '("UT*"))
  (princ))
(princ)

Gary
« Last Edit: August 28, 2006, 04:57:57 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #26 on: August 28, 2006, 05:05:03 PM »
Gary;

Test this:

In the block list argument, place the following:

(list "UTA4" "UTA5"  "UTA6") instead of ("UT*")

GDF

  • Water Moccasin
  • Posts: 2081
Re: Delete Objects on Layers from List
« Reply #27 on: August 28, 2006, 05:14:17 PM »
Luis

I already tried that. Also the wildcard worked in Tim's eariler example.
However it only exploded one occurance of the block and not all four.

This one works for exploding the block...just not all of the ones with the same name.
Code: [Select]
;;;by Tim Willey 8/24/06
(defun ReloadBindXrefs (Doc / XrefList LstLen TroubleList)
  (vlax-for
Blk  (vla-get-Blocks Doc)
    (if (= (vla-get-IsXref Blk) :vlax-true)
      (progn
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Reload (list Blk)))
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Detach (list Blk)))
    (setq TroubleList (cons Blk TroubleList))
    (prompt (strcat "\n Detached xref: " (vla-get-Name Blk))))
  (progn (vla-Bind Blk :vlax-true)
(if (and (= (vla-get-IsXref Blk) :vlax-true)
  (not (vl-position (vla-get-Name Blk) XrefList)))
   (setq XrefList (cons Blk XrefList))))))))
  (setq LstLen (length XrefList))
  (while (and (> LstLen 0) (> LstLen (setq LstLen (length XrefList))))
    (foreach
   Blk XrefList
      (if (or (= (vla-get-IsXref Blk) :vlax-false)
      (and (vla-Bind Blk :vlax-true) (= (vla-get-IsXref Blk) :vlax-true)))
(setq XrefList (vl-remove Blk XrefList)))))
  (foreach
Blk  (append XrefList TroubleList)
    (prompt (strcat "\n Unable to bind xref: " (vla-get-Name Blk))))
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;by Tim Willey 8/28/06
  (defun DeletObjLays  (Doc LayList)
    (vlax-for
   Lo  (vla-get-Layouts Doc)
      (vlax-for
     Obj  (vla-get-Block Lo)
(if
  (vl-position
    T
    (mapcar '(lambda (x) (wcmatch (strcase (vla-get-Layer Obj)) (strcase x)))
    LayList))
   (vla-Delete Obj))))
    (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;by Tim Willey 8/28/06
(defun ExplodeBlkList  (Doc BlkList / cnt)
  (setq cnt 0)
  (vlax-for
Lo  (vla-get-Layouts Doc)
    (vlax-for
   Obj (vla-get-Block Lo)
      (if
(and (= (vla-get-ObjectName Obj) "AcDbBlockReference")
     (vl-position
       T
       (mapcar '(lambda (x) (wcmatch (strcase (vla-get-Name Obj)) (strcase x)))
       BlkList)))
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Explode (list Obj)))
   (setq cnt (1+ cnt)))))
    (prompt (strcat "\n " (itoa cnt) " were not able to be exploded."))
    (princ)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (ReloadBindXrefs (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (ExplodeBlkList
  (vla-get-ActiveDocument (vlax-get-Acad-Object))
  '("UT*"))
  (DeletObjLays
    (vla-get-ActiveDocument (vlax-get-Acad-Object))
    '("*A-ARE*" "*A-DIM*" "*A-NOT*" "*A-PAT*" "*A-SYM*"))
  (princ))
(princ)

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #28 on: August 28, 2006, 05:15:02 PM »
Maybe an old fashion way of using the undocumented QAFLAGS variable = 1 and then to 0 and in between simple call the explode command on your selection set.

(setvar "qaflags" 1)
(command "_.explode" your_selection_set "")
(setvar "qaflags" 0)
« Last Edit: August 28, 2006, 05:44:26 PM by LE »

LE

  • Guest
Re: Delete Objects on Layers from List
« Reply #29 on: August 28, 2006, 05:21:03 PM »
And for your selection it can be:

Code: [Select]
(setq ss (ssget (list (cons 8 "A-ARE*,A-DIM*,A-NOT*,A-PAT*,A-SHT*,A-SYM*") (cons 2 "UT*"))))