+ Reply to Thread
Results 1 to 2 of 2

Thread: Flatten

  1. #1
    Administrator CADTutor's Avatar
    Computer Details
    CADTutor's Computer Details
    Operating System:
    Windows 7 Home Premium 64bit
    Motherboard:
    Asus P7P55D-E PRO
    CPU:
    Intel Core i7-860
    RAM:
    4GB PC3-12800 C8 Corsair Dominator
    Graphics:
    NVIDIA Quadro FX 1800 768 MB
    Primary Storage:
    Intel X25-M SSD 160GB
    Secondary Storage:
    Samsung Spinpoint 320GB
    Monitor:
    BenQ FP241W 24" Wide
    Discipline
    Education
    CADTutor's Discipline Details
    Occupation
    Senior Lecturer (Digital Design), Landscape Architect & Web Designer
    Discipline
    Education
    Using
    AutoCAD 2014
    Join Date
    Aug 2002
    Location
    Hampshire, UK
    Posts
    3,606

    Default Flatten

    Registered forum members do not see this ad.

    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.

    Code:
    ;   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 0.93 KB

    See the original topic for more details.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.
    AutoCAD Tutorials | How to add images to your posts | How to register successfully | Forum FAQ

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    Registered forum members do not see this ad.

    A faster variation on the above:

    Code:
    (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.
    Last edited by Lee Mac; 6th Apr 2011 at 03:25 pm.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts