Jump to content

Flatten


CADTutor

Recommended Posts

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.

Link to comment
Share on other sites

  • 4 years later...

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
Link to comment
Share on other sites

  • 9 years later...
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...