View Full Version : Creating points from Excel Data sheets
todd.mackay
2005-01-18, 05:14 PM
I have Excel spread sheets with X and Y coordinates:
Example -
A-1 (Name column) 565837.3 (X column) 337756.4 (Y column)
A-2 (Name column) 565837.4 (X column) 337750.4 (Y column)
etc...
Would love to have a program that would create points (in Acad) at each X and Y and, to go further with it, it would be great if it would also put the name (A-1) right next to the point.
I might be able to create the points from the Excel coordinates but I'm not sure I know how to put the name next to each point.
Please help, I'll be trying to figure out as much as I can in the mean time.
Thank you - Todd
Mike.Perry
2005-01-18, 09:44 PM
Hi
I think the following thread should get you going in the right direction -
Excel X,Y Coordinates -->AutoCad???? (http://forums.augi.com/showthread.php?t=10880)
Have a good one, Mike
todd.mackay
2005-01-19, 02:22 PM
Hi
I think the following thread should get you going in the right direction -
Excel X,Y Coordinates -->AutoCad???? (http://forums.augi.com/showthread.php?t=10880)
Have a good one, Mike
I tried doing that right after I wrote this thread, but my problem with that is the only way, that I found, to go from Excel to Notepad is to do a save as *.txt. Then when I open it in Notepad, I get Tabs between the X and Y coordinates. If I could get it to go into Notepad as a comma-delimited file, that would save a long step (replacing the Tab with a Comma for 200+ coordinates).
And that's half the battle. I have to also figure out a way to place a Name tag to each coordinate and try to automate that into one smooth program.
Thanks for the help - Todd
Lemons
2005-01-19, 02:34 PM
If I could get it to go into Notepad as a comma-delimited file, that would save a long step (replacing the Tab with a Comma for 200+ coordinates).
You can save an Excel file as a CSV file, which is a comma delimited file. On my computer, the resulting csv file defaults to opening in Excel, but I can choose "Open with" and open it in NotePad. Play with it a little bit and I think you'll find this will work for you.
Good luck,
Celie
todd.mackay
2005-01-19, 03:51 PM
You can save an Excel file as a CSV file, which is a comma delimited file. On my computer, the resulting csv file defaults to opening in Excel, but I can choose "Open with" and open it in NotePad. Play with it a little bit and I think you'll find this will work for you.
Good luck,
Celie
That works great!!! Thanks a lot!!
jwanstaett
2005-01-19, 08:27 PM
try is code
;;test getxlsrange where the range data name is mydata
;;the Excel file need to be open
;;and the data range name mydata is set to
;;3 or 4 Columns and any number of rows
;; columns 1 is the text
;; columns 2 is the x
;; columns 3 is the y
;; and if you use coloumns 4 it is the z
(defun c:getXls()
(SETQ XX (getxlsrange "mydata"));Get the Excel data in the data range mydata
(addpoint xx)
)
;;function getxlsrage
;;Use
;;(getxlsrange "yourdatarange"
;; The Excel shoud be open before called this function
;;return
;; a list of row that are a list of the columns
;;exp: (("c1 r1" "c2 r1")("c1 r1" "c2 r2"))
(defun GetxlsRange (Myrange)
(setq myxls (vlax-get-or-create-object "Excel.Application"))
;start Excel
(vlax-put-property myxls "visible" t) ;make Excel visible
(setq myxlsnames (vlax-get-property myxls "names"))
;get the names collection object
(setq myxlsname (vlax-invoke-method myxlsnames "item" Myrange))
;the mydata name object
(setq myxlsRange (vlax-get-property myxlsname "RefersToRange"))
;get the range for mydata
(setq myxlsrows (vlax-get-property myxlsRange "rows"))
;get the rows in the range
(setq numRows (vlax-get-property myxlsrows "count"))
;the the number of rows in range
(setq myxlsColumns (vlax-get-property myxlsRange "Columns"))
;get the Columns in the range
(setq numColumns (vlax-get-property myxlsColumns "count"))
;the the number of Columns in range
(setq mydata nil) ;clear mydata
(setq mydatatemp nil) ;clear data
(setq r 1)
(repeat numrows
(setq c 1)
(repeat numcolumns
(setq mydatatemp
(append mydatatemp (list (getcell myxlsRange r c)))
)
(setq c (+ c 1))
)
(setq mydata (append mydata (list mydatatemp)))
(setq mydatatemp nil)
(setq r (+ r 1))
)
(SETQ MYDATA MYDATA)
)
(defun getcell (cmyrange crow ccolums)
(setq cmycells (vlax-variant-value (vlax-get-property cmyrange "item" crow ccolums)))
(setq cmydata (vlax-variant-value(vlax-get-property cmycells "Value")))
)
;this is the part that add the point to your drawing
;need to be in the space where you need the point paper or model
;change the layer and txthight to the set you need
;the data pointlist in a list of list
;exp:
;(("text1" x1 y1 )("test2" x2 y2)) or
;(("test1 x1 y1 z1)("test2" x2 y2 z2))
(defun ADDPoint(pointList )
(setq layer "layer");set layer to the layer name to add point on
(setq txthight 1);set txthight to the hight of the text
(foreach point pointlist
(setq entPoint (list (cons 0 "Point") (cons 8 layer) (cons 10 (cdr point))))
(entmake entpoint)
(setq entText (list (cons 0 "text") (cons 8 layer) (cons 10 (cdr point)) (cons 1 (car point))(cons 40 txthight)))
(entmake enttext)
)
)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.