Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data input

Status
Not open for further replies.

cad123

Structural
Joined
Aug 15, 2002
Messages
49
Location
VN
I have one file .xls have coordinate of point
ex H502 73847.83 82333.93 (H502 is name of point )
-------------------------
-------------------------
how can I import it to Cad

I wrote a lisp for this work, but it have problem at name of point ( it must is number, I can not solve char and number, ex 502 is OK, but H502 it message symbol error)and sometime have problem with Y-coordinate ( some time not correct miss some numbers)
Could you advice me?
I send it here :
(please make a text style with height >0, and make a block name is bor first)
-------------
(defun C:dab (/ FN PR RL PT PT1 Len Len1 i j A B X Y Lst Le fi na lena)
(setq FN(getfiled "Select a data file " "" "txt" 0 ))
( if (null FN)
(princ " No file selected!")
(progn
(setq PR (open FN "r"))
(setq lst nil)
(setq lst2 nil)
(while (setq RL(read-line PR))
;(princ RL)
(setq i 0)
(setq j 0)
(setq na (itoa(read RL))) ;Input first element (name of point)
;(princ (type na))
;(princ na)
(setq Lena (strlen na)) ; length of RL
(setq j (+ Lena 1))
;-------
(setq RL (substr RL j))
;-------
(setq Len (strlen RL)) ; length of RL
;(princ len)
(setq A (rtos(read RL))) ;Input first element convert to str
;(princ A)
(setq Len1 (strlen A)) ; length A
(setq i (+ Len1 1)) ; i = length A +1
(setq B (substr RL i)) ; B return sub string on RL
;(princ B)
(setq X (atof A)
Y (atof B)
)
(setq PT (list X Y))
;(princ PT)
(setq Lst (append Lst (list PT)))
;(setq na (atoi na))
(setq Lst2 (append lst2 (list na)))





); close while 1

;(princ lst2)

(close PR)
(setq fi (car lst))
(setq lst (cdr lst))
;(princ lst)

(command ".insert" "bor" fi "" "" "" )
(setq fi1 (car lst2))
;(princ(type fi1))
(setq lst2 (cdr lst2))
(command ".text" fi "" fi1 "" "")




(foreach Le Lst
(command ".insert" "bor" le "" "" "" )
(setq fi2 (car lst2))
(setq lst2 (cdr lst2))
(command ".text" le "" fi2 "" "" )

)
;(command "")
); close progn

);close if


(princ)
)
 
I suggest you use something other than 'read' to extract information from text file. Read will return (I think) the first number in a text string, or if not a valid number will treat it as a variable name. So you have the problem with "H502". Also converting a number to string with 'rtos' may not give the same number of characters after the decimal point, which messes up your character count, possibly the Y coordinate problem. As an alternate to 'read', step through a line one character at a time, using a counter and 'substr'; when a space is encountered extract the string between spaces based on the count.

An idea anyway, HTH,
Carl
 
Here's one way to extract the data from a text file
and use it in your routine. No error checking.

;;;
;;;to convert the text file into a list of list of strings
;;;Code based on the format you have posted, delimiter
;;;is a space.
;;;

(setq lst '() ptlist '())
(while (setq RL (read-line PR))
(setq len (strlen RL))
count 0
chars ""
)
(repeat 2
(setq flag T)
(while flag
(setq tmp (substr RL (1+ count) 1))
(if (/= tmp " ")
(setq chars (strcat chars tmp)
count (1+ count)
);end setq, not space
(setq lst (cons chars lst)
count (1+ count)
flag nil
char ""
);end setq, space
);end if
);end while
);end repeat
(setq chars (substr RL count len)
lst (cons chars lst)
ptlist (cons lst ptlist)
)
);end while

;;;
;;;to extract the point name, X and Y coords
;;;

(foreach item (reverse ptlist)
(setq pointname (car item) ;;in string format ex "H502"
xcoord (atof (cadr item)) ;;convert string to real
ycoords (atof (caddr item)) ;; -ditto-
pt (list xcoords ycoords)
)
(do what you want with the data here)
...........
............
(etc)
);end foreach

Leo
 
Thank Carl and Leo
I will try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top