乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 4|回复: 4

[编程交流] What's wrong with my code

[复制链接]
mit

13

主题

33

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 18:25:21 | 显示全部楼层 |阅读模式
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:
  1. (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:
 
  1. (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

32

主题

2722

帖子

2666

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
211
发表于 2022-7-5 18:47:36 | 显示全部楼层
  1. (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 ]
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:02:30 | 显示全部楼层
I think we need to see what 01010101.txt looks like.
 
Nice foreach Pbe
回复

使用道具 举报

10

主题

253

帖子

75

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
223
发表于 2022-7-5 19:16:42 | 显示全部楼层
Another way:

[code](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 pos  1               prev 1               _str (substr string pos)               ) ;_ end of setq         (while (
回复

使用道具 举报

mit

13

主题

33

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 19:37:06 | 显示全部楼层
Thank you so much pBe and kpblc
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 19:44 , Processed in 1.152152 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表