Hi friends , in this article i will explain how to read a File in AutoLISP.
First of all open the
Visual LISP Editor,If you want to know about how to open Visual LISP Editor in
AutoCAD.
Suppose if
want to read the file in the C disk and in the TEMP folder. Normally we take
the path as C:\TEMP.But if we take the path as C:\TEMP
then it shows file nil.So we have take like C:\\TEMP\\.
Now let us write the program for read the
values from file and draw the rectangles according to the values in the file.
Write or copy and paste the below code in
the Visual LISP Editor.
(defun
c:readfile()
(setq cid (open
"C:\\TEMP\\CID.txt" "r"))
(setq nocids 0
cidlist ()
n 0)
(while (/= (setq n(read-line cid)) nil)
(setq nocids(+ nocids 1))
(setq cidlist(cons n cidlist))
)
(setq breath (open
"C:\\TEMP\\Breath.txt" "r"))
(setq noBreaths 0
brlist ()
n 0)
(while (/= (setq n(read-line breath)) nil)
(setq noBreaths(+ noBreaths 1))
(setq brlist(cons n brlist))
)
(setq Depth (open
"C:\\TEMP\\Depth.txt" "r"))
(setq nodepths 0
dlist ()
n 0)
(while (/= (setq n(read-line depth)) nil)
(setq nodepths(+ nodepths 1))
(setq dlist(cons n dlist))
)
(setq k 0)
(while(<= k (- nocids 1))
(setq cid(nth k (reverse cidlist))
breath(atof (nth k (reverse brlist)))
depth(atof (nth k (reverse dlist)))
)
(setq p1(getpoint "\npick the
point"))
(setq x(car p1)
y(cadr p1)
)
(setq col1(strcat (rtos x) ","
(rtos y)))
(setq col2(strcat (rtos (+ x breath))
"," (rtos (+ y depth))))
(command "rectang" col1 col2
"")
(setq k(+ k 1))
)
)
|
Save the file as readfile.LSP
Then write the
below line in the AutoCAD Command prompt.
Command: (load “readfile”)
Command:file
|
Then it will ask the following in the
command and press ENTER.
pick the point:
|
Suppose your files contains 3 values then it asks 3 pick the
point and draw 3 rectangles.
The output of the above program will be like the below
figure.
Happy Reading my blog .If you like my blog or is it useful
to you then please share this to your friends.
No comments:
Post a Comment