Jump to content
samifox

cant flatten a drawing

Recommended Posts

samifox

hi

 

i cant flatten this dwg.

 

can anyone take a look?

 

thanks

Shay

Share this post


Link to post
Share on other sites
BIGAL

I used Zero.lsp and it said "all done" problem is I do not want to spend 1/2 hour searching for non zero objects.

 

Please post dwg with objects that Flatten does not work on so we can help you. You have posted so obviously there are objects with non zero.

 

Any one a lisp non zero objects ??

Share this post


Link to post
Share on other sites
samifox

the drawing ive posted is after flattern.lsp but it didnt help

 

i didnt get what you are saying

 

flatten didnt edit anything in this drawing

Share this post


Link to post
Share on other sites
pendean
Posted (edited)

Use this lisp, it worked on your file just fine to move all of your errant objects back to Z=0.

 


; FLATTEN3 flattens entities onto the Z=0 X-Y plane in AutoCAD's World Coordinate System (WCS).
(defun C:FLATTEN3 (/ olderr oldcmd ss1 ss1len i numchg numnot numno0 ssno0
                   ename elist etype yorn)
;*error handler
  (setq olderr *error*)
  (defun *error* (msg)
     (if (= msg "quit / exit abort")
        (princ)
        (princ (strcat "error: " msg))
     )
     (setq *error* olderr)
     (command "._UCS" "_Restore" "$FLATTEN-TEMP$"
              "._UCS" "_Delete" "$FLATTEN-TEMP$")
     (command "._UNDO" "_End")
     (setvar "CMDECHO" oldcmd)
     (princ)
  )

;*setup
  (setq oldcmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "._UNDO" "_Group")
  (command "._UCS" "_Save" "$FLATTEN-TEMP$" "._UCS" "World") ;set World UCS

;*get input
  (prompt (strcat 
     "\nFLATTEN sets the Z coordinates of lines, polylines, circles, arcs,"
     "\ntext, dimensions, block inserts, points, hatches, and solids to zero."
  ))

  (initget "Yes No")
  (setq yorn (getkword "\nDo you want to continue <Y>: "))
  (cond ((/= yorn "No")
        (graphscr)  
        (prompt "\nChoose entities to FLATTEN ")
        (prompt "[press return to select all entities 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 
                            '("LINE" "POLYLINE" "TEXT" "INSERT" 
                              "CIRCLE" "ARC" "POINT" "SOLID" 
                              "DIMENSION" "LWPOLYLINE" "HATCH" "MTEXT")))
              (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 '("LINE" "POLYLINE" "TEXT" "INSERT" "CIRCLE"
                                "ARC" "POINT" "SOLID" "DIMENSION" "HATCH" 
                                "MTEXT"))
              (setq elist (zeroz 10 elist)     ;change entities in list above
                    numchg (1+ numchg)
              )
           )

;*change group 11 Z coordinate to 0 for LINEs, TEXT, and SOLIDs
           (if (member etype '("LINE" "TEXT" "SOLID" "DIMENSION"))
              (setq elist (zeroz 11 elist))
           )

;*change groups 12 and 13 Z coordinate to 0 for SOLIDs
           (if (member etype '("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))
              )
           )

;*special handling for R14 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
        );while
        (prompt " Done.")

;*print results
        (prompt (strcat "\n" (itoa numchg) " entity(s) flattened"))
        (prompt (strcat "\n" (itoa numnot) " entity(s) not flattened"))

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

  (command "._UCS" "_Restore" "$FLATTEN-TEMP$"
           "._UCS" "_Delete" "$FLATTEN-TEMP$")
  (command "._UNDO" "_End")
  (setvar "CMDECHO" oldcmd)
  (setq *error* olderr)
  (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)
)
(princ);end

Edited by rkmcswain
added [CODE] tags

Share this post


Link to post
Share on other sites
samifox

i get this :

 

Command: FLATTEN3

Yes or No, please.

error: Function cancelled

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended.

UCS "$FLATTEN-TEMP$" already exists. Replace it?

 

Share this post


Link to post
Share on other sites
pendean

Are you still on AutoCAD 2010? Simply start PROPERTIES, select everything on screen, sort by object type in the pulldown and set any/all Z settings to 0 (that's a zero). Should take about 3-minutes max to fix your Z=something problem entities.

Share this post


Link to post
Share on other sites
samifox
Use this lisp, it worked on your file just fine to move all of your errant objects back to Z=0.

 


; FLATTEN3 flattens entities onto the Z=0 X-Y plane in AutoCAD's World Coordinate System (WCS).
(defun C:FLATTEN3 (/ olderr oldcmd ss1 ss1len i numchg numnot numno0 ssno0
                   ename elist etype yorn)
;*error handler
  (setq olderr *error*)
  (defun *error* (msg)
     (if (= msg "quit / exit abort")
        (princ)
        (princ (strcat "error: " msg))
     )
     (setq *error* olderr)
     (command "._UCS" "_Restore" "$FLATTEN-TEMP$"
              "._UCS" "_Delete" "$FLATTEN-TEMP$")
     (command "._UNDO" "_End")
     (setvar "CMDECHO" oldcmd)
     (princ)
  )

;*setup
  (setq oldcmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "._UNDO" "_Group")
  (command "._UCS" "_Save" "$FLATTEN-TEMP$" "._UCS" "World") ;set World UCS

;*get input
  (prompt (strcat 
     "\nFLATTEN sets the Z coordinates of lines, polylines, circles, arcs,"
     "\ntext, dimensions, block inserts, points, hatches, and solids to zero."
  ))

  (initget "Yes No")
  (setq yorn (getkword "\nDo you want to continue <Y>: "))
  (cond ((/= yorn "No")
        (graphscr)  
        (prompt "\nChoose entities to FLATTEN ")
        (prompt "[press return to select all entities 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 
                            '("LINE" "POLYLINE" "TEXT" "INSERT" 
                              "CIRCLE" "ARC" "POINT" "SOLID" 
                              "DIMENSION" "LWPOLYLINE" "HATCH" "MTEXT")))
              (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 '("LINE" "POLYLINE" "TEXT" "INSERT" "CIRCLE"
                                "ARC" "POINT" "SOLID" "DIMENSION" "HATCH" 
                                "MTEXT"))
              (setq elist (zeroz 10 elist)     ;change entities in list above
                    numchg (1+ numchg)
              )
           )

;*change group 11 Z coordinate to 0 for LINEs, TEXT, and SOLIDs
           (if (member etype '("LINE" "TEXT" "SOLID" "DIMENSION"))
              (setq elist (zeroz 11 elist))
           )

;*change groups 12 and 13 Z coordinate to 0 for SOLIDs
           (if (member etype '("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))
              )
           )

;*special handling for R14 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
        );while
        (prompt " Done.")

;*print results
        (prompt (strcat "\n" (itoa numchg) " entity(s) flattened"))
        (prompt (strcat "\n" (itoa numnot) " entity(s) not flattened"))

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

  (command "._UCS" "_Restore" "$FLATTEN-TEMP$"
           "._UCS" "_Delete" "$FLATTEN-TEMP$")
  (command "._UNDO" "_End")
  (setvar "CMDECHO" oldcmd)
  (setq *error* olderr)
  (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)
)
(princ);end

 

it works!@

thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×