# Thread: XYZ coordinate data export

1. ## XYZ coordinate data export

Registered forum members do not see this ad.

How do I export the XYZ coordinate data of 3D polyline vertices into a *txt or *xls files?

2. You will need a Lisp routine. Do you have the full AutoCAD?

3. Yes, I do have the full of AutoCAD 2007. Do you know where I can find such a routine? Thanks for the reply

4. Try PTEXPORT.LSP, found at http://www.dotsoft.com/freestuff.htm

5. You can try the following VBA application. It displays the coordinates of all 3DPolylines selected by the user in Excel.

Sub Export3DPolylines()

Dim objSS As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets("MySS").Delete
Set objSS = ThisDrawing.SelectionSets("MySS")
objSS.SelectOnScreen

Dim objent As AcadEntity
Dim MasRem() As AcadEntity
Dim N As Integer
N = -1

For Each objent In objSS
If objent.ObjectName <> "AcDb3dPolyline" Then
N = N + 1
If N = 0 Then
ReDim MasRem(N)
Else
ReDim Preserve MasRem(N)
End If
Set MasRem(N) = objent
End If
Next

objSS.RemoveItems MasRem

If objSS.Count = 0 Then
MsgBox "No 3DPolylines found!"
Exit Sub
End If

Dim Excel As Object
Set Excel = CreateObject("Excel.Application")
Set wkb = Excel.workbooks.Add
Set sht = wkb.sheets(1)

Dim MasCoord As Variant
Dim Col As Integer
Dim Row As Integer
Col = -3
Row = 1

For i = 0 To objSS.Count - 1
Col = Col + 4
Row = 1
MasCoord = objSS(i).Coordinates

sht.cells(1, Col) = "3DPolyline " & i + 1 & " coordinates"
sht.cells(2, Col) = "X"
sht.cells(2, Col + 1) = "Y"
sht.cells(2, Col + 2) = "Z"
Row = 2
For j = 0 To (UBound(MasCoord) + 1) / 3 - 1
Row = Row + 1
sht.cells(Row, Col) = MasCoord(3 * j)
sht.cells(Row, Col + 1) = MasCoord(3 * j + 1)
sht.cells(Row, Col + 2) = MasCoord(3 * j + 2)
Next
Next

Excel.Visible = True

End Sub

6. and this is for exporting polyline points into text or csv files to open them in excel. Note thet you can edit the program text tochange the separator. You may use \t to have the items separated by a tab, \n to have them on a new line or use any other symbol.
Code:
```;export old style polyline vertex coords to a text file
;    mfuccaro@hotmail.com
(defun c:pl2tx( / en ask i a file)
(setq en (car (entsel)))
(if en (setq ask (= "POLYLINE" (cdr (assoc 0 (entget en))))))
)
(setq file (open (getfiled "Output file"
(strcat (getvar "dwgprefix")
(substr (getvar "DWGNAME") 1 (- (strlen (getvar "dwgname")) 4)))
"txt"     ;file type
1) "w"))
(setq i 0 sep ";")    ;sep=separator
(while (or (zerop i) a)
(setq a (mapcar 'rtos (cdr (assoc 10 (entget (setq en (entnext en)))))))
(if a (write-line (strcat (car a) sep (cadr a) sep (caddr a)) file))
(setq i (1+ i))
)
(close file)
(princ (strcat "\n" (itoa (1- i)) " points exported"))
(princ)
)```
And HERE you will find help on how to run Lisp routines.

7. Registered forum members do not see this ad.

Hey... a few years later I found this post.

I ran the vba from Joro thanks it works really good except that...

Id really like to have alle the coordinate in the first 3 row. The code does export the coordinate of each polyline in different set of 3 row.

I tried to modified the code with no sucess. I tried to change col = col +4 to col = col but it didnt work.

I no nothing about coding.

If someonw can help it will save me a lot of time.

Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts