Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to read excel file to insert text values at coordinates

5 REPLIES 5
Reply
Message 1 of 6
gilsoto13
15756 Views, 5 Replies

Lisp to read excel file to insert text values at coordinates

Hi, Guys

 

I've been off the forum for a long time, I know.... sorry about it... sometimes I answer threads or new questions from old threads, but now I got a simple new one, I may have a similar lisp around, but while I find it, I wanted to post my new little trouble for you guys.

 

I got a new work to help and get it done in the next 2 days, but first I need to do this... from a text file (or excel file, I got both) I got 3 columns, 1 one for node number, and 2 other for X and Y coordinates for each node.

 

So from that file I need to insert into autocad the node numbers as text (using the current style and height) at the point specified by the other two columns, that are the X,Y coordinates which will be the insertion point of text.... 

 

 

like this..

 

2619                 406,359.91                  1,866,448.12

 

Does anyone have a lisp to do this?

 

5 REPLIES 5
Message 2 of 6
pbejse
in reply to: gilsoto13


@gilsoto13 wrote:

Hi, Guys

 

I've been off the forum for a long time, I know.... sorry about it... sometimes I answer threads or new questions from old threads, but now I got a simple new one, I may have a similar lisp around, but while I find it, I wanted to post my new little trouble for you guys.

 

I got a new work to help and get it done in the next 2 days, but first I need to do this... from a text file (or excel file, I got both) I got 3 columns, 1 one for node number, and 2 other for X and Y coordinates for each node.

 

So from that file I need to insert into autocad the node numbers as text (using the current style and height) at the point specified by the other two columns, that are the X,Y coordinates which will be the insertion point of text.... 

 


So its text entity and not an attribute block? 

Message 3 of 6
Anonymous
in reply to: gilsoto13

Hi there.

Why not create a script file instead of a lisp since youre using excel? Its much easier that way.
Message 4 of 6
devitg
in reply to: gilsoto13

Better save the file as CSV, it is easy to handle.

 

Do you want the text´s insertion point be at such X Y values ??

 

Feel free to send me a sample DWG and the CSV or XLS , or upload it here .

 

 

 

 

 

 

 

 

 

Message 5 of 6
Anonymous
in reply to: gilsoto13

Attached lisp program. Copy program below into a text file and save as csvextract.lsp

 

Assumptions

 

1. CSV looks like this:  1234,100000.1, 1002034.1

                                      2345,200000.2,200403.1

 

2. Text style will be whatever is current

3. Text will be entered as MC justification and rotation angle of 0. Text height is entered as part of the program

4. Program allows user to select CSV fiel through a dialog box.

 

(defun c:csvextract()
   (echooff)
   (setq f (getfiled "Select CSV File" "c:/temp" "csv" 2))
   (setq g (open f "r"))
   (setq hgt (getreal "\nEhter text height: "))
   (while (/= (setq tmpstr(read-line g)) nil)
      (insert_data)
   )
   (echoon)
)
;
(defun insert_data ()
   (setq tmp "")
   (setq idx 1)
   (while (<= idx (strlen tmpstr))
      (if (/= (substr tmpstr idx 1) ",");extract number
         (progn
            (setq tmp (strcat tmp (substr tmpstr idx 1)))
            (setq idx (+ idx 1))
         )
   (progn
      (setq no tmp)
            (setq tmp "")
   (setq idx (+ idx 1))
   )
      )
      (if (/= (substr tmpstr idx 1) ",");extract x coord
         (progn
            (setq tmp (strcat tmp (substr tmpstr idx 1)))
            (setq idx (+ idx 1))
         )
   (progn
      (setq xpt tmp)
            (setq tmp "") 
            (setq idx (+ idx 1))
   )
      )
      (if (/= (substr tmpstr idx 1) ",");extract y coord
         (progn
            (setq tmp (strcat tmp (substr tmpstr idx 1)))
            (setq idx (+ idx 1))
         )
      )
    )  
    (setq ypt tmp)
 (setq tmp "")
    (command "text" "MC" (list (atof no) (atof ypt)) hgt 0 xpt)
)
;
(defun echooff ()
  (setq oldecho (getvar "CMDECHO"))
  (setq oldblip (getvar "BLIPMODE"))
  (setq oldosm (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  (setq olderror_echo *ERROR*)
  (terpri)
  (defun *ERROR* (msg)
    (princ " \n")
    (princ msg)
    (echoon)
  )
)
;
(defun echoon ()
  (setvar "CMDECHO" oldecho)
  (setvar "BLIPMODE" oldblip)
  (setvar "OSMODE" oldosm)
  (setq *ERROR* olderror_echo)
  (princ)
)

 

Separate note to Kent Cooper. Program works but I had to revise the TEXT command

 

(command "text" "MC" (list (atof no) (atof ypt)) hgt 0 xpt) 

 

Works although xpt should have been switched with no, yet when I did this the text was not inserted with correct text or coordinates. Used the ALERT command to check the value of no, xpt and yet as the program runs and everything displayed correctly, but then the text was inserted incorrectly. Woudl greatly appreciate your comments.

Message 6 of 6
gilsoto13
in reply to: gilsoto13

Thanks, to all of you guys for your help

 

 

But, anyway I need to tell you that found a lisp a few minutes after I made this thread, and I posted it also in Cadtutor, and I answered myself with the solution...

 

here is the thread I made in Cadtutor

http://www.cadtutor.net/forum/showthread.php?77838-Lisp-to-read-excel-file-to-insert-text-values-at-...

 

and here is the lisp is used in this case... worked perfect

https://sites.google.com/site/cadlispandtips/autocad-lisp/import-points

 

thanks and sorry for the delay in my answer

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost