Visual LISP, AutoLISP and General Customization
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
importing coord. from excel to draw lines
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
60 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
Re: importing coord. from excel to draw lines
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-08-2003 06:02 AM in reply to:
cadlabrat
Although you can interface excel directly with
autocad, it is not beginners
autocad, it is not beginners
territory. For ease of implementation, I
suggest:
suggest:
1. Save the worksheet as text in
the csv format.
the csv format.
2. Close excel and rename the file to have an
scr extension
scr extension
3. Drag it into notepad or
wordpad.
wordpad.
4. Add the word LINE or PLINE at the
top. Add a blank line at the bottom. Save.
top. Add a blank line at the bottom. Save.
5. In autocad, enter script and choose your
new script file. Voila. The
new script file. Voila. The
lines are drawn
If you do this a lot and want a canned application,
drop me a line and
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">
"cadlabrat" <have
href="mailto:magnuspalmgren@yahoo.com">magnuspalmgren@yahoo.com> wrote
in message
href="news:f141bd1.-1@WebX.maYIadrTaRb">news:f141bd1.-1@WebX.maYIadrTaRb...
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.
Re: importing coord. from excel to draw lines
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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!
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
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!
Re: importing coord. from excel to draw lines
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Magnus Palmgren

