Jump to content
CADTutor

Flatten

Recommended Posts

CADTutor

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 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)
   (princ)
)
(vl-load-com) (princ)

Edited by Lee Mac

Share this post


Link to post
Share on other sites
symoin
On 4/15/2009 at 1:26 AM, Lee Mac said:

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)
   (princ)
)
(vl-load-com) (princ)
 

 

how to select required objects and not all objects.

Share this post


Link to post
Share on other sites
ReMark

You have managed to resurrect a thread from 12 years ago.

 

One option would be to isolate the objects you want to flatten from all the other objects in the drawing.  You are familiar with freezing layers are you not?

  • Like 1

Share this post


Link to post
Share on other sites
ketxu
6 hours ago, symoin said:

how to select required objects and not all objects.

Maybe use the first post and supress "x" character ?

Share this post


Link to post
Share on other sites
symoin
On 12/19/2018 at 3:04 PM, ReMark said:

You have managed to resurrect a thread from 12 years ago.

 

One option would be to isolate the objects you want to flatten from all the other objects in the drawing.  You are familiar with freezing layers are you not?

Today I am in a situation, which the mentors might have foreseen 12 years ago. Thanks for the archive.

  • Like 1

Share this post


Link to post
Share on other sites
symoin
20 hours ago, ketxu said:

Maybe use the first post and supress "x" character ?

I could not locate the "x" as I believe this is visual lisp and not autolisp

Share this post


Link to post
Share on other sites
ReMark

Attach a copy of the drawing to your next post.  If the file size is too large then upload it to a file sharing website like DropBox and post a link to it here.  Indicate what object(s) need to be flattened.  Perhaps someone here can accomplish the task and provide you a copy of the result.

Share this post


Link to post
Share on other sites
Josue Rincon

Hi!

Use

(setq total-nabor (ssget))

instead of 

(setq total-nabor (ssget "x" '((410 . "model"))))

ssget without arguments will prompt the user to select objects through the AutoCAD general 'Select objects:' mechanism.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...