+ 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 2015
    Join Date
    Aug 2002
    Location
    Hampshire, UK
    Posts
    3,731

    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
    19,347

    Default

    Registered forum members do not see this ad.

    Below is a faster variation on the above:

    Code:
    (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)
        (princ)
    )
    (vl-load-com) (princ)
    Last edited by Lee Mac; 4th Nov 2014 at 12:49 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

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