Author Topic: Lisp to create points from .xls file  (Read 965 times)

0 Members and 1 Guest are viewing this topic.

castro.brm

  • Mosquito
  • Posts: 2
Lisp to create points from .xls file
« on: June 07, 2022, 07:40:50 AM »
Hello to all.

I'm a student from Portugal, and i'm trying to find a lisp that could help me to draw multiple points in autocad from a xls file.

The real problem is that i must place the point from a horizontal angle that it was given in grads, a distance and the ID of the point. All off them start from the same point that could be the 0,0,0

Can anyone help me please. I have already look in google and youtube and didn't find nothing similar.

Thank you very much for your time and help




Points   Angle (grades)   "Horizontal distance"
                  Horizontal   
E2             72,731                             47,79
E3           167,772                             87,54
1             57,446                             45,25
2             54,839                             44,58
3             45,811                             48,82
4             39,220                             45,54
5             35,727                             42,40
6             54,649                               2,74
7            106,992                               6,20
8            120,702                              11,95
9            124,634                              16,60
10            142,317                              11,76
11            154,056                              15,74
12            146,164                              25,35
13           153,683                              26,11
14           184,728                              10,89
15           160,595                                6,14
16             87,536                                8,06
17           106,307                              12,48
18             83,485                              12,50
19               54,030                              37,23
20             45,039                              36,02
21             48,113                              40,27
22             35,768                              39,92
23             36,213                              39,93
24             36,451                              34,92
25             35,986                              34,91
26             41,950                                7,26
27             43,964                                5,80
28             54,493                                7,61
29             59,026                                6,27

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Lisp to create points from .xls file
« Reply #1 on: June 07, 2022, 10:14:21 AM »
Transfer tabular data into datalist variable from xls file :
- convert xls to csv or txt
- use (open) on csv or txt file, (read-line) functions to get row table data, and store it into datalist variable by subsequently using (cons) or (append) function on sucessive (read-line) data - point data...

*** Note : you must use (str->lst) sub function to parse retrieved row string into list of sub strings by specifying string delimiter - I suspected to ";" since "," character was used as decimal separator from your provided example...

Code - Auto/Visual Lisp: [Select]
  1. (setq fn (open "*.csv" "r"))
  2. (while (setq li (read-line fn))
  3.   (setq datalist (cons (str->lst li ";") datalist)
  4. )
  5. (setq datalist (reverse datalist))
  6.  

Foreach (row) of datalist :

Code - Auto/Visual Lisp: [Select]
  1. (foreach row datalist
  2.   (setq hdist (atof (vl-string-translate "." "," (last row))))
  3.   (setq ang (atof (vl-string-translate "." "," (cadr row))))
  4.   (setq d ... vvv ...)
  5.   ...
  6. )
  7.  

Look for real distance based on hdist (DWG units) and ang (grades) :

Code - Auto/Visual Lisp: [Select]
  1. (setq d (/ hdist (cos (cvunit ang "grade" "radian"))))
  2.  

Then use (polar) function to make point :

Code - Auto/Visual Lisp: [Select]
  1. (setq pt (polar (list 0.0 0.0 0.0) (cvunit ang "grade" "radian") d))
  2.  

Finally (entmake) point in WCS :

Code - Auto/Visual Lisp: [Select]
  1. (entmake (list (cons 0 "POINT") (cons 10 pt)))
  2.  
« Last Edit: June 07, 2022, 10:18:31 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

castro.brm

  • Mosquito
  • Posts: 2
Re: Lisp to create points from .xls file
« Reply #2 on: June 07, 2022, 10:56:55 AM »
Thank you very much Sir.

I'm going to try it.

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Lisp to create points from .xls file
« Reply #3 on: June 07, 2022, 08:34:30 PM »
You could look at doing the calcs in excel, found 1 grad = 0.9 degrees so grad / 1.111111111, can then use tan to work out Y value. Add to start point Hor & Ver

In excel can use =Concatenate to make a formula =Concatenate( d1,e1,",",f1) this would translate to POINT X,Y so you have a column of these point's just copy and paste the column to Acad command line and your points would appear.

A man who never made a mistake never made anything