mit Posted October 21, 2015 Posted October 21, 2015 Hello everyone Cloud you please help me? I have some problem to convert the list coordinate below: ("102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" "102.6137704879814,17.95798561968717,0" "102.614364152051,17.95733901085014,0") I want to convert to ((102.614364152051,17.95733901085014,0) (102.6148784682264,17.95771822280192,0) (102.6142663942859,17.95835128371222,0) (102.6141224420007,17.95824935570436,0) (102.6137704879814,17.95798561968717,0) (102.614364152051,17.95733901085014,0)) Please Mit Quote
Hippe013 Posted October 21, 2015 Posted October 21, 2015 You may want to look into downloading Dos_Lib. http://wiki.mcneel.com/developer/doslib Free Download. It contains a lisp function called 'Dos_StrTokens' dos_strtokens Converts a string of tokens into a list. -------------------------------------------------------------------------------- Syntax (dos_strtokens string tokens [T]) Parameters string A string. tokens A string interpreted as a set of delimiter characters. T If specified, the result is compatible with the strtok C/C++ run-time library function. Returns A list of strings, if successful. nil on error. Example Command: (dos_strtokens "Hockey is the best." " ") ("Hockey" "is" "the" "best.") Command: (dos_strtokens "A string\tof ,,tokens\nand some more tokens" " ,\t\n" t) ("A" "string" "of" "tokens" "and" "some" "more" "tokens") Command: (dos_strtokens "0,0,,0,0" ",") ("0" "0" "" "0" "0") Command: (dos_strtokens "0,0,,0,0" "," t) ("0" "0" "0" "0") Quote
satishrajdev Posted October 21, 2015 Posted October 21, 2015 (edited) Here is my way of doing it... for ((102.614 17.9573 0) (102.615 17.9577 0) (102.614 17.9584 0) (102.614 17.9582 0) (102.614 17.958 0) (102.614 17.9573 0) ) (mapcar '(lambda (x) (read (strcat "(" (vl-string-translate "," " " x) ")" ) ) ) list ) Edited October 21, 2015 by satishrajdev Quote
BIGAL Posted October 22, 2015 Posted October 22, 2015 Another (setq lst (list "102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" )) (setq num (length lst)) (setq y num) (repeat num (setq newlst (cons (list (nth (setq y (- y 1)) lst )) newlst))) Quote
mit Posted October 22, 2015 Author Posted October 22, 2015 First of all Thank you Hippe013, satishrajdev and BIGAL I was sorry about my questions It was not clear and It had something wrong I had use convert code from Lee Mac http://www.lee-mac.com/stringtolist.html my first list are : (defun c:coordformat () (setq coords '("102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0")) ;and when I used this function (setq coords (LM:str->lst coords " ")) ;It was not convert to list coordinate format ) (defun LM:str->lst ( str del / len lst pos ) (setq len (1+ (strlen del))) (while (setq pos (vl-string-search del str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos len)) ) ) (reverse (cons str lst)) ) . When I used this code It was not convert list to coordinate format. It was: ("102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" "102.6137704879814,17.95798561968717,0" "102.614364152051,17.95733901085014,0") The coordinate list format should be: ((102.614364152051 17.95733901085014 0) (102.6148784682264 17.95771822280192 0) (102.6142663942859 17.95835128371222 0) (102.6141224420007 17.95824935570436 0) (102.6137704879814 17.95798561968717 0) (102.614364152051 17.95733901085014 0)) or should be: ((102.614364152051 17.95733901085014) (102.6148784682264 17.95771822280192) (102.6142663942859 17.95835128371222) (102.6141224420007 17.95824935570436) (102.6137704879814 17.95798561968717) (102.614364152051 17.95733901085014)) If you have anything else Please help me mit Quote
satishrajdev Posted October 22, 2015 Posted October 22, 2015 The coordinate list format should be: ((102.614364152051 17.95733901085014 0) (102.6148784682264 17.95771822280192 0) (102.6142663942859 17.95835128371222 0) (102.6141224420007 17.95824935570436 0) (102.6137704879814 17.95798561968717 0) (102.614364152051 17.95733901085014 0)) For this read my post... but there are change in decimals. I don't know the reason. Will try to fix it tomorrow Quote
Lee Mac Posted October 22, 2015 Posted October 22, 2015 Since your data is already in a literal string format, I would follow the same method as Satish in the post above, using a read expression to convert the values into AutoLISP data types, e.g.: _$ ([color=BLUE]setq[/color] coords [color=MAROON]"102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0"[/color]) [color=MAROON]"102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0"[/color] _$ ([color=BLUE]while[/color] ([color=BLUE]/=[/color] coords ([color=BLUE]setq[/color] coords ([color=BLUE]vl-string-subst[/color] [color=MAROON]")("[/color] [color=MAROON]" "[/color] coords)))) [color=BLUE]nil[/color] _$ ([color=BLUE]read[/color] ([color=BLUE]strcat[/color] [color=MAROON]"(("[/color] ([color=BLUE]vl-string-translate[/color] [color=MAROON]","[/color] [color=MAROON]" "[/color] coords) [color=MAROON]"))"[/color])) ((102.614 17.9573 0) (102.615 17.9577 0) (102.614 17.9584 0) (102.614 17.9582 0) (102.614 17.958 0) (102.614 17.9573 0)) For this read my post... but there are change in decimals. I don't know the reason. Will try to fix it tomorrow Please note that no precision is lost in the output to the console - the coordinate values are still stored in memory to the highest available precision, however, the printed values are truncated for readability. Quote
mit Posted October 23, 2015 Author Posted October 23, 2015 Hoo! so sorry about mistake code the code should be the same Lee Mac: (defun c:coordformat () (setq coords "102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0) ;and when I used this function (setq coords (LM:str->lst coords " ")) ;It was not convert to list coordinate format ) (defun LM:str->lst ( str del / len lst pos ) (setq len (1+ (strlen del))) (while (setq pos (vl-string-search del str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos len)) ) ) (reverse (cons str lst)) ) thank you os much satishrajdev and thank you two times for Lee Mac Quote
satishrajdev Posted October 23, 2015 Posted October 23, 2015 Please note that no precision is lost in the output to the console - the coordinate values are still stored in memory to the highest available precision, however, the printed values are truncated for readability. Noted thank you os much satishrajdev Your welcome:) Quote
Lee Mac Posted October 23, 2015 Posted October 23, 2015 (setq coords "102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0) ;and when I used this function (setq coords (LM:str->lst coords " ")) ;It was not convert to list coordinate format Note that my LM:str->lst function is performing exactly as described: the string is separated into a list of items using the given delimiter, e.g.: _$ (LM:str->lst "1,2,3 4,5,6 7,8,9" " ") ("1,2,3" "4,5,6" "7,8,9") However, the above is not the format recognised by the AutoLISP interpreter as a list of 3D points - a point list must be a list of 2 or 3 numerical values, whereas the above is simply a list of strings. For future reference, I would appreciate if you could please retain the code headers which accompany the functions published on my site. thank you two times for Lee Mac You're most welcome Quote
Recommended Posts
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.