PDA

View Full Version : Please help. How to convert 3D drawing to 2D drawing?

SIDRIX
19th May 2011, 10:42 am
1. I was making my plan on 2D and then I went to 3D view, I saw that my 2D was actually all the time 3D, it wasn’t on x,y axes only, it had many deformations around y ax. (That also finally explained why I had measurement problems in 2D) But I need the plans flat in 3D, so I could put the 1st floor plan properly and nice looking above the second! Isn’t there an option to make the 3D nice flat and the same looking in 2D?
Thanks a lot.
Andris

Tiger
19th May 2011, 10:45 am
try the command FLATTEN. If you have lots of objects (blocks and such) I recommend doing FLATTEN on smallish parts first. It might appear at a stand-still for a while though but don't panic. Have a coffee and return later.

ReMark
19th May 2011, 10:52 am
Various methods for flattening 3D geometry explained within the attached document.

27680

SIDRIX
19th May 2011, 10:52 am
Wow that was amazing, everything works great, thanks a lot, you just saved a lot of work for me! :D

designerstuart
19th May 2011, 11:06 am
i know this has been solved by FLATTEN, but sometimes this doesn't work for me but alan cullen has written a great lisp called ZERO which does wonders. sorry i don't remember where i got it.

;----------------------------------------------------------------------------
; ZERO.LSP CHANGE "Z" VALUE OF ENTITIES TO ZERO
;================================================= ===========================
;DESCRIPTION: This routine will globally change the "z" value of all selected
; entities to zero.
; Select entities using any method (window, crossing etc.)
;
;WRITTEN BY: Alan Cullen December 1994
; McPherson Maclean Wargon Chapman - CAIRNS
;
;START COMMAND: zero
;
;AMENDED: August 1995 Error handler included
;
;;--------------------------------ERROR HANDLER------------------------------
(defun clerr (s)
(if (/= s "Function cancelled")
(if (= s "quit / exit abort")
(princ)
(princ (strcat "\nError: " s))
)
)
(command "_.UNDO" "_BACK")
(setq a nil)
(setvar "CMDECHO" ocmd)
(if olderr (setq *error* olderr))
(princ "\nERROR...CONSOLE BREAK...'Z' VALUES RESTORED TO PREVIOUS VALUES...")
(princ)
)
;;-----------------------------MAIN PROGRAM------------------------------

(defun c:zero (/ a olderr ocmd n index b1 c d b2 c2 d2 b3 c3 d3 b4 c4 d4 b5
c5 d5 b6 c6 d6 b7 c7 d7 b8 c8 d8 b9 c9 d9 b10)

(princ "\n CHANGE \"Z\" VALUE OF ENTITIES TO ZERO - August 1995 - Alan CULLEN")
(setq ocmd (getvar "CMDECHO"))

(setvar "CMDECHO" 0)

(setq olderr *error* *error* clerr) ;; Set new error handler

(command "_.UNDO" "_MARK")

(prompt "\nThis routine will change the 'z' value of selected entities to zero")

(setq a (ssget))

(setq n (sslength a))

(setq index 0)

(repeat n
(setq b1 (entget (ssname a index)))
(setq index (+ 1 index))

(progn
(setq c (assoc 10 b1 ))
(setq d (list (car c) (cadr c) (caddr c) 0))
(setq b2 (subst d c b1))
(setq c2 (assoc 11 b1 ))
(setq d2 (list (car c2) (cadr c2) (caddr c2) 0))
(setq b3 (subst d2 c2 b2))
(setq c3 (assoc 12 b1 ))
(setq d3 (list (car c3) (cadr c3) (caddr c3) 0))
(setq b4 (subst d3 3c b3))
(setq c4 (assoc 13 b1 ))
(setq d4 (list (car c4) (cadr c4) (caddr c4) 0))
(setq b5 (subst d4 c4 b4))
(setq c5 (assoc 14 b1 ))
(setq d5 (list (car c5) (cadr c5) (caddr c5) 0))
(setq b6 (subst d5 c5 b5))
(setq c6 (assoc 15 b1 ))
(setq d6 (list (car c6) (cadr c6) (caddr c6) 0))
(setq b7 (subst d6 c6 b6))
(setq c7 (assoc 16 b1 ))
(setq d7 (list (car c7) (cadr c7) (caddr c7) 0))
(setq b8 (subst d7 c7 b7))
(setq c8 (assoc 17 b1 ))
(setq d8 (list (car c8) (cadr c8) (caddr c8) 0))
(setq b9 (subst d8 c8 b8))
(setq c9 (assoc 18 b1 ))
(setq d9 (list (car c9) (cadr c9) (caddr c9) 0))
(setq b10 (subst d9 c9 b9))
(entmod b10)
)
)

(setq a nil)
(princ "\n all \"z\" values have been ZERO'D")
(setvar "CMDECHO" ocmd)
(setq *error* olderr) ;; Restore old error handler
(princ)
(princ)

19th May 2011, 11:21 am
you probably got that from here or the swamp. Alan was a major contributor to this forum a few years back.

ReMark
19th May 2011, 11:33 am
Allen's Zero.lsp was submitted to CADTutor on 23-May-2007.

SLW210
19th May 2011, 03:05 pm
In my opinion the Macro works the best overall, Allen's is good as well. I have had more than one drawing lockup on the Flatten command and I never use it.

DANIEL
19th May 2011, 03:10 pm
how is that zero lisp different from flatten?

designerstuart
19th May 2011, 04:02 pm
it must be in the coding but like SLW i find it more robust than the flatten command. never tried the flatten lisp though.

SLW210
19th May 2011, 04:35 pm
how is that zero lisp different from flatten?

I would have to see the code for AutoCAD flatten.

DANIEL
19th May 2011, 04:48 pm
I've been here how long and am just now posting my first code ? .....anyway lol, i hope i got it right ...

(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)
(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 <Y>: "))
(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))
)
)
)
)

;;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.01f loaded. Type FLATTEN to run it."
)
(princ)

ReMark
19th May 2011, 04:52 pm
I'm sorry, did you say you are posting your first code? Did I read that correctly?

DANIEL
19th May 2011, 04:58 pm
I'm sorry, did you say you are posting your first code? Did I read that correctly?

yes, well, on this forum, and it's not my code lol, i've had it so long though that i don't even recall where i got my flatten routine.

ReMark
19th May 2011, 05:05 pm
Daniel, I'm going to give you the benefit of the doubt here.

Code posting etiquette dictates that the author of the original code be acknowledged by retaining his/her header information. If an author is unknown then it should be stated up front.

The code you have posted was originally written by Mark Middlebrook and subsequently revised by Vladmir Livshiz with his permission. The following text always should accompany the code.

The code can be downloaded, in its entirety from a number of locations. This is one of them: http://www.activedwg.com/Downloads/Flatten.lsp

designerstuart
19th May 2011, 05:15 pm
now i am going to be careful here because i am scared of remark's laser eyes, but

Daniel, ... you are relatively newhis profile date says May 2005, and yours says Nov 2005! or......

Did I read that correctly?
LOL!

ps remark - you didn't use code tags! [ducking beneath desk]

ReMark
19th May 2011, 05:18 pm
I am older than Yoda looks. In reality I'm so old that "Dirt" is my younger brother by about two eons.

I can barely use Post-It Notes and you want me to use code tags? Don't you have a building design to finish today?

The post has been slightly modified re: relatively new.

DANIEL
19th May 2011, 05:20 pm
... i hope i got it right ...

guess i didn't lol