Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
cadlabrat
Posts: 10
Registered: ‎03-20-2003
Message 1 of 4 (104 Views)

importing coord. from excel to draw lines

104 Views, 3 Replies
02-08-2003 03:17 AM
i have approx 4,000 pairs (help!!) of coordinates (x,y & z) in an excel document, each pair representing a line. i'm supposed to draw these lines in acad. lisp-beginner's question: (if this is even possible) can anyone help me with a lisp routine that imports the coordinates from the excel document into acad, and draws the lines for me? grateful for any input!
*Broad, Doug
Message 2 of 4 (104 Views)

Re: importing coord. from excel to draw lines

02-08-2003 06:02 AM in reply to: cadlabrat
Although you can interface excel directly with
autocad, it is not beginners

territory.  For ease of implementation, I
suggest:

1.  Save the worksheet as text in
the csv format.

2.  Close excel and rename the file to have an
scr extension

3.  Drag it into notepad or
wordpad.

4.  Add the word LINE or PLINE at the
top.  Add a blank line at the bottom. Save.

5.  In autocad, enter script and choose your
new script file.  Voila.  The

lines are drawn

 

If you do this a lot and want a canned application,
drop me a line and

we'll discuss it.

Regards,

Doug

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
have
approx 4,000 pairs (help!!) of coordinates (x,y & z) in an excel document,
each pair representing a line. i'm supposed to draw these lines in acad.
lisp-beginner's question: (if this is even possible) can anyone help me with a
lisp routine that imports the coordinates from the excel document into acad,
and draws the lines for me? grateful for any
input!
*van Rij, w.k.m.
Message 3 of 4 (104 Views)

Re: importing coord. from excel to draw lines

02-09-2003 12:17 AM in reply to: cadlabrat
Try this:

The path to the Excel file was hard coded. Adapt as required

for the start points:
X- values are assumed in column 'A', Y values in 'B', Z in column 'C'

for the end points:
X- values are assumed in column 'D', Y values in 'E', Z in column 'F'
The routine stops at the first blank cell in the 'A' column.


(defun c:excel-lines (/ getcoords ms XL xlBook s-e)
(vl-load-com)
(defun getcoords (Sheet row /)
(if (vlax-get (vlax-get-property Sheet 'Range (strcat "A" (itoa row)))
'Value
) ;_ end of vlax-get
(list
(vlax-3d-point
(vlax-get (vlax-get-property Sheet 'Range (strcat "A" (itoa row)))
'Value
) ;_ end of vlax-get
(vlax-get (vlax-get-property Sheet 'Range (strcat "B" (itoa row)))
'Value
) ;_ end of vlax-get
(vlax-get (vlax-get-property Sheet 'Range (strcat "C" (itoa row)))
'Value
) ;_ end of vlax-get
) ;_ end of vlax-3d-point

(vlax-3d-point
(vlax-get (vlax-get-property Sheet 'Range (strcat "D" (itoa row)))
'Value
) ;_ end of vlax-get
(vlax-get (vlax-get-property Sheet 'Range (strcat "E" (itoa row)))
'Value
) ;_ end of vlax-get
(vlax-get (vlax-get-property Sheet 'Range (strcat "F" (itoa row)))
'Value
) ;_ end of vlax-get
) ;_ end of vlax-3d-point
) ;_ end of list
) ;_ end of if
) ;_ end of defun
(and (setq ms (vlax-get (vla-get-activedocument (vlax-get-acad-object))
'ModelSpace
) ;_ end of vlax-get
) ;_ end of setq
(or
(setq XL (vlax-create-object "Excel.Application"))
(alert "Could not load Excel. Sorry")
(exit)
) ;_ end of or
(not (vlax-put XL 'Visible :vlax-true))
;;(not (vlax-put XL 'ReferenceStyle 1))
(or (setq xlBook (vlax-invoke (vlax-get XL 'Workbooks)
'Open
"C:\\My documents\\coords.xls" ;; Or whereever your Excel file
resides
) ;_ end of vlax-invoke
) ;_ end of setq
(alert "Could not load the Excel file. Sorry to quit")
) ;_ end of or
(setq row 1
xlSheet (vlax-get xlBook 'ActiveSheet)
) ;_ end of setq
(while (setq s-e (getcoords xlSheet row))
(vlax-invoke-method
ms
'AddLine
(car s-e)
(cadr s-e)
) ;_ end of vlax-invoke
(setq row (1+ row))
) ;_ end of while
) ;_ end of and
(vlax-invoke-method XL 'Quit)
) ;_ end of defun

cadlabrat schreef in berichtnieuws
f141bd1.-1@WebX.maYIadrTaRb...
have approx 4,000 pairs (help!!) of coordinates (x,y & z) in an excel
document, each pair representing a line. i'm supposed to draw these lines in
acad. lisp-beginner's question: (if this is even possible) can anyone help
me with a lisp routine that imports the coordinates from the excel document
into acad, and draws the lines for me? grateful for any input!
Active Member
cadlabrat
Posts: 10
Registered: ‎03-20-2003
Message 4 of 4 (104 Views)

Re: importing coord. from excel to draw lines

02-09-2003 01:16 AM in reply to: cadlabrat
w.k.m.van Rij, Doug - Thank you both for your input! although i'm at work (yes, i know it's sunday!) i can't access the specific excel file until tomorrow. i will, however, make an attempt at solving my "problem" first thing monday using your input - we'll see how it goes...might still need advice.

Magnus Palmgren
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.