Jump to content

Z values lisp please


Organic

Recommended Posts

Try this for lines:

 


(defun c:0line (/ ss pt1 pt2 lst)
 (if (setq ss (ssget "X" (list (cons 0 "LINE")
   (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
      (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (setq ss (mapcar 'entget (mapcar 'cadr (ssnamex ss))))
     (foreach elst ss
   (setq pt1 (cdr (assoc 10 elst)) pt2 (cdr (assoc 11 elst)))
   (setq pt1 (subst 0.0 (last pt1) pt1) pt2 (subst 0.0 (last pt2) pt2))
   (setq lst (subst (cons 10 pt1) (assoc 10 elst) elst))
   (entmod (subst (cons 11 pt2) (assoc 11 lst) lst))))
   (princ "\n<!> No Lines Found <!>"))
 (princ))

 

Not my best, but its gone midnight here.

Link to comment
Share on other sites

To be honest, in my posted LISP i wanted to change both start points and end points at the same time using a mapcar function, but for some reason only the endpoint would be updated when I did it that way, so had to settle for the less elegant method. :(

Link to comment
Share on other sites

Sometimes less elegant methods work fine, maybe even less code!

 

For example you could select all lines & polylines, (say ss1) then use the move command on them to "flatten" to 0:

 

(command "._move" ss1 "" '(0.0 0.0 1e99) "" "._move" ss1 "" '(0.0 0.0 -1e99) "")

Link to comment
Share on other sites

Maybe it has changed over the years, but "_.CHANGE " "_P" "_E" would be sweet if it dealt with differing z values

Command:
CHANGE
Select objects: l
1 found

Select objects:
Specify change point or [Properties]: _P

Enter property to change [Color/Elev/LAyer/LType/ltScale/LWeight/Thickness]: _E

Specify new elevation <varies>: 0

Enter property to change [Color/Elev/LAyer/LType/ltScale/LWeight/Thickness]:

Cannot change elevation of objects with differing Z coordinates.

So its back to AutoLISP

 

Change all model space LINEs Z axis values to 0.0

 

[b][color=BLACK]([/color][/b]defun c:flatline [b][color=FUCHSIA]([/color][/b]/ ss i en ed p10 p11 n10 n11[b][color=FUCHSIA])[/color][/b]
  [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]67 . 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b]
                    ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                   p10 [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 10 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                   n10 [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]car p10[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cadr p10[b][color=BLUE])[/color][/b] 0.0[b][color=GREEN])[/color][/b]
                   p11 [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 11 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                   n11 [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]car p11[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cadr p11[b][color=BLUE])[/color][/b] 0.0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 10 n10[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 10 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 11 n11[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 11 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Link to comment
Share on other sites

try this i found it the Other Day for A freind of mine He Was Having problems With Files That he was sent All The plan Drawings Were on Diffrent z's This moved All to 0 And Did not miss any he Was happy Hope this Helps Download And Load Lisp And Type Z0 in Commandline Select All In Drawing Then It moves All Or only select What you need to move

 

Regards Dave b

MOVEZ.lsp

Link to comment
Share on other sites

  • 4 weeks later...
try this i found it the Other Day for A freind of mine He Was Having problems With Files That he was sent All The plan Drawings Were on Diffrent z's This moved All to 0 And Did not miss any he Was happy Hope this Helps Download And Load Lisp And Type Z0 in Commandline Select All In Drawing Then It moves All Or only select What you need to move

 

Regards Dave b

 

 

 

Works on autocad 2010?

Link to comment
Share on other sites

  • 2 weeks later...

Hey everyone,

I have R14 and am trying to use survey drawings to create 2D images. I have lots of lines that do not have z = 0. I have tried the posted LISPs and keep getting AutoLISP stack overflows. I have looked all over for a LISP to make both end points with a z = 0. Can anyone help as I have 20 drawings to work on.

Link to comment
Share on other sites

I found an easy way to do this actually. Just use Quick Properties to select all lines in the drawing, then on the Properties palette you can easily set the start and end Z values to 0 (all at the same time).

 

Thanks for those with lisps, they got me though till I found out how to dio it the easy way lol.

Link to comment
Share on other sites

Have you tried a LISP like this? To "flatten" all objects:

 

(defun c:flat  (/ laylst ss ssObj j)
 (vl-load-com)
 (vlax-for lay
        (vla-get-layers
          (vla-get-ActiveDocument
            (vlax-get-acad-object)))
   (setq laylst (cons lay laylst)))
 (mapcar '(lambda (l) (vla-put-lock l :vlax-false)) laylst)
 (if (setq ss (ssget "X"
             (list (if    (getvar "CTAB")
                 (cons 410 (getvar "CTAB"))
                 (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (setq ssObj (mapcar 'vlax-ename->vla-object
             (mapcar 'cadr (ssnamex ss))) j 0)
     (foreach Obj  ssObj
   (foreach n  '(1e99 -1e99)
     (if (vl-catch-all-error-p
       (vl-catch-all-apply
         '(lambda (x)
            (vla-move x (vlax-3d-point (list 0 0 0))
                  (vlax-3d-point (list 0 0 n))))
         (list Obj)))
       nil (setq j (1+ j)))))
     (princ (strcat "\n" (rtos (/ j 2.0)) " Objects Flattened.")))
   (princ "\n<!> No Objects Found <!>"))
 (princ))

Link to comment
Share on other sites

mlutzen: For Release 14 Vladmir Livshiz's Flatten.lsp routine should work quite nicely. The other option is to use the Change command. Change > Properties > All > Elevation > 0 > Enter. Done.

 

Note: There is a Flat.lsp routine in the CADTutor AutoLisp Archive section too.

Link to comment
Share on other sites

Thanks for the tip on "Flatten", change only works with elevation and I had differing z coordiates which also prevented global quick prop. this is the working file.

 

Thanks again everyone, this has saved lots of tedious blah.......:shock:

Flatten.LSP

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