Extracting x, y, z information form a .DWG file

Extracting x, y, z information form a .DWG file

Anonymous
Not applicable
9,720 Views
17 Replies
Message 1 of 18

Extracting x, y, z information form a .DWG file

Anonymous
Not applicable

I have a few drawing files that contain both point and line type geometry. I need to export this data into a PostgreSQL data base.
However, when extracting the line type geometry, only the first z value (first point of the line) is used for the remaining values for x and y.

Is there a way to extract all the values for the lines within the drawing file? Ideally I would want something that is similar to:
Line1 - ((X1, Y1, Z1) (X2, Y2, Z2) (Xn, Yn, Zn)) etc.

Line2 - ((X1, Y1, Z1) (X2, Y2, Z2) (Xn, Yn, Zn)) etc.

 

Alternatively, is there a way to import a CAD file into PostgreSQL so that all X,Y,Z values are imported?

0 Likes
Accepted solutions (2)
9,721 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable

the command you need is eattext. This will export any graphical or data in your drawing.

 

You choose to select objects or use whole file to extract x, y, & Z as required.

 

 

Hope this helps

 

Message 3 of 18

Anonymous
Not applicable

I've tried using this command, but I have not been able to extract x,y,z information for the polylines/ lines that I am interested in. Is there a step that I'm not completing correctly? 
Currently, I've exported to a .xls format, and all the values that have a Name of "line", "polyline" or "3Dpolyline" have no values in the "position x", "position y", "position z" columns.
This is the information that I am looking for.

0 Likes
Message 4 of 18

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I need to export this data into a PostgreSQL data base

Do you only have plain AutoCAD or do you have AutoCAD Map 3D as product.

If you have only AutoCAD installed, do you have access to AutoCAD toolsets? If yes you can install AutoCAD Map 3D which gives you direct access to PostgreSql and also command _MAPEXPORT for exporting CAD-geometry to GIS-data.

 

>> when extracting the line type geometry, only the

>> first z value (first point of the line) is used

What command are you using to get that?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 18

Anonymous
Not applicable

Unfortunately I don't have access to these specialised tools, just the standard AutoCAD environment.

 

I'm not using any commands at the moment. I have a shape file that I assume is a direct copy of the .DWG file. So I've imported the shape file into QGIS, then imported into PostgrSQL database. However, like I mentioned before, only the z value (elevation) of the first vertices is used for the rest of the vertices. Are you aware of other ways to extract information from .DWG files?

 

So, I thought that if I could somehow extract the x,y,z of all the vertices of all the lines, I could create some kind of script to import into PostgrSQL/ QGis. But so far have had no luck.

0 Likes
Message 6 of 18

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I thought that if I could somehow extract the x,y,z of

>> all the vertices of all the lines

A list of points does not help as you then lose the information about how these points are connected.

 

>> Are you aware of other ways to extract information from .DWG files?

Yes, DXF as the most common file format for cad geometry data exchange.

But I don't know the tools you have to import the data to PostgreSQL, do you have FME?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 7 of 18

Anonymous
Not applicable

This is why I mention eattext as this is native in Autocad no addin or plugins required. if your on R2019 then you'll need to use -eattext

I use this to get a poins file form 2D survey plans to create topography in Revit. Basically you can extract any data from the dwg.

 

 

Here's the steps if you not familiar

The EATTEXT command is an eight-page Data Extraction wizard. That allows the user to get the desired shopping list of ingredients to make the point file.

Page 1 can Create a new data extraction

 6a0115711b8d26970b01bb09fd34a4970d.png

Page 2 sets the Data source

6a0115711b8d26970b01bb09fd34b7970d.png

Page 3 allows to select the attributed block.

6a0115711b8d26970b01bb09fd34c2970d.png

Page 4 allows for a Category filter of the Attribute and Geometry. Also checking the box of the XYZ Property.

6a0115711b8d26970b01b8d2e442ab970c.png

Page 5 allows to set the order of the columns by dragging them to a Northing Easting Elevation format

6a0115711b8d26970b01b7c95a0313970b.png

Page 6 Allows to set the Output data to external file (xls, csv, mdb, txt) In this case CSV is selected

6a0115711b8d26970b01b7c95a031d970b-800wi.png

Page 7 is omitted with this extraction

6a0115711b8d26970b01b8d2e442c6970c.png

Page 8 Allows to select Finish.

