# 3D polyline Vector Z value to 2D polyline elevation...

## Recommended Posts

Hello everyone, I am quite new here in this forum and I was expecting some help.

Recently I've been working with water distribution models and I just faced a wasting time problem when working with elevation data. People in my office have to look for every elevation data in the topografic dwg and then write down all those numbers one by one in an Excel spreadsheet. I think this process is kinda waste of time, so I came here looking for some help. If anyone could help me I would apreciate it very much.

Basicaly, what I do actualy need is a lisp routine capable of converting a 3Dpolyline to a 2Dpolyline but changing also the 3D polylines' vector Z to the 2D polylines' elevation. For example: if I have a 3d polyline with vector Z value of 350 (meters), I want the lisp program to turn it into a 2D polyline with Elevation value of 350.

##### Share on other sites

3d polyline vertices (points) may have different Z coordinate... Are all them on the same elevation? If that's the case, the easiest way to do conversion is to explode 3d polyline, and then join lines into light 2d polyline (elevation will be preserved)...

M.R.

##### Share on other sites

3d polyline vertices (points) may have different Z coordinate... Are all them on the same elevation? If that's the case, the easiest way to do conversion is to explode 3d polyline, and then join lines into light 2d polyline (elevation will be preserved)...

M.R.

Actualy all the vertices of the 3d polylines have exactly the same Z vector value. I want all the vertices to continue at the same "elevation".

I found a lisp program to convert 3d polylines to 2d polylines but the program prompts for every elevation change what becomes annoying.

I will try ot be more specific: imagine 100 3dpolylines with different VECTOR Z values. Every 3dpolylines have a lot of vertices but they are all in the same Vector Z (elevation). So what I need is a program to convert those 3d polylines into 2dpolylines but also the program must convert the Vector Z (3dpolylines elevation) to Elevation (2dpolyline).

Once the number of 3d polylines is enourmous in every file that I have to work with, it becomes a huge waste of time to change every single 3dpolyline one by one.

##### Share on other sites

Just explode all 3d polylines and then join - all (new objects will be light 2d polylines with preserved elevations)...

M.R.

##### Share on other sites

Try something like this:

```;;------------=={ 3D Polylines to LWPolylines }==-------------;;
;;                                                            ;;
;;  Converts a selection of 3D Polylines to LWPolylines with  ;;
;;  elevation equal to the Z-component of the first vertex of ;;
;;  the 3D Polyline. Retains all properties of the original   ;;
;;  3D Polyline.                                              ;;
;;------------------------------------------------------------;;
;;------------------------------------------------------------;;

(defun c:3d2lw ( / e i l s v x )
(if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . 8))))
(repeat (setq i (sslength s))
(setq e (ssname  s (setq i (1- i)))
l (entget  e)
e (entnext e)
x (entget  e)
v nil
)
(while (eq "VERTEX" (cdr (assoc 0 x)))
(setq v (cons (assoc 10 x) v)
e (entnext e)
x (entget  e)
)
)
(if (entmake
(append
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons  090 (length v))
(cons  070 (logand 129 (cdr (assoc 70 l))))
(assoc 008 l)
(cond ((assoc 006 l)) ('(006 . "BYLAYER")))
(cond ((assoc 039 l)) ('(039 . 0.0)))
(cond ((assoc 062 l)) ('(062 . 256)))
(cond ((assoc 370 l)) ('(370 . -1)))
(assoc 210 l)
(assoc 410 l)
)
(mapcar '(lambda ( v ) (list 10 (cadr v) (caddr v))) (reverse v))
)
)
(entdel (cdr (assoc -1 l)))
)
)
)
(princ)
)
(princ)```

Edited by Lee Mac
##### Share on other sites

Lee Mac you are the one.. The routine worked just fine.

Cheers up to Lee Mac and a big thank you.

##### Share on other sites

You're welcome scremin.

##### Share on other sites

• 7 years later...

I know this is an old thread, but I am having the same issue and can't get Lee Mac's LSP to run using the command found in the source (3d2lw)

When I load the app, it also gives me this error: extra cdrs in dotted pair on input. I'm using AutoCAD 2018

I don't know how to code so I'm just trying to figure this out as I go.

##### Share on other sites

@Groke

Correct the following line in the code:

`(if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . ))));<--MISSING Value with DXF code 70`

With

`(if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . 8))));<-- CORRECTED`

Edited by pkenewell
##### Share on other sites

An alternative is to read Z, use flatten, then put property elevation to Z.

##### Share on other sites

2 hours ago, pkenewell said:

@Groke

Correct the following line in the code:

```
(if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . ))));<--MISSING Value with DXF code 70```

With

```
(if (setq s (ssget "_:L" '((0 . "POLYLINE") (-4 . "&=") (70 . 0))));<-- CORRECTED```

Shouldn't that be

`(70 . 8)`

for a 3d polyline. IIRC this was one of the problems when then site moved over and 8 )  became a smilie So you lost the 8 and a closing brace

Edited by dlanorh
##### Share on other sites

On 3/3/2020 at 6:25 PM, groke said:

I know this is an old thread, but I am having the same issue and can't get Lee Mac's LSP to run using the command found in the source (3d2lw)

When I load the app, it also gives me this error: extra cdrs in dotted pair on input. I'm using AutoCAD 2018

I don't know how to code so I'm just trying to figure this out as I go.

I've now corrected the code in my post from 2012 that was damaged by the forum software update - I daren't think how many other code snippets are affected by this issue...

##### Share on other sites

18 hours ago, dlanorh said:

Shouldn't that be

```
(70 . 8)```

for a 3d polyline. IIRC this was one of the problems when then site moved over and 8 )  became a smilie So you lost the 8 and a closing brace

Oops you are right - thanks for the correction and the explanation to the OP! Updated my original post.

Edited by pkenewell

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

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.