Jump to content


Recommended Posts




This routine will flatten a 3D drawing so that all Z values are set to zero. Although LDT has a specific function for this purpose, if you're using plain AutoCAD, this neat routine could save hours.


;   Flatten a 3D drawing 
;   Written by Eduard 
;   This command will set all elevations and points to zero, efectively flattening any 3D drawing. 
(defun c:flat (/ total-nabor) 
   (setq total-nabor (ssget "x" '((410 . "model")))) 
      (setq total-nabor 
       (mapcar 'vlax-ename->vla-object 
         (mapcar 'cadr 
           (ssnamex total-nabor) 

         ) ;_ end of mapcar 
       ) ;_ end of mapcar 
      ) ;_ end of setq 
      (foreach  i '(1e99 -1e99) 
  (mapcar (function (lambda (x) 
          (vla-move x 
              (vlax-3d-point (list 0 0 0)) 
              (vlax-3d-point (list 0 0 i)) 
          ) ;_ end of vla-move 
        ) ;_ end of lambda 
    ) ;_ end of function 
  ) ;_ end of mapcar 
      ) ;_ end of foreach 
    ) ;_ end of progn 
 ) ;_ end of if 
) ;_ end of defun

Download flat.lsp 0.93 KB


See the original topic for more details.

Share this post

Link to post
Share on other sites
Lee Mac

Below is a faster variation on the above:


(defun c:flat ( / doc org )
   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         org (vlax-3D-point 0 0 0)
   (vlax-for blk (vla-get-blocks doc)
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (if (vlax-write-enabled-p obj)
                   (foreach elv '(1e99 -1e99) (vla-move obj org (vlax-3D-point 0 0 elv)))
   (vla-regen doc acallviewports)
(vl-load-com) (princ)

Edited by Lee Mac

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now