Author Topic: List blocks containing objects with Z>0  (Read 1627 times)

0 Members and 1 Guest are viewing this topic.

w64bit

  • Newt
  • Posts: 78
List blocks containing objects with Z>0
« on: July 02, 2021, 06:02:13 AM »
I am using this code to check if a drawing has Z>0.
Code: [Select]
(if (and (/= (caddr (getvar "EXTMAX")) -1E+20)
      (or (> (abs (caddr (getvar "EXTMIN"))) 0)
          (> (abs (caddr (getvar "EXTMAX"))) 0)))
(alert "Drawing is 3D !"))
How I can get in addition, in an alert window or in command line, a list with all blocks containing objects with Z>0?
« Last Edit: July 02, 2021, 06:07:42 AM by w64bit »

kpblc

  • Bull Frog
  • Posts: 396
Re: List blocks containing objects with Z>0
« Reply #1 on: July 02, 2021, 07:29:20 AM »
Without any checking
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ is-block-with-3d res temp)
  2.   (defun is-block-with-3d (block-def / f mi ma)
  3.     (vlax-for ent block-def
  4.       (if (not f)
  5.         (progn
  6.           (if (not (vl-catch-all-apply
  7.                      (function (lambda ()
  8.                                  (vla-getboundingbox ent 'mi 'ma)
  9.                                  (setq mi (vlax-safearray->list mi)
  10.                                        ma (vlax-safearray->list ma)
  11.                                  ) ;_ end of setq
  12.                                ) ;_ end of lambda
  13.                      ) ;_ end of function
  14.                    ) ;_ end of vl-catch-all-apply
  15.               ) ;_ end of not
  16.             (setq f (apply (function and) (mapcar (function (lambda (x) (equal (caddr x) 0 1e-9))) (list mi ma))))
  17.           ) ;_ end of if
  18.         ) ;_ end of progn
  19.       ) ;_ end of if
  20.     ) ;_ end of vlax-for
  21.     f
  22.   ) ;_ end of defun
  23.     (if (setq temp (is-block-with-3d blk-def))
  24.       (setq res (cons (vla-get-name temp) res))
  25.     ) ;_ end of if
  26.   ) ;_ end of vlax-for
  27.   (if res
  28.     (princ (strcat "\nThese blocks has 3d geom:"
  29.                    (mapcar (function (lambda (x) (strcat "\n\t" x))) (vl-sort res (function <)))
  30.            ) ;_ end of strcat
  31.     ) ;_ end of princ
  32.   ) ;_ end of if
  33.   (princ)
  34. ) ;_ end of defun
Sorry for my English.

w64bit

  • Newt
  • Posts: 78
Re: List blocks containing objects with Z>0
« Reply #2 on: July 02, 2021, 04:35:44 PM »
Tried with the file attached. No message.

kpblc

  • Bull Frog
  • Posts: 396
Re: List blocks containing objects with Z>0
« Reply #3 on: July 04, 2021, 01:07:25 PM »
Try this
Code - Auto/Visual Lisp: [Select]
  1. (defun t1 (/ is-block-with-3d res)
  2.   (defun is-block-with-3d (block-def / f mi ma)
  3.     (vlax-for ent block-def
  4.       (if (not f)
  5.         (progn
  6.           (if (not (vl-catch-all-error-p
  7.                      (vl-catch-all-apply
  8.                        (function (lambda ()
  9.                                    (vla-getboundingbox ent 'mi 'ma)
  10.                                    (setq mi (vlax-safearray->list mi)
  11.                                          ma (vlax-safearray->list ma)
  12.                                    ) ;_ end of setq
  13.                                  ) ;_ end of lambda
  14.                        ) ;_ end of function
  15.                      ) ;_ end of vl-catch-all-apply
  16.                    ) ;_ end of vl-catch-all-error-p
  17.               ) ;_ end of not
  18. ;; modified. Thanks to ribarm
  19.             (setq f (apply (function or) (mapcar (function (lambda (x) (not (equal (caddr x) 0 1e-9)))) (list mi ma))))
  20.           ) ;_ end of if
  21.         ) ;_ end of progn
  22.       ) ;_ end of if
  23.     ) ;_ end of vlax-for
  24.     f
  25.   ) ;_ end of defun
  26.     (if (is-block-with-3d blk-def)
  27.       (setq res (cons (vla-get-name blk-def) res))
  28.     ) ;_ end of if
  29.   ) ;_ end of vlax-for
  30.   (if res
  31.     (princ (strcat "\nThese blocks has 3d geom:"
  32.                    (apply (function strcat)
  33.                           (mapcar (function (lambda (x) (strcat "\n\t" x))) (vl-sort res (function <)))
  34.                    ) ;_ end of apply
  35.            ) ;_ end of strcat
  36.     ) ;_ end of princ
  37.   ) ;_ end of if
  38.   (princ)
  39. ) ;_ end of defun
