text in autocad - excel
text in autocad - excel
(OP)
I found a lovely program in the shareware to give me the x,y,z coordintes of a point. The thing is it printas themn to a table in AutoCAD in the model space. Is there anyway to copy text from AutoCAD to excel?
the program is called XYZTBL.lsp
if someone could give me a lisp routine that does it then fantastic
Thank all for help
Andrew299
the program is called XYZTBL.lsp
if someone could give me a lisp routine that does it then fantastic
Thank all for help
Andrew299





RE: text in autocad - excel
I suggest you to write a program in VBA to access data in
Excel.
The below macro is written for AutoCAD VBA. It basically
reads data from current Excel session (from active cell)and
writes it in a message box. If you know some about EXCEL and AutoCAD VBA, you can extend the code to export coordinates to EXCEL.
Sub Main()
Dim ex As Object
Set ex = GetObject(, "EXCEL.Application")
MsgBox ex.ActiveCell
End Sub
You can write the program so that there is no need to run
the Excel and read data directly from a xls file.
The VLISP can do all, but it is more complicated.
:)
Farzad
RE: text in autocad - excel
Here is a very crude lisp file that will let you create a file and then let you pick points and they will be written to that file with the point number, x-coord, y-coord, z-coord (comma delimited). The number of decimal places depends on what you have them set to in Acad. This was created by cutting and pasting code from various lisp files. It works in R14 and I don't see why it would not work for other releases
Hope this helps,
SEMott
(defun C:xyz-export (/ Temp_Name Temp_File File_Name
Count xc yc zc Coords)
(setvar "cmdecho" 0)
(setq Temp_Name (getstring "Enter the file name: "))
(setq Temp_File (open Temp_Name "r"))
(if (/= Temp_File nil)
(progn
(prompt "File already exists.\n")
(close Temp_File)
)
(progn
(setq File_Name (open Temp_Name "w"))
(prompt "\nFile now open")
(setq Exit nil)
(setq Count 0)
(while (null Exit)
(setq p1 (getpoint "\nSelect Point for Coordinate Export: "))
(cond
((null P1)(setq Exit 1))
(t (progn
(setq
count (1+ count)
xc (rtos (car p1) 2)
yc (rtos (cadr p1) 2)
zc (rtos (caddr p1) 2)
coords (strcat (rtos count 2 0) (chr 44) xc (chr 44) yc (chr 44) zc)
)
(write-line coords File_Name)
)
)
)
)
(close File_Name)
)
)
)
RE: text in autocad - excel
The program reads the points to the command line from which I can cut and paste to excel so to all intents and purposes it is perfect.
Thanks again very much
Andrew299
RE: text in autocad - excel
To stop the program just hit <spacebar> or <enter>. I made the format for the text file that is created - comma delimited, therefore you can easily import it or open it in Excel.
SEMott
RE: text in autocad - excel
RE: text in autocad - excel
The below VBA code writes the coordinates of picked points directly int EXCEL. It calls EXCEL automatically.
Sub Main()
Dim Excel As Excel.Application
Dim ExcelWorkbook As Object
Dim flag As Boolean
Dim pp As Variant
On Error Resume Next
Set Excel = New Excel.Application
Excel.Visible = True
Set ExcelWorkbook = Excel.Workbooks.Add
pp = False
flag = True
Do While flag
pp = ThisDrawing.Utility.GetPoint _
(, vbCrLf & "Pick a point:")
If pp <> False Then
Excel.ActiveCell.Value = pp(0)
Excel.ActiveCell.Offset(0, 1).Value = pp(1)
Excel.ActiveCell.Offset(0, 2).Value = pp(2)
Excel.ActiveCell.Offset(1, 0).Activate
Else
flag = False
End If
pp = False
Loop
End Sub
:)
Farzad
RE: text in autocad - excel
RE: text in autocad - excel
The above VBA code lets you pick as many points as you wish.
:)
Farzad