What's wrong with my code
Hello everyoneI want to import data from text file
but, I have some problem about my code
Cloud you please help me?
first type:
(defun c:P_Import ()(setq SourceFile (open "C:\\test\\01010101.txt" "r")) (setq coords (read-line SourceFile)) (close SourceFile) (command "_pLine" (foreach pt coords;(command "_pLine" (foreach pt XY (command XY)))(command pt));(foreach pt XY );(command "_pLine");close defun
Second type:
(defun c:P_Import ()(setq SourceFile (open "C:\\test\\01010101.txt" "r"))(setq coords (read-line SourceFile)) (close SourceFile) (while (/= coords (setq coords (vl-string-subst ")(" " " coords))))(setq coords (read (strcat "((" (vl-string-translate "," " " coords) "))")))(command "_pLine" (foreach pt coords;(command "_pLine" (foreach pt XY (command XY)))(command pt));(foreach pt XY );(command "_pLine");close defun
01010101.txt (defun c:P_Import () (setq SourceFile (open "C:\\test\\01010101.txt" "r")) (setq coords (read-line SourceFile)) (close SourceFile) (command "_pLine" (foreach pt (read (Strcat "(" coords ")")) (command pt) ) ) )Now try and figure out the next one based on the code above [ if there are more than one set of point list that is ] I think we need to see what 01010101.txt looks like.
Nice foreach Pbe Another way:
(vl-load-com)(defun test (/ _kpblc-conv-string-to-list file handle adoc coords) (defun _kpblc-conv-string-to-list (string separator / i) (cond ((= string "") nil) ((vl-string-search separator string) ((lambda (/ pos res) (while (setq pos (vl-string-search separator string)) (setq res (cons (substr string 1 pos) res) string (substr string (+ (strlen separator) 1 pos)) ) ;_ end of setq ) ;_ end of while (reverse (cons string res)) ) ;_ end of lambda ) ) ((wcmatch (strcase string) (strcat "*" (strcase separator) "*")) ((lambda (/ pos res _str prev) (setq pos1 prev 1 _str (substr string pos) ) ;_ end of setq (while ( Thank you so much pBe and kpblc
页:
[1]