LT-Flatten (Z=0)

LT-Flatten (Z=0)

Anonymous
Not applicable
27,848 Views
17 Replies
Message 1 of 18

LT-Flatten (Z=0)

Anonymous
Not applicable
Inspired by a recent Autodesk NG's posting of Flatten LSP application,
here is a "quick-n-dirty" LT macro which flattens drawing entities (in
the current workspace) to Z=0.

[FlattenSel]^C^C_UCS;;_select \_move _p;;0,0,1e99;;_move _p;;0,0,-1e99;;

[FlattenAll]^C^C_UCS;;_move _all;;0,0,1e99;;_move _all;;0,0,-1e99;;

--------------
Vladimir Michl
CAD Studio s.r.o. - Autodesk Systems Center, HP Authorized Dealer
AutoCAD application development
[email protected] http://www.cadstudio.cz
Tylova 17, 370 01 Ceske Budejovice, Czech Rep.
tel. +420-38-6352966 fax. +420-38-6352979 BBS +420-38-6352962
Accepted solutions (2)
27,849 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable
Thanks for the macro Vladimir (and thanks for the earlier walkthrough by
Paul Turvil).

Just so you'll know, if you weren't already aware, moving the entities to a
maximim limit "glass box" and back to flatten them will distort any solids
in the drawing. If that's not a problem, then this is a good workaround
(Compare the massprops of a solid object before and after this flatten
routine.)

--
Bob Felton
PSG Product Support, Americas
WW Support & Services, Autodesk
Discussion Q&A: http://www.autodesk.com/discussion

Vladimir Michl wrote:

> Inspired by a recent Autodesk NG's posting of Flatten LSP application,
> here is a "quick-n-dirty" LT macro which flattens drawing entities (in
> the current workspace) to Z=0.
>
> [FlattenSel]^C^C_UCS;;_select \_move _p;;0,0,1e99;;_move _p;;0,0,-1e99;;
>
> [FlattenAll]^C^C_UCS;;_move _all;;0,0,1e99;;_move _all;;0,0,-1e99;;
>
> --------------
> Vladimir Michl
> CAD Studio s.r.o. - Autodesk Systems Center, HP Authorized Dealer
> AutoCAD application development
> [email protected] http://www.cadstudio.cz
> Tylova 17, 370 01 Ceske Budejovice, Czech Rep.
> tel. +420-38-6352966 fax. +420-38-6352979 BBS +420-38-6352962
Message 3 of 18

Anonymous
Not applicable
a thousand thank yous to the kind soul that created that macro - there are literally a dozen draftsmen celebrating right now!!!!!

mille grazie!
0 Likes
Message 4 of 18

Anonymous
Not applicable

Hi

Please advice me where should I add this macro in autocad.

We are using 2011 LT.

 

Thanks

 

0 Likes
Message 5 of 18

Charles_Shade
Mentor
Mentor

Create a Custom Command (button) in the CUI and place it in the Ribbon of your desire. This is entirely up to you.

 

Please mark any response as "Accept as Solution" if it answers your question.
_____________________________________________________________

Message 6 of 18

vaughn
Enthusiast
Enthusiast

Thnak you for this macro - you have saved me hours. Having nearly finished a site layout for 13 houses with contours and all levels drawn on I was wondering why i suddenly got a non co-planar issue when trying to fillet. A quick look at a side view and I realised that all the contours, retaining walls and building plots were all on different (and wrong) z geometry. AHHHHHHHH.

 

The flatten all macro didn't work for me but the flatten selected worked a treat.

 

Thanks again.

Smiley Happy

0 Likes
Message 7 of 18

Charles_Shade
Mentor
Mentor

Try this one for ALL entities. It may be the 13 year old translation of the original Macro that gets hung in later versions of AutoCAD LT software.

 

-Flatten Z coordinate:
^C^C_move;_all;;0,0,0;0,0,1e99;_move;_p;;0,0,0;0,0,-1e99;

0 Likes
Message 8 of 18

Anonymous
Not applicable

Using the Express tools flatten command returns an invaild point error 0,0,1e99. I have the macro as well and it is only moving the objects in teh positive direction. it returns an invalid point error. When I list the objects each time I run the macro the Z value increase IE: 0,0,1e99 then 0,0,2e99 and so on.

 

