读txt文件并分离出坐标来lisp程序.还不完善还是先发一个也许能帮初学者一个忙.->
这是一个有关DMC配准前读txt中(见附件)的特定字符串后坐标的小程序,例子中我只提取西南和东北角点的X,Y坐标.我是集合了几个人的思路来写的.还不完善,但对于像我这样的初学者来说可能会帮上一点忙儿.所以就先发上来一个.希望多提宝贵意见.(defun c:DMCpz ( / txt fi start li str_tfh str_blc<BR> str_WSx str_WSy str_ENx str_ENy WS_x WS_y EN_x EN_y<BR> )<BR> <BR> (setq path_txt (getfiled "Select .txt file" "" "txt" 2))<BR> (setq fi (open path_txt "r"))<BR> <BR> (setq ;str_tfh ""<BR> str_WSx ""<BR> str_WSy ""<BR> str_ENx ""<BR> str_ENy ""<BR> ;str_blc "1:5000"<BR> )<BR> <BR> (setq start T)<BR> <BR> (while (and start (setq li (read-line fi)))<BR> (cond<BR> ((wcmatch li "*图号*") (setq str_tfh li))<BR> ((wcmatch li "*DOM裁切范围西南角点X坐标*") (setq str_WSx li))<BR> ((wcmatch li "*DOM裁切范围西南角点Y坐标*") (setq str_WSy li))<BR> ((wcmatch li "*DOM裁切范围东北角点X坐标*") (setq str_ENx li))<BR> ((wcmatch li "*DOM裁切范围东北角点Y坐标*") (setq str_ENy li)(setq start nil))<BR> (t nil)<BR> )<BR> )<BR> (setq WS_x<BR> (atof (substr str_WSx (+ 1 (strlen ":") (vl-string-search ":" str_WSx))) <BR> ))<BR> (setq WS_y<BR> (atof (substr str_WSy (+ 1 (strlen ":") (vl-string-search ":" str_WSy))) <BR> ))<BR> (setq EN_x<BR> (atof (substr str_ENx (+ 1 (strlen ":") (vl-string-search ":" str_ENx))) <BR> ))<BR> (setq EN_y<BR> (atof (substr str_ENy (+ 1 (strlen ":") (vl-string-search ":" str_ENy))) <BR> ))<BR> <BR> (command ".line" (list WS_x WS_y) (list EN_x EN_y) "")<BR> <BR> (close fi)<BR> (princ)<BR>)
回复
本帖最后由 作者 于 2004-12-11 19:00:29 编辑读取文件,尤其是txt文件,是初学者首先会面对的最实用的课题!
页:
[1]