Jump to content

Importing Data Text to Autocad


lucky9

Recommended Posts

Hi, I have set of data in xls/csv format

 

I have also attached the complete xls file for the reference.

 

What I need is the lisp routine that will ask for the xls or csv file and import the text in the drawing in new or current layer (User choice)

 

I know that this can be done using " -TEXT Command " but I need a lisp to do it without the hackle of copying and pasting the data to autocad

 

 

Thanks :)

 

Format of Data in excel file is given as under and the original excel is attached.

 

Count Name Height Obliquing Position X Position Y Position Z Rotation Style Thickness Value Width Factor Text

1 Text 5.0000 0 49285.6009 54406.5908 0.0000 0 Standard 0.0000 1 1.0000 250

1 Text 5.0000 0 49272.7950 54398.0611 0.0000 0 Standard 0.0000 2 1.0000 250

1 Text 5.0000 0 49248.2878 54415.1307 0.0000 0 Standard 0.0000 3 1.0000 200

1 Text 5.0000 0 49238.3952 54465.0371 0.0000 0 Standard 0.0000 4 1.0000 200

1 Text 5.0000 0 49238.1664 54498.7899 0.0000 0 Standard 0.0000 5 1.0000 200

1 Text 5.0000 0 49264.4541 54528.9029 0.0000 0 Standard 0.0000 6 1.0000 125

1 Text 5.0000 0 49331.2186 54487.0991 0.0000 0 Standard 0.0000 7 1.0000 100

Sample.xls

Link to comment
Share on other sites

What does Value column relate to, and is Text column the actual text?

 

The coordinates XY of points have been extracted from using autocad with all the attributes like position , rotation etc..

Text column is the text which is needed to be placed in the extracted points (coordinates - XY)

 

Regards,

Lucky9

Link to comment
Share on other sites

Agree with Asos a slightly easier way may be to read each line in the csv and make just 1 list at a time, again a Lee-mac solution. parse.lsp

 

; Take a csv file of text details and make in Cad
; By Alan H May 2018

(defun c:AHXL->text ( / fname str oldtxtsty oldtxtsize newlst pt ro val ht wid )
; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
   (if (setq pos (vl-string-position 44 str))
       (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
       (list str)
   )
)

; program starts here hardcoded for testing
(setq fname (open "C:\\temp\\test.csv" "r"))
(setq newline (read-line fname)) ;dummy for heading

(setq oldtxtsty (getvar 'textstyle))
(setq oldtxtsize (getvar 'textsize))

(while (setq newline (read-line fname))
   (setq newlst ( _csv->lst newline))
   (setvar 'textsize (atof (nth 2 newlst)))
   (setq pt (list (atof (nth 4 newlst)) (atof(nth 5 newlst))))
   (setq ro (atof(nth 7 newlst)))
   (setvar "textstyle" (nth 8 newlst))
   (setq val (nth 12 newlst))
   (setq ht (atof (nth 2 newlst)))
   (setq wid (atof (nth 11 newlst)))
       (command "Text" pt ht ro val )
)
(close fname)
(setvar 'textstyle oldtxtsty)
(setvar 'textsize oldtxtsize)

(princ)

)

Edited by BIGAL
1st line dummy added
Link to comment
Share on other sites

Agree with Asos a slightly easier way may be to read each line in the csv and make just 1 list at a time, again a Lee-mac solution. parse.lsp

 

; Take a csv file of text details and make in Cad
; By Alan H May 2018

(defun c:AHXL->text ( / fname str oldtxtsty oldtxtsize newlst pt ro val ht wid )
; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
	(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
	(list str)
   )
)

; program starts here hardcoded for testing
(setq fname (open "C:\\temp\\test.csv" "r"))

(setq oldtxtsty (getvar 'textstyle))
(setq oldtxtsize (getvar 'textsize))

(while (setq newline (read-line fname))
(setq newlst ( _csv->lst newline))
(setvar 'textsize (atof (nth 2 newlst)))
(setq pt (list (atof (nth 4 newlst)) (atof(nth 5 newlst))))
(setq ro (atof(nth 7 newlst)))
(setvar "textstyle" (nth 8 newlst))
(setq val (nth 10 newlst))
(setq ht (atof (nth 2 newlst)))
(setq wid (atof (nth 11 newlst)))
	(command "Text" pt ht ro val )
)
(close fname)
(setvar 'textstyle oldtxtsty)
(setvar 'textsize oldtxtsize)

(princ)

)

 

 

I'm getting the following error.

 

a40550d929cc9cbb07daf5cb005226fe.png

Link to comment
Share on other sites

I tested using your posted data in 1st post as a csv file your excel file may be different. The textsize was 5.000.

 

Maybe a easy fix delete 1st row in csv file. If its headings then makes sense will not work or add a read-line and do nothing this will skip the headings. See above post for changes. Note it is hard coded to just look for test.csv in c:\temp it can be changed to look elsewhere need more detail. This will cause errors also.

 

Tested again with your excel sample.

Edited by BIGAL
Link to comment
Share on other sites

Why not copy and paste as an AutoCAD table

- Select Range in Excel

-In Autocad Go to Edit Paste Special

AutoCADTable.jpg

Link to comment
Share on other sites

I tested using your posted data in 1st post as a csv file your excel file may be different. The textsize was 5.000.

 

Maybe a easy fix delete 1st row in csv file. If its headings then makes sense will not work or add a read-line and do nothing this will skip the headings. See above post for changes. Note it is hard coded to just look for test.csv in c:\temp it can be changed to look elsewhere need more detail. This will cause errors also.

 

Tested again with your excel sample.

 

Thanks, Your solution worked but the text am getting is 0 in all the instead of the text field -> 250 250 200 200 ....

 

4e99b6cf6bba55c53034de682c4512cc.png

 

The second issue is that the processing is slow .. it took 1 minutes to place all the texts in autocad comparing to manually pasting.

Link to comment
Share on other sites

Why not copy and paste as an AutoCAD table

- Select Range in Excel

-In Autocad Go to Edit Paste Special

[ATTACH]63933[/ATTACH]

 

Thanks for your approach, but I do not want to manually copy and past in autocad.

Link to comment
Share on other sites

I don't understand this, is it a trial program? When I clicked on the start it says "end trial period program!" and it does not work. Sorry man I'm here for the lisp not for buying a third party app, rather I would be interested in lisp coding and understanding how this language works. I'm proficient in VBA-Excel but not in lisp I'm here to learn lisp.

 

715418b8a5210d0441bd50a3b0fdb7d5.png

Link to comment
Share on other sites

1 A simple fix, you need to count the columns in a lisp "List" the 1st item is 0 so your text value is the 12th item (nth 12 newlst) code changed above. I was not sure which of the columns was the text value.

 

 

2 Speed all done for sample provide above, in about 3 seconds, I7, on my I3 laptop maybe 8 seconds.

 

 

3 It appears that what you have as standard text and what I have as standard text are different, can you post a sample dwg. The text "Style" can cause some hiccups and just need to know so can put in place a couple of checks.

Link to comment
Share on other sites

1 A simple fix, you need to count the columns in a lisp "List" the 1st item is 0 so your text value is the 12th item (nth 12 newlst) code changed above. I was not sure which of the columns was the text value.

 

 

2 Speed all done for sample provide above, in about 3 seconds, I7, on my I3 laptop maybe 8 seconds.

 

 

I modified the code as you suggested by fixing the column number and then it worked.

 

Thank you so much for your help! :D

 

Regards,

lucky

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...