THe problem is another user did not catch this and all objects ( Plines, block, dimensions) have an z of 1.0000E+99. The problem is only 1 grip shows up on all items and you can only move the item.

 

Command: _move

Select objects: _all
2808 found
78 were not in current space.

Select objects:

Specify base point or [Displacement] <Displacement>: 0,0,0
Specify second point or <use first point as displacement>: 0,0,1e99

Command: _move

Select objects: _p
2730 found

Select objects:

Specify base point or [Displacement] <Displacement>: 0,0,0
Specify second point or <use first point as displacement>: 0,0​,-1e99

Invalid point.
Specify second point or <use first point as displacement>:

0 Likes
Message 9 of 18

pendean
Community Legend
Community Legend
The macro touted here will create that error on occasion: to fix it, you have to do it the long way in LT with PROPERTIES command to fix the Z setting that is listed that way.

For full AutoCAD, there are better Z=0 free lisp to use: Express Tools' FLATTEN does so much more than move items to Z=0 and you really have to know it's side effects as well. Full AutoCAD also have other better options to explore and use.
0 Likes
Message 10 of 18

Anonymous
Not applicable
Thank you for your response, but could I ask you to elaborate a little on the Full Autocad better options. Every search I do for this comes back with either the Macro code or the Flatten command, of which neither work.

The manual properties method really isn't an option at this point. The drawing with many details and several entities of which the dimensions that do not show the z location in the properties window. But do under the list command.



John Lowry
Project Manager
KT Fabrication Inc.
Phone 480-497-3140
Fax 480-497-3159
[Description: cid:[email protected]]
See our projects on Facebook ... don't forget to "like" our page.

The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, business-confidential and/or privileged material. If you are not the intended recipient of this message you are hereby notified that any use, review, re-transmission, dissemination, distribution, reproduction or any action taken in reliance upon this message is prohibited. If you received this in error, please contact the sender and delete the material from any computer. Any views expressed in this message are those of the individual sender and may not necessarily reflect the views of the company.
0 Likes
Message 11 of 18

pendean
Community Legend
Community Legend
Accepted solution

I use the Lisp below in full AutocAD to bring all items in a file to Z=0, you can search for others on the internet https://www.google.com/?gws_rd=ssl#q=autocad+flatten+lisp+routine

 

 

; FLATTEN2 sets the Z-coordinates of LINEs, POLYLINEs, LWPOLYLINEs, CIRCLEs, 
; ARCs, TEXT, DIMENSIONs, Block INSERTs, POINTs, HATCHes, and SOLIDs to 0.
; If you don't like the results, just type U to undo FLATTEN's work.
;
; Note that FLATTEN2 flattens entities onto the Z=0 X-Y plane in AutoCAD's
; World Coordinate System (WCS).

(defun C:FLATTEN2 (/ 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

 

0 Likes
Message 12 of 18

Anonymous
Not applicable
Hi is there any method for opposite function, points hight give to the existing 3d polyline, I have3d polyline passing through points. Any commands or lisp
0 Likes
Message 13 of 18

pendean
Community Legend
Community Legend
No LISP in LT.

If you know someone with AutoCADCivil3D they can help you out with this method https://knowledge.autodesk.com/support/autocad-civil-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/...
0 Likes
Message 14 of 18

Anonymous
Not applicable
I am sorry , but how can I get my points vertex and polyline vertex same, that is my main issue
0 Likes
Message 15 of 18

pendean
Community Legend
Community Legend
3DPLOY objects cannot have their vertices locations edited with any core commands in LT: 2d Plines vertices can be edited in PROPERTIES.

Are you only using LT? You need access to full AutoCAD or Civil to convert it. Download the trial for one of those if needed for a one time fix.
0 Likes
Message 16 of 18

bob
Contributor
Contributor

Thanks!

0 Likes
Message 17 of 18

bob
Contributor
Contributor

This macro used to work, when I had an earlier version of Autocad LT, but it appears that this macro is no longer useful with Autocad LT 2017. Has anyone else have luck with flattening lines in the newer versions of LT?

0 Likes
Message 18 of 18

pendean
Community Legend
Community Legend
Accepted solution
0 Likes