An AutoLISP program that reads point list from file and puts them into drawing
Print This Post
![]() |
Author | Orhan Toker |
| Profession | Architect M.Sc. | |
| Autodesk Authorized Consultant | ||
| Database Specialist | ||
Visual LISP
Hello Daily AutoCAD readers,
This week, i have chosen an application came into my mind after a question from Ahmet who is studying Geodesy at Yıldız Techinal University. He came to my office and asked how he can read the output txt file of a laser coordinate instrument, that includes RGB color codes and point coordinates and use it as an input to the drawing. In this practice, I am not going to answer to the Ahmet’s question yet; I haven’t done anything about the RGB color codes. If anyone knows about this subject, please contact and assist Ahmet to resolve the issue.
Plase read my Managing basic file operations in AutoLISP article before start programming.
Let’s start with studying the txt file. Fig.1

Fig.1 The content of the txt file
Each line consists of a six digit value and corresponds to X,Y and Z coordinates of a point and the RGB color code. The space pattern between the values is irregular. The first thing to be done is to create a function that transforms the six digit values to real numbers and put them into an autolisp list. I prepared this function apart from the whole one because it can be used for any other purpose. The input parameter of the function is any line includes numerical values seperated by spaces. And as an output, it transforms the values into real numbers and put them into an autolisp list in order. The important point here is eliminating the spaces. Fig.2

Fig.2 The function that transforms the lines into a list
Examine and write down the function. Now we can proceed to the main function.

Fig.3 The main function
Write the function I showed above into the main function’s bottom. Do not forget to arrange the line that includes the path of the txt file according to your own file. This application is very useful if you do everyting correct.
Have a nice day,
You can download the necessary (TAL_ImportPts.lsp and points.txt) files from here.
Related articles: AutoLISP section
Read in other languages: TR
Similar Posts
Rate this article:


November 15th, 2007 23:16
To map the true color to the object take the RGB values, run them through the formula below, and map it to DXF code 420:
(+ B (* 256 G)(* 65536 R))
The code for this implementation would be:
(cons 420 (+ (nth 5 lst:list) (* 256 (nth 4 lst:list))(* 65536 (nth 3 lst:list))))
…and should appear below (or in the vicinity of) the line:
(cons 10 pt)
…which appears at line 44 of the main function in Fig.3
Out of curiosity, why did you include the line (cons 100 “AcDbPoint”), as it is not really necessary?
November 16th, 2007 12:36
Hi,
i had the same problem when I started to work with 3D laser scanners and solved it with similar lisp but the problem is not in the data input but in the AutoCADs capability of handling large amount od points. AutoCAD can handle maybe 200k of point and some scaners colect that many points in few seconds of scanning. Only way to work with such large datasets of points in AutoCAD is to use 3rd party addins that provide (like Trimble Lasergen, Leica Cyclone etc.) such handling.
November 19th, 2007 02:57
Hello,
I get error “bad argument type: FILE nil”.
Somebody have same problem with this code or I did something wrong?
November 28th, 2007 00:28
I would like to talk to you about lists.
First thing how would you get the first element in 9 different lists? (list named row1 …. row9)
send me an email m82626@gamil.com
Thanks
March 24th, 2008 22:20
Hello ,
Thansk for this important Auto lisp.
I get error “bad argument type: FILE nil”.