明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2307|回复: 6

从文件读坐标绘制多义线问题

[复制链接]
发表于 2007-6-3 15:38:00 | 显示全部楼层 |阅读模式

从txt文件中逐个读入坐标值,每次只能读进了一个坐标值,然后调用pline,但不能继续循环下去,

请高手指点,这是我的代码:

(defun c:bianxing()
  (setq oldcmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq oldblip (getvar "blipmode"))
  (setvar "blipmode" 0)
  (setq oldsnap (getvar "osmode"))
  (setvar "osmode" 0)
  (setq rr (getfiled "请选择变形数据文件" "a0" "txt;dat;*" 8))
  (setq rr1 (open rr "r"))
(while (setq coor (read-line rr1)) ;循环读取每一行
     (setq coor (read-line rr1))
     (setq coor0 (read (strcat "(" coor ")")))
     (command "pline" coor0)
  )
  )

发表于 2007-6-3 15:48:00 | 显示全部楼层

(while (setq coor (read-line rr1)) ;循环读取每一行
     (setq coor (read-line rr1))
     (setq coor0 (read (strcat "(" coor ")")))
     (command "pline" coor0)
  )

改成
(command "pline")
(while (setq coor (read-line rr1)) ;循环读取每一行
     (setq coor (read-line rr1))
     (setq coor0 (read (strcat "(" coor ")")))
     (command coor0)
  )
(command "")


发表于 2007-6-3 15:50:00 | 显示全部楼层
  1. (defun c:bianxing (/ oldcmd oldblip oldsnap rr rr1 coor)
  2.   (setq oldcmd (getvar "cmdecho"))
  3.   (setvar "cmdecho" 0)
  4.   (setq oldblip (getvar "blipmode"))
  5.   (setvar "blipmode" 0)
  6.   (setq oldsnap (getvar "osmode"))
  7.   (setvar "osmode" 0)
  8.   (setq rr (getfiled "请选择变形数据文件" "a0" "txt;dat;*" 8))
  9.   (setq rr1 (open rr "r"))
  10.   (command "_.pline")
  11.   (while (setq coor (read-line rr1)) ;循环读取每一行
  12.     (command coor)
  13.   ) ;_ 结束while
  14.   (command "")
  15.   (close rr1)
  16. ) ;_ 结束defun
DAT文件格式:
5,5
6,6
7,65
78.12,458

 楼主| 发表于 2007-6-3 16:02:00 | 显示全部楼层
非常感谢楼上两位,感激涕零
 楼主| 发表于 2007-6-3 17:17:00 | 显示全部楼层

再请教一下,我现在是做的的两个文件中数值所计算后的数值作为坐标,来画线。

为什么楼上的加上  (command "c")就可以曲线闭合,而下面的代码就不行呢,帮我看看问题所在,谢谢
(defun c:bianxing()
  (setq oldcmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq oldblip (getvar "blipmode"))
  (setvar "blipmode" 0)
  (setq oldsnap (getvar "osmode"))
  (setvar "osmode" 0)
  (setq rr (getfiled "请选择变形数据文件" "a0" "txt;dat;*" 8))
  (setq rr1 (open rr "r"))
  (setq ff (getfiled "请选择变形数据文件" "a2" "txt;dat;*" 8))
  (setq ff1 (open ff "r"))

  (command "pline" )
  (while (setq data (read-line ff1)) ;循环读取每一行
    (setq aa (strcat "(" data ")"));用来检测读出的数据格式
    (setq bb (read aa)) ;用来检测读出的数据格式 
    (setq data (read (strcat "(" data ")")))
    (setq number (car bb)
   neirong (cadr bb ))
     (setq coor (read-line rr1))
     (setq coor (read (strcat "(" coor ")")))
     (setq xx (car coor)
    yy (cadr coor))
    (setq xx1 (+ xx number)
   yy1 (+ yy neirong))
    (setq coor1 (list xx1 yy1))
    (command coor1)
  )  
  (command "c")
 
  (prin1)
)

 楼主| 发表于 2007-6-3 18:55:00 | 显示全部楼层
问题已经解决,是数据文件的末尾有几个回车的原因
发表于 2022-8-24 01:52:42 | 显示全部楼层
sailorcwx 发表于 2007-6-3 15:48
(while (setq coor (read-line rr1)) ;循环读取每一行     (setq coor (read-line rr1 ...

真好,看似简单,正到用时,因为一点点小问题就寸步难行。感谢感谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-15 16:54 , Processed in 0.216650 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表