AutoCAD Architecture Customization
Welcome to Autodesk’s AutoCAD Architecture Customization Forums. Share your knowledge, ask questions, and explore popular AutoCAD Architecture Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flatten drawing

5 REPLIES 5
Reply
Message 1 of 6
dean-depetra
1644 Views, 5 Replies

Flatten drawing

I have a drawing that contains z value's and the flatten command doesn't work. The original drawing was a 3D model.

What can I do to flatten the entire 2D drawing?
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: dean-depetra

Configure a DXB plotter and plot to a file then
import the DXB file back into Autocad.

All lines will be white though, and on the same
layer


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a drawing that contains z value's and the flatten command doesn't work.
The original drawing was a 3D model.

What can I do to flatten the entire 2D
drawing?

Message 3 of 6
Anonymous
in reply to: dean-depetra

Here's a routine to do it.
--
Bobby C.
Jones
http://code.AcadX.com


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a drawing that contains z value's and the flatten command doesn't work.
The original drawing was a 3D model.

What can I do to flatten the entire 2D
drawing?

Message 4 of 6
deandepetra
in reply to: dean-depetra

Thanks for replying.
I have looked through the web page but can't seem to find anything that might help - flattening z value's.
What folder is it in and what is it called?
Cheers.
Message 5 of 6
Anonymous
in reply to: dean-depetra

The file was attached.  Sorry about
that.

 

;|

 

Flatten.lsp

 

Version history
1.0 2003/05/14 Initial
release.

 

Flattens all objects in all block objects
(including ModelSpace and Layouts) that are not on locked layers.
Warning!
This *will* render 3D solids as flat, although they will still list as having a
3D bounding box.
Warning! This operation is *not* reversible. An Undo will
*not* return objects to their original state.

 

Dependencies: rrbI:axPoint
Usage:
  Command: Flatten
Arguments: n/a
Returns:
 n/a

 

Copyright © 2003 by R. Robert Bell.

 

Written permission must be obtained to copy,
modify, and distribute this software.
Permission to use this software for any
purpose and without fee is hereby granted,
provided that the above copyright
notice appears in all copies and that both
the copyright notice and the
limited warranty and restricted rights notice below
appear in all supporting
documentation.

 

R. ROBERT BELL PROVIDES THIS PROGRAM "AS IS" AND
WITH ALL FAULTS.
R. ROBERT BELL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY
OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.
R. ROBERT BELL DOES
NOT WARRANT THAT THE OPERATION OF THE PROGRAM
WILL BE UNINTERRUPTED OR ERROR
FREE.

 


 

|;

 

(defun rrbI:axPoint 
(Pt)                                                      
; translate point list into SafeArray
 (vlax-SafeArray-Fill
 
(vlax-Make-SafeArray vlax-vbDouble (cons 0 (1- (length Pt))))
 
Pt))

 

