PDA

View Full Version : Flatten



CADTutor
3rd Dec 2004, 07:31 pm
Flatten

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)
(vl-load-com)
(if
(setq total-nabor (ssget "x" '((410 . "model"))))
(progn
(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
total-nabor
) ;_ end of mapcar
) ;_ end of foreach
) ;_ end of progn
) ;_ end of if
(princ)
) ;_ end of defun



Download flat.lsp (http://www.cadimage.net/cadtutor/lisp/files/flat.lsp) 0.93 KB

See the original topic (http://www.cadtutor.net/forum/viewtopic.php?t=2119) for more details.

Lee Mac
14th Apr 2009, 11:26 pm
A faster variation on the above:



(defun c:flat ( / acsel elv ) (vl-load-com)
(if (ssget "_X" (list (cons 410 (getvar 'CTAB))))
(progn
(vlax-for obj
(setq acsel
(vla-get-ActiveSelectionSet
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
(foreach elv '(1e99 -1e99)
(vl-catch-all-apply 'vla-move
(list obj (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point (list 0. 0. elv)))
)
)
)
(vla-delete acsel)
)
)
(princ)
)
The above routine will not flatten 3D blocks - if you require these to be flattened also, they will need to be exploded before running the routine.