6a0115711b8d26970b01b8d2e442d1970c.png

 

Hope this helps.

Message 8 of 18

ara_neresesian
Collaborator
Collaborator

Hi 

Please upload your cad file.

to see more what you have in your drawing.

good luck

Message 9 of 18

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

@Anonymous 

>> Basically you can extract any data from the dwg

Sorry, not correct, you can not use _DATAEXTRACTION to export vertex coordinates of polylines.

And I guess that is what the OP is looking for.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 10 of 18

Anonymous
Not applicable

That is exactly what I'm looking for. I want the x,y,z coordinates for each vertex of all the lines in the drawing

0 Likes
Message 11 of 18

Anonymous
Not applicable

Unfortunately, due to confidentiality issues, I'm not able to upload the drawing. To try and explain what I am working with, it is a CAD drawing of sub surface utilities. Each line within the drawing represents an underground utility asset. The extents of the drawings is quite a large area, and therefore has a large variance in height, as well as x and y.

0 Likes
Message 12 of 18

ara_neresesian
Collaborator
Collaborator

Hi

we dont need all file , a small portion which includes thos lines and points.

maybe  they aren’t 2d line, they 3d line,or those point mayn’t a point, Could be a block.

or at list take a screen shot from lines and point properties .

good luck

0 Likes
Message 13 of 18

Anonymous
Not applicable

Top View:

Top ViewTop View

 

Bottom View:Front ViewFront View

 

As you can see, there is a significant difference in elevation, especially with the polyline that travels fro the highest point, to one of the lowest point.
This line has about 100 vertices along the line. So what I want is to get the x,y,z values of these vertices. (As well as the vertices and points of all the other lines)

0 Likes
Message 14 of 18

ara_neresesian
Collaborator
Collaborator

HI

Would you please select one of those line and show properties of that lines (screen shot)

I think they are 3d poly line  not line (they aren't the same)

good luck

0 Likes
Message 15 of 18

ara_neresesian
Collaborator
Collaborator
Accepted solution

Hi

i forget to say"

if you have 3dpoly line ,DATAEXTRACTION cant help you.

you need a lisp file to get that information.

u can use this lisp 

https://www.cadtutor.net/forum/topic/2417-extracting-3d-polyline-co-ordinates/

this one create a  *.csv file.

Capture.JPG

if you prove the data on csv file , with a little  modification on lisp  you can change  like yours.

and if you are expert in Execle , do it on the Execle without lisp modification.

good luck.

 

 

 

0 Likes
Message 16 of 18

Anonymous
Not applicable

Here is a screenshot of the properties of the longest line in the drawing.
The first image is the properties when the first vertex is selected (start of line):
ACAD_Properties_1.png

 

This second image is the properties when the last vertex is selected (end point):

ACAD_Properties_2.png

 

As you can see, there are 103 vertices, and a large variation in height (z value). 
I don't understand how if you check the properties, you can manually extract x,y,z values for each vertex, but there s no way to automatically export it.

0 Likes
Message 17 of 18

ara_neresesian
Collaborator
Collaborator
Accepted solution

Hi

As i told you they are 3d polyline, and you cant harvest the information by data extraction you need a lisp to do it.

See my last post!

😊

is it helpful ? 🤔

 

if not , i can change the autolip to give an export like this,

3dpolyline 1  (vertex 1    X1,Y1,Z1)(vertex 2  X2,Y2,Z2)......(vertex 123  X123,Y123,Z123)

3dpolyline n   (vertex 1    Xn,Yn,Zn).......

or like yours 

Line1 - ((X1, Y1, Z1) (X2, Y2, Z2) (Xn, Yn, Zn))

 

one more thing

how you will find in the drawing   "Line1" or "Line n"   from exported  excel file ? or its not important🤔

if you explain what you want to do with exported data,maybe we can help more,

lets say like this " do you need any tag  " 

or can you find line 65 (for example ) in the drawing and go to vertex 30 (for example).

i mean if want go back to the drawing and make some correction refer to excel, 

you have to think about this matter,

 

 

 

good luck

 

0 Likes
Message 18 of 18

Anonymous
Not applicable

Thank you so much! I am so grateful for your help. I used the lisp command and have successfully created a csv with all of the x,y,z values for all the 3D Polylines!
I would never had thought to create a custom command to do this, it has certainly opened up a new area of learning!
Thank you!

0 Likes