Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

text in autocad - excel 1

Status
Not open for further replies.

aesoton

Marine/Ocean
Sep 25, 2002
42
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
 
Replies continue below

Recommended for you

Dear andrew299,
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
 
andrew299

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)
)
)
)
 
Thank you SEMott. I loaded the program and it opens a new file and reads all the points. The only problem is how do i stop the program when I have finished selecting my points?
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
 
Andrew299,

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
 
Thanks Everyone for their help, I have a program that takes selected text and writes it to a CSV file. This can be exported into excel. I have to state here that I did not write it but if anyone would like a copy then put a post on here and I will email it to them.
 
Dear friends,

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 & &quot;Pick a point:&quot;)
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
 
With a little modification to the VBA code (last reply), you pick as many points as you wish rather than one point at a time.
 
Dear Jotham,
The above VBA code lets you pick as many points as you wish.
:)
Farzad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor