mit 发表于 2022-7-5 18:25:21

What's wrong with my code

Hello everyone
I 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

pBe 发表于 2022-7-5 18:47:36

(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 ]

BIGAL 发表于 2022-7-5 19:02:30

I think we need to see what 01010101.txt looks like.
 
Nice foreach Pbe

kpblc 发表于 2022-7-5 19:16:42

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 (

mit 发表于 2022-7-5 19:37:06

Thank you so much pBe and kpblc
页: [1]
查看完整版本: What's wrong with my code