« Last Edit: July 05, 2021, 02:45:32 AM by kpblc »
Sorry for my English.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: List blocks containing objects with Z>0
« Reply #4 on: July 04, 2021, 03:18:46 PM »
There is a not missing on line 19.

kpblc

  • Bull Frog
  • Posts: 396
Re: List blocks containing objects with Z>0
« Reply #5 on: July 04, 2021, 04:57:12 PM »
Ok, fine, you're right. Right now threre is a midnight, I can't create any kind of code. Could you corrent it please?
Sorry for my English.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: List blocks containing objects with Z>0
« Reply #6 on: July 05, 2021, 01:53:51 AM »
  (defun is-block-with-3d (block-def / f mi ma)
    (vlax-for ent block-def
      (if (not f)
        (progn
          (if (not (vl-catch-all-error-p
                     (vl-catch-all-apply
                       (function (lambda ()
                                   (vla-getboundingbox ent 'mi 'ma)
                                   (setq mi (vlax-safearray->list mi)
                                         ma (vlax-safearray->list ma)
                                   ) ;_ end of setq
                                 ) ;_ end of lambda
                       ) ;_ end of function
                     ) ;_ end of vl-catch-all-apply
                   ) ;_ end of vl-catch-all-error-p
              ) ;_ end of not
            (setq f (apply (function or) (mapcar (function (lambda (x) (not (equal (caddr x) 0 1e-9)))) (list mi ma))))
          ) ;_ end of if
        ) ;_ end of progn
      ) ;_ end of if
    ) ;_ end of vlax-for
    f
  ) ;_ end of defun
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kpblc

  • Bull Frog
  • Posts: 396
Re: List blocks containing objects with Z>0
« Reply #7 on: July 05, 2021, 02:46:35 AM »
Thank you. Code modified.
Sorry, I forgot about this thread.
Sorry for my English.

w64bit

  • Newt
  • Posts: 78
Re: List blocks containing objects with Z>0
« Reply #8 on: July 05, 2021, 05:32:57 AM »
Thank you. It's working but it did not list all the blocks' names, only reports IS-BLOCK-WITH-3D for the whole DWG.

kpblc

  • Bull Frog
  • Posts: 396
Sorry for my English.

w64bit

  • Newt
  • Posts: 78
Re: List blocks containing objects with Z>0
« Reply #10 on: July 05, 2021, 09:18:56 AM »
Thank you.
I have to pay more attention.

w64bit

  • Newt
  • Posts: 78
Re: List blocks containing objects with Z>0
« Reply #11 on: July 11, 2021, 06:52:22 AM »
One question.
Is it possible to have the list of blocks in alert window instead of command line?

kpblc

  • Bull Frog
  • Posts: 396
Re: List blocks containing objects with Z>0
« Reply #12 on: July 11, 2021, 12:14:21 PM »
Replace princ to alert
Sorry for my English.

w64bit

  • Newt
  • Posts: 78
Re: List blocks containing objects with Z>0
« Reply #13 on: July 11, 2021, 06:57:24 PM »
Excellent. Thank you.