(defun C:Flatten  (/ Inp pt1
pt2)
 (vl-Load-Com)                                                                 
; load ActiveX
interface
 (princ                                                                        
; warn the user
  "\nWarning! This command will flatten even 3D solids,
and cannot be undone.")
 (initget 0 "Yes
No")                                                          
; permit <enter> and keywords
 (setq Inp (cond ((getkword "\nDo
you wish to continue? [No/Yes] <No>: "))      ;
get user
input
                
("No")))                                                      
; return default if <enter>
 (cond ((eq "Yes"
Inp)                                                         
; if proceeding...
        (princ
"\nFlattening the
drawing,")                                    
; inform user
        (setq pt1
(rrbI:axPoint '(0.0 0.0
0.0))                                
; base
point
             
pt2 (rrbI:axPoint '(0.0 0.0
1e99)))                              
; extreme point
       
(vlax-Map-Collection
        
(vla-Get-Blocks (vla-Get-ActiveDocument
(vlax-Get-Acad-Object)))       ; for all
blocks...
        
(function
          (lambda
(objBlk)                                                     
; each object in a
block
          
(vlax-Map-Collection
           
objBlk
           
(function (lambda
(obj)
                      
(vl-Catch-All-Apply 'vla-Move '(obj pt1
pt2))            ;
flatten by extreme
move
                      
(vl-Catch-All-Apply 'vla-Move '(obj pt2
pt1))))))))      ; move back to
0,0,0
        (princ "
done.")))                                                     
; inform
user
 (princ))                                                                      
; clean exit

--
Bobby C. Jones

href="http://www.AcadX.com">www.AcadX.com


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thanks
for replying.
I have looked through the web page but can't seem to find
anything that might help - flattening z value's.
What folder is it in and
what is it called?
Cheers.
Message 6 of 6
deandepetra
in reply to: dean-depetra

Thanks again for your help.
I ran your routine but for some reason the 'z' values of line entities within the drawing, before running the routine had a 'z' value of 0.007......now whether the routine doesn't completely flatten it to '0.000', it didn't completly flatten it.

I have found another routine that does completly flatten lines completely to '0.000'

It's quite long.........let me know what you think in comparison to your routine? I don't understand the language so if you could shed some light on the difference it would be good, cheers.

Check it out:

;;; FLATTEN.LSP version 2k.01, 25-Jun-1999
;;;
;;; FLATTEN sets the Z-coordinates of these types of objects to 0
;;; in the World Coordinate System:
;;; "3DFACE" "ARC" "ATTDEF" "CIRCLE" "DIMENSION"
;;; "ELLIPSE" "HATCH" "INSERT" "LINE" "LWPOLYLINE"
;;; "MTEXT" "POINT" "POLYLINE" "SOLID" "TEXT"
;;;
;;;-----------------------------------------------------------------------
;;; copyright 1990-1999 by Mark Middlebrook
;;; Daedalus Consulting
;;; e-mail: markmiddlebrook@compuserve.com
;;;
;;; Thanks to Vladimir Livshiz for improvements in polyline handling
;;; and the addition of several other object types.
;;;
;;; You are free to distribute FLATTEN.LSP to others so long as you do not
;;; charge for it.
;;;
;;;-----------------------------------------------------------------------
;;; Revision history
;;; v. 2k.0 25-May-1999 First release for AutoCAD 2000.
;;; v. 2k.01 25-Jun-1999 Fixed two globalization bugs ("_World" & "_X")
;;; and revised error handler.
;;;-----------------------------------------------------------------------
;;;*Why Use FLATTEN?
;;;
;;; FLATTENing is useful in at least two situations:
;;; 1) You receive a DXF file created by another CAD program and discover
;;; that all the Z coordinates contain small round-off errors. These
;;; round-off errors can prevent you from object snapping to
;;; intersections and make your life difficult in other ways as well.
;;; 2) In a supposedly 2D drawing, you accidentally create one object with
;;; a Z elevation and end up with a drawing containing objects partly
;;; in and partly outside the Z=0 X-Y plane. As with the round-off
;;; problem, this situation can make object snaps and other procedures
;;; difficult.
;;;
;;; Warning: FLATTEN is not for flattening the custom objects created by
;;; applications such as Autodesk's Architectural Desktop. ADT and similar
;;; programs create "application-defined objects" that only the
;;; application really knows what to do with. FLATTEN has no idea how
;;; to handle application-defined objects, so it leaves them alone.
;;;
;;;-----------------------------------------------------------------------
;;;*How to Use FLATTEN
;;;
;;; This version of FLATTEN works with AutoCAD R12 through 2000.
;;;
;;; To run FLATTEN, load it using AutoCAD's APPLOAD command, or type:
;;; (load "FLATTEN")
;;; at the AutoCAD command prompt. Once you've loaded FLATTEN.LSP, type:
;;; FLATTEN
;;; to run it. FLATTEN will tell you what it's about to do and ask you
;;; to confirm that you really want to flatten objects in the current
;;; drawing. If you choose to proceed, FLATTEN prompts you to select objects
;;; to be flattened (press ENTER to flatten all objects in the drawing).
;;; After you've selected objects and pressed ENTER, FLATTEN goes to work.
;;; It reports the number of objects it flattens and the number left
;;; unflattenened (because they were objects not recognized by FLATTEN; see
;;; the list of supported objects above).
;;;
;;; If you don't like the results, just type U to undo FLATTEN's work.
;;;
;;;-----------------------------------------------------------------------
;;;*Known limitations
;;; 1) FLATTEN doesn't support all of AutoCAD's object types. See above
;;; for a list of the object types that it does work on.
;;; 2) FLATTEN doesn't flatten objects nested inside of blocks.
;;; (You can explode blocks before flattening. Alternatively, you can
;;; WBLOCK block definitions to separate DWG files, run FLATTEN in
;;; each of them, and then use INSERT in the parent drawing to update
;;; the block definitions. Neither of these methods will flatten
;;; existing attributes, though.
;;; 3) FLATTEN flattens objects onto the Z=0 X-Y plane in AutoCAD's
;;; World Coordinate System (WCS). It doesn't currently support
;;; flattening onto other UCS planes.
;;;
;;;=======================================================================

(defun C:FLATTEN (/ tmpucs olderr oldcmd zeroz ss1 ss1len
i numchg numnot numno0 ssno0 ename elist
etype yorn vrt crz
)
(setq tmpucs "$FLATTEN-TEMP$") ;temporary UCS

;;Error handler
(setq olderr *error*)
(defun *error* (msg)
(if (or
(= msg "Function cancelled")
(= msg "quit / exit abort")
)
;;if user cancelled or program aborted, exit quietly
(princ)
;;otherwise report error message
(princ (strcat "\nError: " msg))
)
(setq *error* olderr)
(if (tblsearch "UCS" tmpucs)
(command "._UCS" "_Restore" tmpucs "._UCS" "_Delete" tmpucs)
)
(command "._UNDO" "_End")
(setvar "CMDECHO" oldcmd)
(princ)
)

;;Function to change Z coordinate to 0

(defun zeroz (key zelist / oplist nplist)
(setq oplist (assoc key zelist)
nplist (reverse (append '(0.0) (cdr (reverse oplist))))
zelist (subst nplist oplist zelist)
)
(entmod zelist)
)
;;Setup
(setq oldcmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "._UNDO" "_Group")
(command "._UCS" "_Delete" tmpucs "._UCS" "_Save" tmpucs "._UCS" "_World")
;set World UCS

;;Get input
(prompt
(strcat
"\nFLATTEN sets the Z coordinates of most objects to zero."
)
)

(initget "Yes No")
(setq yorn (getkword "\nDo you want to continue : "))
(cond ((/= yorn "No")
(graphscr)
(prompt "\nChoose objects to FLATTEN ")
(prompt
"[press return to select all objects in the drawing]"
)
(setq ss1 (ssget))
(if (null ss1) ;if enter...
(setq ss1 (ssget "_X")) ;select all entities in database
)


;;*initialize variables
(setq ss1len (sslength ss1) ;length of selection set
i 0 ;loop counter
numchg 0 ;number changed counter
numnot 0 ;number not changed counter
numno0 0 ;number not changed and Z /= 0 counter
ssno0 (ssadd) ;selection set of unchanged entities
) ;setq

;;*do the work
(prompt "\nWorking.")
(while (< i ss1len) ;while more members in the SS
(if (= 0 (rem i 10))
(prompt ".")
)
(setq ename (ssname ss1 i) ;entity name
elist (entget ename) ;entity data list
etype (cdr (assoc 0 elist)) ;entity type
)

;;*Keep track of entities not flattened
(if (not (member etype
'("3DFACE" "ARC" "ATTDEF"
"CIRCLE" "DIMENSION" "ELLIPSE"
"HATCH" "INSERT" "LINE"
"LWPOLYLINE" "MTEXT" "POINT"
"POLYLINE" "SOLID" "TEXT"
)
)
)
(progn ;leave others alone
(setq numnot (1+ numnot))
(if (/= 0.0 (car (reverse (assoc 10 elist))))
(progn ;add it to special list if Z /= 0
(setq numno0 (1+ numno0))
(ssadd ename ssno0)
)
)
)
)

;;Change group 10 Z coordinate to 0 for listed entity types.
(if (member etype
'("3DFACE" "ARC" "ATTDEF" "CIRCLE"
"DIMENSION" "ELLIPSE" "HATCH" "INSERT"
"LINE" "MTEXT" "POINT" "POLYLINE"
"SOLID" "TEXT"
)
)
(setq elist (zeroz 10 elist) ;change entities in list above
numchg (1+ numchg)
)
)

;;Change group 11 Z coordinate to 0 for listed entity types.
(if (member etype
'("3DFACE" "ATTDEF" "DIMENSION" "LINE" "TEXT" "SOLID")
)
(setq elist (zeroz 11 elist))
)

;;Change groups 12 and 13 Z coordinate to 0 for SOLIDs and 3DFACEs.
(if (member etype '("3DFACE" "SOLID"))
(progn
(setq elist (zeroz 12 elist))
(setq elist (zeroz 13 elist))
)
)

;;Change groups 13, 14, 15, and 16
;;Z coordinate to 0 for DIMENSIONs.
(if (member etype '("DIMENSION"))
(progn
(setq elist (zeroz 13 elist))
(setq elist (zeroz 14 elist))
(setq elist (zeroz 15 elist))
(setq elist (zeroz 16 elist))
)
)

;;Change each polyline vertex Z coordinate to 0.
;;Code provided by Vladimir Livshiz, 09-Oct-1998
(if (= etype "POLYLINE")
(progn
(setq vrt ename)
(while (not (equal (cdr (assoc 0 (entget vrt))) "SEQEND"))
(setq elist (entget (entnext vrt)))
(setq crz (cadddr (assoc 10 elist)))
(if (/= crz 0)
(progn
(zeroz 10 elist)
(entupd ename)
)
)
(setq vrt (cdr (assoc -1 elist)))
)
)
)

;;Special handling for LWPOLYLINEs
(if (member etype '("LWPOLYLINE"))
(progn
(setq elist (subst (cons 38 0.0) (assoc 38 elist) elist)
numchg (1+ numchg)
)
(entmod elist)
)
)

(setq i (1+ i)) ;next entity
)
(prompt " Done.")

;;Print results
(prompt (strcat "\n" (itoa numchg) " object(s) flattened."))
(prompt
(strcat "\n" (itoa numnot) " object(s) not flattened.")
)

;;If there any entities in ssno0, show them
(if (/= 0 numno0)
(progn
(prompt (strcat " ["
(itoa numno0)
" with non-zero base points]"
)
)
(getstring
"\nPress enter to see non-zero unchanged objects... "
)
(command "._SELECT" ssno0)
(getstring "\nPress enter to unhighlight them... ")
(command "")
)
)
)
)

(command "._UCS" "_Restore" tmpucs "._UCS" "_Delete" tmpucs)
(command "._UNDO" "_End")
(setvar "CMDECHO" oldcmd)
(setq *error* olderr)
(princ)
)

(prompt
"\nFLATTEN version 2k.01 loaded. Type FLATTEN to run it."
)
(princ)

;;;eof

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost