Hi
I have a file list which contains code x y z ina a space deliminated format. there are six different codes in the file and I want to end up with a list for each code containing just the x y z coordinates so I can create a seperate polyline for each. I have tried a number of methods and not getting very far. The codes are bi,bp,sq,tr,bc,sh.
example is as follows
sq 3.0 100 0
bp 3.1 80 0
sq 3.1 100 0
tr 3.1 40 0
bc 3.2 40 0
sh 3.47 60 0
bp 6.67 80 0
tr 6.67 40 0
sq 6.67 140 0
Not a complete list but enough to be going on with if you have the six diferent codes, the 0 at the end could be left off.
I would like to be able to controll the poliline perameters like line type and color so once the seperate lists are compiled I just set the layer,color,linetype then command a polyline for each of the six lists if they exist.
@richie_hodgson wrote:example is as follows
sq 3.0 100 0
bp 3.1 80 0
sq 3.1 100 0
tr 3.1 40 0
bc 3.2 40 0
sh 3.47 60 0
bp 6.67 80 0
tr 6.67 40 0
sq 6.67 140 0
Not a complete list but enough to be going on with if you have the six diferent codes, the 0 at the end could be left off.
I would like to be able to controll the poliline perameters like line type and color so once the seperate lists are compiled I just set the layer,color,linetype then command a polyline for each of the six lists if they exist.
(defun c:REbuild (/ _delFinder fl a b pl_ RebList)
(defun _delFinder (str md / d l str)
(while (setq d (vl-string-position md str nil T))
(setq l (cons (substr str (+ 2 d)) l)
str (substr str 1 d)))
(cons str l)
)
(if (and (setq fl (GetFiled "Select point file" "" "txt" 4))
(setq RebList nil fl (open fl "r")))
(progn
(while (setq a (read-line fl))
(setq pointlist (cons (_delFinderc a 32) pointlist))
)
(close fl)
(while (setq a (car pointlist))
(while (setq b (assoc (car a) pointlist ))
(setq pl_ (cons b pl_) pointlist (vl-remove b pointlist)))
(setq RebList (cons (list (caar pl_)(mapcar 'cdr pl_))
RebList) pl_ nil))
(foreach p RebList (print p)(princ));<test purposed
)
)
(princ)
)
("bc" ((3.2 40 0)))
("sh" ((3.47 60 0)))
("bp" ((3.1 80 0) (6.67 80 0)))
("tr" ((3.1 40 0) (6.67 40 0)))
("sq" ((3.0 100 0) (3.1 100 0) (6.67 140 0)))
HTH
Hi,
I'm not sure what you want, but this lisp take a file like the example and return a list of lists with the following format: ((code1 point1)(code2 point2)...)
(defun readF(MyFile / fp rl slist p pldata pldatalist) (setq fp (open Myfile "r")) (if fp (progn (while (setq rl (read-line fp)) (setq slist (split rl 32)) (setq p (list (read (nth 1 slist)) (read (nth 2 slist)))) (setq pldata (list (car slist) p)) (setq pldataList (cons pldata pldataList)) ) ) (alert "File not found!") ) (reverse pldatalist) ) (defun split(str char / sl i n e word slist) (setq sl (vl-string->list str)) (setq n (length sl)) (setq i 0) (setq word "") (while (< i n) (setq e (nth i sl)) (if (/= e char) (setq word (strcat word (chr e))) (progn (setq slist (cons word slist)) (setq word "") ) ) (setq i (+ i 1)) ) (reverse (cons word slist)) )
Gaston Nunez
Hi thanks for that, I get ; error: no function definition: _DELFINDERC, it looks like the outputs on your message are what I want, I assume I just need to write a car and cadr statement to separate the code and points so I can use an if statement to write the points to a polyline with colour and linetype, please let me know if I am wrong I am still relatively new to this lisp thing.
@richie_hodgson wrote:Hi thanks for that, I get ; error: no function definition: _DELFINDERC, it looks like the outputs on your message are what I want, I assume I just need to write a car and cadr statement to separate the code and points so I can use an if statement to write the points to a polyline with colour and linetype, please let me know if I am wrong I am still relatively new to this lisp thing.
oops my bad. i posted the wrong sub. replace the code in the previous post with this one
This converts the values as it compiels the list
(defun c:REbuild (/ _delFinder fl a b pl_ RebList)
(defun _delFinderC (str md / d l str)
(setq conv (lambda (k / num word)
(if (numberp (setq num (read k)))
num
k)))
(while (setq d (vl-string-position md str nil T))
(setq l (cons
(conv (substr str (+ 2 d)))
l)
str (substr str 1 d)))
(cons (conv str) l)
)
(if (and (setq fl (GetFiled "Select point file" "" "txt" 4))
(setq RebList nil fl (open fl "r")))
(progn
(while (setq a (read-line fl))
(setq pointlist (cons (_delFinderc a 32) pointlist))
)
(close fl)
(while (setq a (car pointlist))
(while (setq b (assoc (car a) pointlist ))
(setq pl_ (cons b pl_) pointlist (vl-remove b pointlist)))
(setq RebList (cons (list (caar pl_)(mapcar 'cdr pl_))
RebList) pl_ nil))
(foreach p RebList (print p)(princ));<test purposed
)
)
(princ)
)
Try it and tell me waht you think
@richie_hodgson wrote:example is as follows
sq 3.0 100 0
bp 3.1 80 0
sq 3.1 100 0
tr 3.1 40 0
bc 3.2 40 0
sh 3.47 60 0
bp 6.67 80 0
tr 6.67 40 0
sq 6.67 140 0
....
It's not necessary to break the lines up into pieces around the spaces -- point lists in AutoLISP are also space-delimited, so you can keep that aspect of the lines in the file. If the "categories" are always two letters, try this:
(setq fil (open "Y:/our/filepath/and/file.txt" "r"))
(while
(setq lin (read-line fil)); get next line in file
(set (read (substr lin 1 2)); variable name for list of points, from first two characters
(append
(eval (read (substr lin 1 2))); existing list of points for that category, if present
(list (read (strcat "(" (substr lin 3) ")"))); add point for current line
); append
); set
); while
(close fil)
On your example file content, that returns a list of point(s) for each category, stored in a variable named for that category, as follows:
Command: !sq
((3.0 100 0) (3.1 100 0) (6.67 140 0))
Command: !bp
((3.1 80 0) (6.67 80 0))
Command: !tr
((3.1 40 0) (6.67 40 0))
Command: !bc
((3.2 40 0))
Command: !sh
((3.47 60 0))
Hi Richie,
You may also want to take a look at our FREE Lisp resourceson the TechCenter web-site.
Here is the URL:
http://www.4d-technologies.com/techcenter
Over there, you can find Lisp routines for a vast array of common CAD and geo-data processing functions.
In fact, our commercial software add-ons, GeoTools and CADPower are built using the FREE libraries you see in TechCenter.
Let me know if you need any further assistance.
Regards
Rakesh
http://www.4d-technologies.com
Can't find what you're looking for? Ask the community or share your knowledge.